0

Get Contents

by
Published Oct 17, 2025
Script exa Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Exa = {
3
  apiKey: string;
4
};
5
/**
6
 * Get Contents
7
 *
8
 */
9
export async function main(
10
  auth: Exa,
11
  body: { urls: string[]; ids?: string[] } & {
12
    text?:
13
      | false
14
      | true
15
      | { maxCharacters?: number; includeHtmlTags?: false | true };
16
    highlights?: {
17
      numSentences?: number;
18
      highlightsPerUrl?: number;
19
      query?: string;
20
    };
21
    summary?: { query?: string };
22
    livecrawl?: "never" | "fallback" | "always" | "auto";
23
    livecrawlTimeout?: number;
24
    subpages?: number;
25
    subpageTarget?: string | string[];
26
    extras?: { links?: number; imageLinks?: number };
27
  },
28
) {
29
  const url = new URL(`https://api.exa.ai/contents`);
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      "X-API-Key": auth.apiKey,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45