Python SDK Specification
Enumeration of methods and types in the Exa Python SDK (exa_py).
For ChatGPT-based Python SDK assistance, go here.
Getting started
Install the exa-py SDK
and then instantiate an Exa client
Get API Key
Follow this link to get your API key
search
Method
Perform an Exa search given an input query and retrieve a list of relevant results as links.
Input Example:
Input Parameters:
Parameter | Type | Description | Default |
---|---|---|---|
query | str | The input query string. | Required |
num_results | Optional[int] | Number of search results to return. | 10 |
include_domains | Optional[List[str]] | List of domains to include in the search. | None |
exclude_domains | Optional[List[str]] | List of domains to exclude in the search. | None |
start_crawl_date | Optional[str] | Results will only include links crawled after this date. | None |
end_crawl_date | Optional[str] | Results will only include links crawled before this date. | None |
start_published_date | Optional[str] | Results will only include links with a published date after this date. | None |
end_published_date | Optional[str] | Results will only include links with a published date before this date. | None |
use_autoprompt | Optional[bool] | If true, convert query to a query best suited for Exa. | False |
type | Optional[str] | The type of search, keyword or neural. | ”auto” |
category | Optional[str] | A data category to focus on when searching, with higher comprehensivity and data cleanliness. Currently, the available categories are: company, research paper, news, linkedin profile, github, tweet, movie, song, personal site, pdf and financial report. | None |
Returns Example:
Return Parameters:
SearchResponse[Result]
Field | Type | Description |
---|---|---|
results | List[Result] | List of Result objects |
autoprompt_string | Optional[str] | Exa query created by autoprompt functionality |
Result Object:
Field | Type | Description |
---|---|---|
url | str | URL of the search result |
id | str | Temporary ID for the document |
title | Optional[str] | Title of the search result |
score | Optional[float] | Similarity score between query/url and result |
published_date | Optional[str] | Estimated creation date |
author | Optional[str] | Author of the content, if available |
search_and_contents
Method
Perform an Exa search given an input query and retrieve a list of relevant results as links, optionally including the full text and/or highlights of the content.
Input Example:
Input Parameters:
Parameter | Type | Description | Default |
---|---|---|---|
query | str | The input query string. | Required |
text | Union[TextContentsOptions, Literal[True]] | If provided, includes the full text of the content in the results. | None |
highlights | Union[HighlightsContentsOptions, Literal[True]] | If provided, includes highlights of the content in the results. | None |
num_results | Optional[int] | Number of search results to return. | 10 |
include_domains | Optional[List[str]] | List of domains to include in the search. | None |
exclude_domains | Optional[List[str]] | List of domains to exclude in the search. | None |
start_crawl_date | Optional[str] | Results will only include links crawled after this date. | None |
end_crawl_date | Optional[str] | Results will only include links crawled before this date. | None |
start_published_date | Optional[str] | Results will only include links with a published date after this date. | None |
end_published_date | Optional[str] | Results will only include links with a published date before this date. | None |
use_autoprompt | Optional[bool] | If true, convert query to a query best suited for Exa. | False |
type | Optional[str] | The type of search, keyword or neural. | ”auto” |
category | Optional[str] | A data category to focus on when searching, with higher comprehensivity and data cleanliness. Currently, the available categories are: company, research paper, news, linkedin profile, github, tweet, movie, song, personal site, pdf and financial report. | None |
Returns Example:
Return Parameters:
The return type depends on the combination of text
and highlights
parameters:
SearchResponse[ResultWithText]
: When onlytext
is provided.SearchResponse[ResultWithHighlights]
: When onlyhighlights
is provided.SearchResponse[ResultWithTextAndHighlights]
: When bothtext
andhighlights
are provided.
SearchResponse\[ResultWithTextAndHighlights\]
Field | Type | Description |
---|---|---|
results | List[ResultWithTextAndHighlights] | List of ResultWithTextAndHighlights objects |
autoprompt_string | Optional[str] | Exa query created by autoprompt functionality |
ResultWithTextAndHighlights
Object
Field | Type | Description |
---|---|---|
url | str | URL of the search result |
id | str | Temporary ID for the document |
title | Optional[str] | Title of the search result |
score | Optional[float] | Similarity score between query/url and result |
published_date | Optional[str] | Estimated creation date |
author | Optional[str] | Author of the content, if available |
text | str | Text of the search result page (always present) |
highlights | List[str] | Highlights of the search result (always present) |
highlight_scores | List[float] | Scores of the highlights (always present) |
Note: If neither text
nor highlights
is specified, the method defaults to including the full text content.
find_similar
Method
Find a list of similar results based on a webpage’s URL.
Input Example:
Input Parameters:
Parameter | Type | Description | Default |
---|---|---|---|
url | str | The URL of the webpage to find similar results for. | Required |
num_results | Optional[int] | Number of similar results to return. | None |
include_domains | Optional[List[str]] | List of domains to include in the search. | None |
exclude_domains | Optional[List[str]] | List of domains to exclude from the search. | None |
start_crawl_date | Optional[str] | Results will only include links crawled after this date. | None |
end_crawl_date | Optional[str] | Results will only include links crawled before this date. | None |
start_published_date | Optional[str] | Results will only include links with a published date after this date. | None |
end_published_date | Optional[str] | Results will only include links with a published date before this date. | None |
exclude_source_domain | Optional[bool] | If true, excludes results from the same domain as the input URL. | None |
category | Optional[str] | A data category to focus on when searching, with higher comprehensivity and data cleanliness. | None |
Returns Example:
Return Parameters:
SearchResponse[_Result]
: The response containing similar results and optional autoprompt string.
SearchResponse\[Results\]
Field | Type | Description |
---|---|---|
results | List[ResultWithTextAndHighlights] | List of ResultWithTextAndHighlights objects |
autoprompt_string | Optional[str] | Exa query created by autoprompt functionality |
Results
Object
Field | Type | Description |
---|---|---|
url | str | URL of the search result |
id | str | Temporary ID for the document |
title | Optional[str] | Title of the search result |
score | Optional[float] | Similarity score between query/url and result |
published_date | Optional[str] | Estimated creation date |
author | Optional[str] | Author of the content, if available |
find_similar_and_contents
Method
Find a list of similar results based on a webpage’s URL, optionally including the text content or highlights of each result.
Input Example:
Input Parameters:
Parameter | Type | Description | Default |
---|---|---|---|
url | str | The URL of the webpage to find similar results for. | Required |
text | Union[TextContentsOptions, Literal[True]] | If provided, includes the full text of the content in the results. | None |
highlights | Union[HighlightsContentsOptions, Literal[True]] | If provided, includes highlights of the content in the results. | None |
num_results | Optional[int] | Number of similar results to return. | None |
include_domains | Optional[List[str]] | List of domains to include in the search. | None |
exclude_domains | Optional[List[str]] | List of domains to exclude from the search. | None |
start_crawl_date | Optional[str] | Results will only include links crawled after this date. | None |
end_crawl_date | Optional[str] | Results will only include links crawled before this date. | None |
start_published_date | Optional[str] | Results will only include links with a published date after this date. | None |
end_published_date | Optional[str] | Results will only include links with a published date before this date. | None |
exclude_source_domain | Optional[bool] | If true, excludes results from the same domain as the input URL. | None |
category | Optional[str] | A data category to focus on when searching, with higher comprehensivity and data cleanliness. | None |
Returns:
The return type depends on the combination of text
and highlights
parameters:
SearchResponse[ResultWithText]
: When onlytext
is provided or when neithertext
norhighlights
is provided (defaults to including text).SearchResponse[ResultWithHighlights]
: When onlyhighlights
is provided.SearchResponse[ResultWithTextAndHighlights]
: When bothtext
andhighlights
are provided.
The response contains similar results and an optional autoprompt string.
Note: If neither text
nor highlights
is specified, the method defaults to including the full text content.
answer
Method
Generate an answer to a query using Exa’s search and LLM capabilities. This method returns an AnswerResponse with the answer and a list of citations. You can optionally retrieve the full text of each citation by setting text=True.
Input Example:
Input Parameters:
Parameter | Type | Description | Default |
---|---|---|---|
query | str | The question to answer. | Required |
text | Optional[bool] | If true, the full text of each citation is included in the result. | False |
stream | Optional[bool] | Note: If true, an error is thrown. Use stream_answer() instead for streaming responses. | None |
Returns Example:
Return Parameters:
Returns an AnswerResponse
object:
Field | Type | Description |
---|---|---|
answer | str | The generated answer text |
citations | List[AnswerResult] | List of citations used to generate the answer |
AnswerResult
object
Field | Type | Description |
---|---|---|
id | str | Temporary ID for the document |
url | str | URL of the citation |
title | Optional[str] | Title of the content, if available |
published_date | Optional[str] | Estimated creation date |
author | Optional[str] | The author of the content, if available |
text | Optional[str] | The full text of the content (if text=True) |
stream_answer
Method
Generate a streaming answer to a query with Exa’s LLM capabilities. Instead of returning a single response, this method yields chunks of text and/or citations as they become available.
Input Example:
Input Parameters:
Parameter | Type | Description | Default |
---|---|---|---|
query | str | The question to answer. | Required |
text | Optional[bool] | If true, includes full text of each citation in the streamed response. | False |
Return Type:
A StreamAnswerResponse
object, which is iterable. Iterating over it yields StreamChunk
objects:
StreamChunk
Field | Type | Description |
---|---|---|
content | Optional[str] | Partial text content of the answer so far. |
citations | Optional[List[AnswerResult]] | Citations discovered in this chunk, if any. |
Use stream.close()
to end the streaming session if needed.