0

Search

by
Published Oct 17, 2025

Perform a search with a Exa prompt-engineered query and retrieve a list of relevant results. Optionally get contents.

Script exa Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Exa = {
3
  apiKey: string;
4
};
5
/**
6
 * Search
7
 * Perform a search with a Exa prompt-engineered query and retrieve a list of relevant results. Optionally get contents.
8
 */
9
export async function main(
10
  auth: Exa,
11
  body: {
12
    query: string;
13
    useAutoprompt?: false | true;
14
    type?: "keyword" | "neural" | "auto";
15
    category?:
16
      | "company"
17
      | "research paper"
18
      | "news"
19
      | "pdf"
20
      | "github"
21
      | "tweet"
22
      | "personal site"
23
      | "linkedin profile"
24
      | "financial report";
25
  } & {
26
    numResults?: number;
27
    includeDomains?: string[];
28
    excludeDomains?: string[];
29
    startCrawlDate?: string;
30
    endCrawlDate?: string;
31
    startPublishedDate?: string;
32
    endPublishedDate?: string;
33
    includeText?: string[];
34
    excludeText?: string[];
35
    contents?: {
36
      text?:
37
        | false
38
        | true
39
        | { maxCharacters?: number; includeHtmlTags?: false | true };
40
      highlights?: {
41
        numSentences?: number;
42
        highlightsPerUrl?: number;
43
        query?: string;
44
      };
45
      summary?: { query?: string };
46
      livecrawl?: "auto" | "never" | "fallback" | "always";
47
      livecrawlTimeout?: number;
48
      subpages?: number;
49
      subpageTarget?: string | string[];
50
      extras?: { links?: number; imageLinks?: number };
51
    };
52
  },
53
) {
54
  const url = new URL(`https://api.exa.ai/search`);
55

56
  const response = await fetch(url, {
57
    method: "POST",
58
    headers: {
59
      "Content-Type": "application/json",
60
      "X-API-Key": auth.apiKey,
61
    },
62
    body: JSON.stringify(body),
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70