Skip to main content

Documentation Index

Fetch the complete documentation index at: https://exa.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

New to Exa? Try the Coding Agent Quickstart to get started in under a minute.
The official JavaScript SDK for Exa. Search the web, get page contents, and get answers with citations.

Get API Key

Get your API key from the dashboard

Install

bash npm install exa-js

Quick Start

import Exa from "exa-js";

const exa = new Exa(); // reads EXA_API_KEY from environment
  • Start with exa.search(...).
  • Use type: "auto" unless you have a clear latency or synthesis reason to change it.
  • Prefer contents: { highlights: true } for first integrations.
  • Switch to exa.getContents(...) only when you already know the URLs.
  • Prefer maxAgeHours over older livecrawl examples when you need freshness control.
On /search, text, highlights, and summary belong inside contents. On /contents, those same fields are top-level arguments.
Search the web and get page contents in one call.
highlights is a strong default for retrieval workflows because it preserves the most relevant evidence without pulling full page text into every response.
const result = await exa.search("blog post about artificial intelligence", {
  contents: {
    highlights: true,
  },
});
const result = await exa.search("interesting articles about space", {
  numResults: 10,
  includeDomains: ["nasa.gov", "space.com"],
  startPublishedDate: "2024-01-01",
  contents: {
    highlights: true,
  },
});
const structuredResult = await exa.search("Who is the CEO of OpenAI?", {
  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"],
  },
  contents: {
    highlights: true,
  },
});

console.log(structuredResult.output?.content);
outputSchema and systemPrompt work across all search types. Keep outputSchema focused on output.content, and use systemPrompt to guide the final returned result. For more demanding synthesis, prefer reasoning-focused search types like deep-lite, deep, or deep-reasoning. Do not include citations/confidence in your schema; Exa returns grounding automatically in output.grounding. Including citation/confidence fields in outputSchema duplicates data, reduces structure quality, and is usually less reliable.
Reasoning-focused search variants:
  • deep-lite: lowest-latency deep-search mode
  • deep: light mode
  • deep-reasoning: base reasoning mode
Need streaming structured synthesis? The raw /search endpoint supports stream: true together with outputSchema and returns OpenAI-compatible SSE chunks. See the Search API guide.

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: 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

The Research API (/research/v1) is legacy and deprecated. For new integrations, use exa.search(...) with type: "deep-reasoning" and outputSchema for structured research-style output.
const result = await exa.search("Find the top 5 AI startups founded in 2024", {
  type: "deep-reasoning",
  outputSchema: {
    type: "object",
    properties: {
      startups: { type: "array", items: { type: "string" } },
    },
  },
  contents: { highlights: true },
});

TypeScript

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

Resources

  • GitHub - View source code
  • npm - View package

Continue

Search guide

Return to the main Search guide for request patterns, filters, and deeper modes.

Search reference

Jump to the full /search request and response schema.

Contents guide

Use Contents when you already know the URLs and want direct extraction.

TypeScript SDK spec

See the full JavaScript and TypeScript SDK method and type reference.