exa-js
v2.8.0
Published
Exa SDK for Node.js and the browser
Downloads
1,093,256
Readme
Exa JavaScript SDK
The official JavaScript SDK for Exa, the web search API built for AI.
Install
npm install exa-jsQuick Start
import Exa from "exa-js";
const exa = new Exa(process.env.EXA_API_KEY);
// Search the web
const result = await exa.search(
"blog post about artificial intelligence",
{
type: "auto",
contents: {
text: true
}
}
);
// Find similar pages
const result = await exa.findSimilar(
"https://paulgraham.com/greatwork.html",
{
contents: {
text: true
}
}
);
// Get answers with citations
const { answer } = await exa.answer("What is the capital of France?");Search
Find webpages using natural language queries.
const result = await exa.search("interesting articles about space", {
numResults: 10,
includeDomains: ["nasa.gov", "space.com"],
startPublishedDate: "2024-01-01",
contents: {
text: true
}
});const deepResult = await exa.search("Who leads OpenAI's safety team?", {
type: "deep",
systemPrompt: "Prefer official sources and avoid duplicate results",
outputSchema: {
type: "object",
properties: {
leader: { type: "string" },
title: { type: "string" },
sourceCount: { type: "number" }
},
required: ["leader", "title"]
}
});
console.log(deepResult.output?.content);Deep outputSchema modes:
type: "text": return plain text inoutput.content(optionally guided bydescription)type: "object": return structured JSON inoutput.content
Deep search also supports systemPrompt to guide both the search process and the final returned result, for example by preferring certain sources, emphasizing novel findings, avoiding duplicates, or constraining output style.
For type: "object", deep search currently enforces:
- max nesting depth:
2 - max total properties:
10
Deep search variants:
deep: light modedeep-reasoning: base reasoning mode
Contents
Get clean text, highlights, or summaries from any URL.
const { results } = await exa.getContents(["https://openai.com/research"], {
text: true,
highlights: true,
summary: true,
});Find Similar
Discover pages similar to a given URL.
const result = await exa.findSimilar(
"https://paulgraham.com/greatwork.html",
{
numResults: 10,
excludeSourceDomain: true,
contents: {
text: true
}
}
);Answer
const response = await exa.answer("What caused the 2008 financial crisis?");
console.log(response.answer);for await (const chunk of exa.streamAnswer("Explain quantum computing")) {
if (chunk.content) {
process.stdout.write(chunk.content);
}
}Research
Run autonomous research tasks that return structured data.
const { researchId } = await exa.research.create({
instructions: "Find the top 5 AI startups founded in 2024",
outputSchema: {
type: "object",
properties: {
startups: { type: "array", items: { type: "string" } },
},
},
});
const result = await exa.research.pollUntilFinished(researchId);TypeScript
Full TypeScript support with types for all methods.
import Exa from "exa-js";
import type { SearchResponse, RegularSearchOptions } from "exa-js";Links
Contributing
Pull requests welcome! For major changes, open an issue first.
