Skip to main content
The official JavaScript SDK for Exa. Search the web, get page contents, find similar pages, and get answers with citations.

Get API Key

Get your API key from the dashboard

Install

npm install exa-js

Quick Start

import Exa from "exa-js";

const exa = new Exa(); // reads EXA_API_KEY from environment
Search the web and get page contents in one call.
const result = await exa.search(
  "blog post about artificial intelligence",
  {
    contents: {
      text: true
    }
  }
);
const result = await exa.search("interesting articles about space", {
  numResults: 10,
  includeDomains: ["nasa.gov", "space.com"],
  startPublishedDate: "2024-01-01",
  contents: {
    text: true
  }
});

Get Contents

Get text, summaries, or highlights from URLs.
const { results } = await exa.getContents(["https://openai.com/research"], {
  text: true
});
const { results } = await exa.getContents(["https://stripe.com/docs/api"], {
  summary: true
});
const { results } = await exa.getContents(["https://arxiv.org/abs/2303.08774"], {
  highlights: {
    numSentences: 3
  }
});

Find Similar

Find pages similar to a URL.
const result = await exa.findSimilar(
  "https://paulgraham.com/greatwork.html",
  {
    contents: {
      text: true
    }
  }
);
const result = await exa.findSimilar(
  "https://waitbutwhy.com/2015/01/artificial-intelligence-revolution-1.html",
  {
    excludeSourceDomain: true,
    contents: {
      text: true
    }
  }
);

Answer

Get answers to questions with citations.
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 research tasks with structured output.
const task = 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(task.researchId);

TypeScript

Full TypeScript support with types for all methods.
import Exa from "exa-js";
import type { SearchResponse, RegularSearchOptions } from "exa-js";