Getting started
Install the exa-js SDK
and then instantiate an Exa client
import Exa from "exa-js" ;
const exa = new Exa (); // Reads EXA_API_KEY from environment
// or explicitly: const exa = new Exa("your-api-key");
Get API Key Follow this link to get your API key
search Method
The
options.type parameter accepts:
"auto" (default),
"fast",
"deep", or
"neural". See
RegularSearchOptions for all available options.
const result = await exa . search ( "hottest AI startups" , {
numResults: 10
});
Parameter Type Description Default query string- Required options RegularSearchOptions & { contents?: T | false | null | undefined }- Required
Return Example
{
"autopromptString" : "Here is a link to one of the hottest AI startups:" ,
"results" : [
{
"title" : "Adept: Useful General Intelligence" ,
"id" : "https://www.adept.ai/" ,
"url" : "https://www.adept.ai/" ,
"publishedDate" : "2000-01-01" ,
"author" : null ,
"text" : "Adept is building AI that can automate any software process..."
}
],
"requestId" : "a78ebce717f4d712b6f8fe0d5d7753f8"
}
Result Object
Field Type Description results SearchResult<T>[]The list of search results. requestId stringThe request ID for the search. context stringThe context for the search (for deep search). autoDate stringThe autoprompt date, if applicable. statuses Status[]Status information for each result. costDollars CostDollarsThe cost breakdown for this request.
searchAndContents Method
The
options.type parameter accepts:
"auto" (default),
"fast",
"deep", or
"neural". See
RegularSearchOptions for all available options.
const result = await exa . searchAndContents ( "AI in healthcare" , {
text: true ,
highlights: true ,
numResults: 5
});
Parameter Type Description Default query stringThe query string. * Required options RegularSearchOptions & T- Required
Return Example
{
"results" : [
{
"title" : "2023 AI Trends in Health Care" ,
"id" : "https://aibusiness.com/verticals/2023-ai-trends-in-health-care-" ,
"url" : "https://aibusiness.com/verticals/2023-ai-trends-in-health-care-" ,
"publishedDate" : "2022-12-29" ,
"author" : "Wylie Wong" ,
"text" : "While the health care industry was initially slow to adopt AI..." ,
"highlights" : [
"AI is transforming healthcare through improved diagnostics and personalized treatment plans."
],
"highlightScores" : [
0.85
]
}
],
"requestId" : "b89fcd823e4f5a91c7d0fe1e6e8864f9"
}
Result Object
Field Type Description results SearchResult<T>[]The list of search results. requestId stringThe request ID for the search. context stringThe context for the search (for deep search). autoDate stringThe autoprompt date, if applicable. statuses Status[]Status information for each result. costDollars CostDollarsThe cost breakdown for this request.
findSimilar Method
const result = await exa . findSimilar ( "https://www.example.com/article" , {
numResults: 10 ,
excludeSourceDomain: true
});
Parameter Type Description Default url string- Required options FindSimilarOptions & { contents?: T | false | null | undefined }- Required
Return Example
{
"results" : [
{
"title" : "Similar Article: AI and Machine Learning" ,
"id" : "https://www.similarsite.com/ai-ml-article" ,
"url" : "https://www.similarsite.com/ai-ml-article" ,
"publishedDate" : "2023-05-15" ,
"author" : "Jane Doe" ,
"text" : "Artificial Intelligence (AI) and Machine Learning (ML) are revolutionizing various industries..."
}
],
"requestId" : "08fdc6f20e9f3ea87f860af3f6ccc30f"
}
Result Object
Field Type Description results SearchResult<T>[]The list of search results. requestId stringThe request ID for the search. context stringThe context for the search (for deep search). autoDate stringThe autoprompt date, if applicable. statuses Status[]Status information for each result. costDollars CostDollarsThe cost breakdown for this request.
findSimilarAndContents Method
const result = await exa . findSimilarAndContents ( "https://www.example.com/article" , {
text: true ,
highlights: true ,
numResults: 5
});
Parameter Type Description Default url stringThe URL for which to find similar links. * Required options FindSimilarOptions & T- Required
Return Example
{
"results" : [
{
"title" : "The Impact of AI on Modern Technology" ,
"id" : "https://www.techblog.com/ai-impact" ,
"url" : "https://www.techblog.com/ai-impact" ,
"publishedDate" : "2023-06-01" ,
"author" : "John Smith" ,
"text" : "In recent years, artificial intelligence has made significant strides..." ,
"highlights" : [
"AI is reshaping industries and creating new opportunities for innovation."
],
"highlightScores" : [
0.92
]
}
],
"requestId" : "c90gde934f5g6b02d8e1gf2f7f9975g0"
}
Result Object
Field Type Description results SearchResult<T>[]The list of search results. requestId stringThe request ID for the search. context stringThe context for the search (for deep search). autoDate stringThe autoprompt date, if applicable. statuses Status[]Status information for each result. costDollars CostDollarsThe cost breakdown for this request.
getContents Method
Retrieves contents of documents based on URLs.
const result = await exa . getContents ([
"https://www.example.com/article1" ,
"https://www.example.com/article2"
], {
text: { maxCharacters: 1000 },
highlights: { query: "AI" , numSentences: 2 }
});
Parameter Type Description Default urls string | string[] | SearchResult<T>[]A URL or array of URLs, or an array of SearchResult objects. * Required options T- Required
Return Example
{
"results" : [
{
"url" : "https://example.com/article" ,
"id" : "https://example.com/article" ,
"title" : "Example Article" ,
"text" : "The full text content of the article..."
}
]
}
Result Object
Field Type Description results SearchResult<T>[]The list of search results. requestId stringThe request ID for the search. context stringThe context for the search (for deep search). autoDate stringThe autoprompt date, if applicable. statuses Status[]Status information for each result. costDollars CostDollarsThe cost breakdown for this request.
answer Method
const result = await exa . answer ( "What is the capital of France?" , {
text: true ,
model: "exa"
});
Parameter Type Description Default query string- Required options AnswerOptions | AnswerOptionsTyped<ZodSchema<T>>- Required
Return Example
{
"answer" : "The capital of France is Paris." ,
"citations" : [
{
"id" : "https://www.example.com/france" ,
"url" : "https://www.example.com/france" ,
"title" : "France - Wikipedia" ,
"publishedDate" : "2023-01-01" ,
"author" : null ,
"text" : "France, officially the French Republic, is a country in... [truncated for brevity]"
}
],
"requestId" : "abc123"
}
Result Object
Field Type Description answer string | Record<string, unknown>The generated answer text (or object matching outputSchema if provided). citations SearchResult<{}>[]The sources used to generate the answer. requestId stringThe request ID for the answer. costDollars CostDollarsThe cost breakdown for this request.
streamAnswer Method
for await ( const chunk of exa . streamAnswer ( "What is quantum computing?" , {
text: true ,
model: "exa"
})) {
if ( chunk . content ) process . stdout . write ( chunk . content );
if ( chunk . citations ) console . log ( "Citations:" , chunk . citations );
}
Parameter Type Description Default query string- Required options { text?: boolean; model?: "exa" | "exa-pro"; systemPrompt?: string; outputSchema?: Record<string, unknown> | ZodSchema<T>; }- Required
Return Example
{
"content" : "The capital of France is Paris." ,
"citations" : [
{
"id" : "https://www.example.com/france" ,
"url" : "https://www.example.com/france" ,
"title" : "France - Wikipedia"
}
]
}
Result Object
Field Type Description content stringThe partial text content of the answer (if present in this chunk). citations Array<{id, url, title?, publishedDate?, author?, text?}>Citations associated with the current chunk of text (if present).
research.create Method
const task = await exa . research . create ({
instructions: "Research the latest AI developments" ,
model: "exa-research-fast"
});
Parameter Type Description Default params { instructions: string; model?: ResearchCreateRequest["model"]; outputSchema?: Record<string, unknown> | ZodSchema<T>; }- Required
Return Example
{
"researchId" : "a1b2c3d4-e5f6-7890-abcd-ef1234567890" ,
"status" : "pending"
}
research.get Method
When called with stream: true, returns an AsyncGenerator<ResearchStreamEvent> for real-time SSE updates instead of a Promise<Research>.
const result = await exa . research . get ( "a1b2c3d4-e5f6-7890-abcd-ef1234567890" );
Parameter Type Description Default researchId string- Required options { stream?: boolean; events?: boolean; outputSchema?: ZodSchema<T>; }- Required
Return Example
{
"researchId" : "a1b2c3d4-e5f6-7890-abcd-ef1234567890" ,
"status" : "completed" ,
"instructions" : "What is the latest valuation of SpaceX?" ,
"output" : {
"parsed" : {
"valuation" : "$350 billion" ,
"date" : "December 2024" ,
"source" : "Financial Times"
}
}
}
research.pollUntilFinished Method
Options include pollInterval (default 1000ms), timeoutMs (default 10 minutes), and events (boolean to include event log).
const result = await exa . research . pollUntilFinished ( "a1b2c3d4-e5f6-7890-abcd-ef1234567890" , {
pollInterval: 1000 ,
timeoutMs: 600000
});
Parameter Type Description Default researchId string- Required options { pollInterval?: number; timeoutMs?: number; events?: boolean; outputSchema?: ZodSchema<T>; }- Required
research.list Method
const tasks = await exa . research . list ({ limit: 10 });
Parameter Type Description Default options ListResearchRequest- Required
Return Example
{
"data" : [
{
"researchId" : "task-1" ,
"status" : "completed" ,
"instructions" : "Research SpaceX valuation"
}
],
"hasMore" : true ,
"nextCursor" : "eyJjcmVhdGVkQXQiOiIyMDI0LTAxLTE1VDE4OjMwOjAwWiIsImlkIjoidGFzay0yIn0="
}
Types Reference
This section documents the types used throughout the SDK.
Content Options
These types configure content retrieval options for the contents parameter.
ContentsOptions
Options for retrieving page contents
Field Type Description text TextContentsOptions | trueOptions for retrieving text contents. highlights HighlightsContentsOptions | trueOptions for retrieving highlights. summary SummaryContentsOptions | trueOptions for retrieving summary. maxAgeHours numberMaximum age of cached content in hours. If content is older, it will be fetched fresh. Special values: 0 = always fetch fresh content, -1 = never fetch fresh (cache only). Example: 168 = fetch fresh for pages older than 7 days. filterEmptyResults booleanIf true, filters out results with no contents. Default is true. subpages numberNumber of subpages to return for each result. subpageTarget string | string[]Text used to match/rank subpages in the returned list. extras ExtrasOptionsMiscellaneous data derived from results. context ContextOptions | trueOptions for retrieving context.
BaseSearchOptions
Options for performing a search query
Field Type Description contents ContentsOptions- numResults number- includeDomains string[]- excludeDomains string[]- startCrawlDate string- endCrawlDate string- startPublishedDate string- endPublishedDate string- category | "company" | "research paper" | "news" | "pdf" | "tweet" | "personal site" | "financial report" | "people"- includeText string[]- excludeText string[]- flags string[]- userLocation string-
RegularSearchOptions
Search options for performing a search query.
Uses a discriminated union to ensure additionalQueries is only allowed when type is “deep”.
Field Type Description type "auto" | "fast" | "deep" | "neural"The type of search to perform. Default is “auto”. numResults numberNumber of search results to return. Default 10. Max 10 for basic plans. includeDomains string[]List of domains to include in the search. excludeDomains string[]List of domains to exclude in the search. startCrawlDate stringStart date for results based on crawl date (ISO format). endCrawlDate stringEnd date for results based on crawl date (ISO format). startPublishedDate stringStart date for results based on published date (ISO format). endPublishedDate stringEnd date for results based on published date (ISO format). category "company" | "research paper" | "news" | "pdf" | "tweet" | "personal site" | "financial report" | "people"A data category to focus on. includeText string[]List of strings that must be present in webpage text. Max 1 string of up to 5 words. excludeText string[]List of strings that must not be present in webpage text. Max 1 string of up to 5 words. contents ContentsOptionsOptions for retrieving page contents for each result. moderation booleanIf true, the search results are moderated for safety. useAutoprompt booleanIf true, uses autoprompt to enhance the query. userLocation stringThe two-letter ISO country code of the user, e.g. US. additionalQueries string[]Alternative query formulations for deep search. Max 5 queries. Only for type: “deep”.
FindSimilarOptions
Options for finding similar links.
Type: BaseSearchOptions & { excludeSourceDomain?: boolean; }
Field Type Description links number- imageLinks number-
TextContentsOptions
Options for retrieving text from page.
Field Type Description maxCharacters number- includeHtmlTags boolean- verbosity VerbosityOptions- includeSections SectionTag[]- excludeSections SectionTag[]-
HighlightsContentsOptions
Options for retrieving highlights from page.
NOTE: For search type “deep”, these options will not be respected. Highlights will be generated with respect
to your initial query, and may vary in quantity and length.
Field Type Description query string- numSentences number- highlightsPerUrl number-
SummaryContentsOptions
Options for retrieving summary from page.
Field Type Description query string- schema Record<string, unknown> | ZodSchema-
ContextOptions
Options for retrieving the context from a list of search results. The context is a string
representation of all the search results.
Field Type Description maxCharacters number-
AnswerOptions
Options for the answer endpoint
Field Type Description text booleanWhether to include text in the source results. Default false. model "exa"The model to use for generating the answer. Default “exa”. stream booleanWhether to stream the response. Default false. systemPrompt stringA system prompt to guide the LLM’s behavior when generating the answer. outputSchema Record<string, unknown>A JSON Schema specification for the structure you expect the output to take. userLocation stringThe two-letter ISO country code of the user, e.g. US.
Response Types
These types represent API response objects.
CostDollars
Represents the total cost breakdown. Only non-zero costs are included.
Field Type Description total number- search CostDollarsSeearch- contents CostDollarsContents-
SearchResult
Represents a search result object.
Field Type Description title string | nullThe title of the search result. url stringThe URL of the search result. id stringThe temporary ID for the document. publishedDate stringThe estimated creation date of the content. author stringThe author of the content, if available. score numberSimilarity score between the query/url and the result. image stringA representative image for the content, if any. favicon stringA favicon for the site, if any. text stringThe text content of the page (if text option enabled). highlights string[]Highlighted text snippets (if highlights option enabled). highlightScores number[]Scores for each highlight. summary stringSummary of the content (if summary option enabled). entities Entity[]Structured entity data for company or person search results.
SearchResponse
Represents a search response object.
Field Type Description results SearchResult<T>[]The list of search results. requestId stringThe request ID for the search. context stringThe context for the search (for deep search). autoDate stringThe autoprompt date, if applicable. statuses Status[]Status information for each result. costDollars CostDollarsThe cost breakdown for this request.
Status
Field Type Description id string- status string- source string-
AnswerResponse
Represents an answer response object from the /answer endpoint.
Field Type Description answer string | Record<string, unknown>The generated answer text (or object matching outputSchema if provided). citations SearchResult<{}>[]The sources used to generate the answer. requestId stringThe request ID for the answer. costDollars CostDollarsThe cost breakdown for this request.
AnswerStreamChunk
Field Type Description content stringThe partial text content of the answer (if present in this chunk). citations Array<{id, url, title?, publishedDate?, author?, text?}>Citations associated with the current chunk of text (if present).
Entity Types
These types represent structured entity data returned for company or person searches.
ResearchModel
The model to use for research tasks.
Type: ‘exa-research-fast’ | ‘exa-research’ | ‘exa-research-pro’
EntityCompanyProperties
Structured properties for a company entity.
Field Type Description name string | nullThe company name. foundedYear number | nullThe year the company was founded. description string | nullA description of the company. workforce EntityCompanyPropertiesWorkforce | nullInformation about the company’s workforce. headquarters EntityCompanyPropertiesHeadquarters | nullInformation about the company’s headquarters location. financials EntityCompanyPropertiesFinancials | nullFinancial information about the company. webTraffic EntityCompanyPropertiesWebTraffic | nullWeb traffic statistics for the company.
EntityPersonProperties
Structured properties for a person entity.
Field Type Description name string | nullThe person’s name. location string | nullThe person’s location. workHistory EntityPersonPropertiesWorkHistoryEntry[]The person’s work history.
CompanyEntity
Structured entity data for a company.
Field Type Description id stringUnique identifier for the entity. type "company"The entity type (always “company”). version numberThe version of the entity schema. properties EntityCompanyPropertiesStructured properties for the company.
PersonEntity
Structured entity data for a person.
Field Type Description id stringUnique identifier for the entity. type "person"The entity type (always “person”). version numberThe version of the entity schema. properties EntityPersonPropertiesStructured properties for the person.