0

Create image

by
Published Oct 17, 2025

Use an image model to generate an image for a given prompt.

Script togetherai Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Togetherai = {
3
  api_key: string;
4
};
5
/**
6
 * Create image
7
 * Use an image model to generate an image for a given prompt.
8
 */
9
export async function main(
10
  auth: Togetherai,
11
  body: {
12
    prompt: string;
13
    model: string;
14
    steps?: number;
15
    image_url?: string;
16
    seed?: number;
17
    n?: number;
18
    height?: number;
19
    width?: number;
20
    negative_prompt?: string;
21
    response_format?: "base64" | "url";
22
  },
23
) {
24
  const url = new URL(`https://api.together.xyz/v1/images/generations`);
25

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