0

Creates an embedding vector representing the input text.

by
Published Oct 17, 2025
Script groqai Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Groq = {
3
  api_key: string;
4
};
5
/**
6
 * Creates an embedding vector representing the input text.
7
 *
8
 */
9
export async function main(
10
  auth: Groq,
11
  body: {
12
    encoding_format?: "float" | "base64";
13
    input: string | string[];
14
    model: string;
15
    user?: string;
16
  },
17
) {
18
  const url = new URL(`https://api.groq.com/openai/v1/embeddings`);
19

20
  const response = await fetch(url, {
21
    method: "POST",
22
    headers: {
23
      "Content-Type": "application/json",
24
      Authorization: "Bearer " + auth.api_key,
25
    },
26
    body: JSON.stringify(body),
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34