Package Exports
- exa-js
- exa-js/package.json
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: {
highlights: 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: {
highlights: true
}
});const resultWithOutput = await exa.search("Who leads OpenAI's safety team?", {
type: "auto",
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(resultWithOutput.output?.content);for await (const chunk of exa.streamSearch("Who leads OpenAI's safety team?", {
type: "auto"
})) {
if (chunk.content) {
process.stdout.write(chunk.content);
}
}Search outputSchema modes:
type: "text": return plain text inoutput.content(optionally guided bydescription)type: "object": return structured JSON inoutput.content
systemPrompt and outputSchema are supported on every search type.
Search streaming is available via streamSearch(...), which yields OpenAI-style chat completion chunks.
For type: "object", search currently enforces:
- max nesting depth:
2 - max total properties:
10
Deep search variants that also support additionalQueries:
deep-litedeepdeep-reasoning
Contents
Get clean text, highlights, or summaries from any URL.
const { results } = await exa.getContents(["https://docs.exa.ai"], {
text: true,
highlights: true,
summary: 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);
}
}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.