0

Create a generation

by
Published Oct 17, 2025

Initiate a new generation 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
 * Create a generation
7
 * Initiate a new generation with the provided prompt
8
 */
9
export async function main(
10
  auth: Lumaai,
11
  body: {
12
    generation_type?: "video";
13
    prompt?: string;
14
    aspect_ratio?: "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "21:9" | "9:21";
15
    loop?: false | true;
16
    keyframes?: {
17
      frame0?:
18
        | { type: "generation"; id: string }
19
        | { type: "image"; url: string };
20
      frame1?:
21
        | { type: "generation"; id: string }
22
        | { type: "image"; url: string };
23
    };
24
    callback_url?: string;
25
    model?: "ray-1-6" | "ray-2" | "ray-flash-2";
26
    resolution?: string;
27
    duration?: string;
28
  },
29
) {
30
  const url = new URL(`https://api.lumalabs.ai/dream-machine/v1/generations`);
31

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