0

Find similar links

by
Published Oct 17, 2025

Find similar links to the link provided. 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
 * Find similar links
7
 * Find similar links to the link provided. Optionally get contents.
8
 */
9
export async function main(
10
  auth: Exa,
11
  body: { url: string } & {
12
    numResults?: number;
13
    includeDomains?: string[];
14
    excludeDomains?: string[];
15
    startCrawlDate?: string;
16
    endCrawlDate?: string;
17
    startPublishedDate?: string;
18
    endPublishedDate?: string;
19
    includeText?: string[];
20
    excludeText?: string[];
21
    contents?: {
22
      text?:
23
        | false
24
        | true
25
        | { maxCharacters?: number; includeHtmlTags?: false | true };
26
      highlights?: {
27
        numSentences?: number;
28
        highlightsPerUrl?: number;
29
        query?: string;
30
      };
31
      summary?: { query?: string };
32
      livecrawl?: "never" | "fallback" | "always" | "auto";
33
      livecrawlTimeout?: number;
34
      subpages?: number;
35
      subpageTarget?: string | string[];
36
      extras?: { links?: number; imageLinks?: number };
37
    };
38
  },
39
) {
40
  const url = new URL(`https://api.exa.ai/findSimilar`);
41

42
  const response = await fetch(url, {
43
    method: "POST",
44
    headers: {
45
      "Content-Type": "application/json",
46
      "X-API-Key": auth.apiKey,
47
    },
48
    body: JSON.stringify(body),
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56