0

Generate an image

by
Published Oct 17, 2025

Generate an image with the provided prompt

Script lumaai Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Lumaai = {
3
  apiKey: string;
4
};
5
/**
6
 * Generate an image
7
 * Generate an image with the provided prompt
8
 */
9
export async function main(
10
  auth: Lumaai,
11
  body: {
12
    generation_type?: "image";
13
    model?: "photon-1" | "photon-flash-1";
14
    prompt?: string;
15
    aspect_ratio?: "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "21:9" | "9:21";
16
    callback_url?: string;
17
    image_ref?: { url?: string; weight?: number }[];
18
    style_ref?: { url?: string; weight?: number }[];
19
    character_ref?: { identity0?: { images?: string[] } };
20
    modify_image_ref?: { url?: string; weight?: number };
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.lumalabs.ai/dream-machine/v1/generations/image`,
25
  );
26

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