1 | |
2 | type Leonardoai = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * Create a Generation of Images |
7 | * This endpoint will generate images |
8 | */ |
9 | export async function main( |
10 | auth: Leonardoai, |
11 | body: { |
12 | alchemy?: false | true; |
13 | contrastRatio?: number; |
14 | controlnets?: { |
15 | initImageId?: string; |
16 | initImageType?: "GENERATED" | "UPLOADED"; |
17 | preprocessorId?: number; |
18 | weight?: number; |
19 | strengthType?: "Low" | "Mid" | "High" | "Ultra" | "Max"; |
20 | }[]; |
21 | elements?: { akUUID?: string; weight?: number }[]; |
22 | userElements?: { userLoraId?: number; weight?: number }[]; |
23 | expandedDomain?: false | true; |
24 | fantasyAvatar?: false | true; |
25 | guidance_scale?: number; |
26 | height?: number; |
27 | highContrast?: false | true; |
28 | highResolution?: false | true; |
29 | imagePrompts?: string[]; |
30 | imagePromptWeight?: number; |
31 | init_generation_image_id?: string; |
32 | init_image_id?: string; |
33 | init_strength?: number; |
34 | modelId?: string; |
35 | negative_prompt?: string; |
36 | num_images?: number; |
37 | num_inference_steps?: number; |
38 | photoReal?: false | true; |
39 | photoRealVersion?: string; |
40 | photoRealStrength?: number; |
41 | presetStyle?: |
42 | | "ANIME" |
43 | | "BOKEH" |
44 | | "CINEMATIC" |
45 | | "CINEMATIC_CLOSEUP" |
46 | | "CREATIVE" |
47 | | "DYNAMIC" |
48 | | "ENVIRONMENT" |
49 | | "FASHION" |
50 | | "FILM" |
51 | | "FOOD" |
52 | | "GENERAL" |
53 | | "HDR" |
54 | | "ILLUSTRATION" |
55 | | "LEONARDO" |
56 | | "LONG_EXPOSURE" |
57 | | "MACRO" |
58 | | "MINIMALISTIC" |
59 | | "MONOCHROME" |
60 | | "MOODY" |
61 | | "NONE" |
62 | | "NEUTRAL" |
63 | | "PHOTOGRAPHY" |
64 | | "PORTRAIT" |
65 | | "RAYTRACED" |
66 | | "RENDER_3D" |
67 | | "RETRO" |
68 | | "SKETCH_BW" |
69 | | "SKETCH_COLOR" |
70 | | "STOCK_PHOTO" |
71 | | "VIBRANT" |
72 | | "UNPROCESSED"; |
73 | prompt: string; |
74 | promptMagic?: false | true; |
75 | promptMagicStrength?: number; |
76 | promptMagicVersion?: string; |
77 | public?: false | true; |
78 | scheduler?: |
79 | | "LEONARDO" |
80 | | "KLMS" |
81 | | "EULER_ANCESTRAL_DISCRETE" |
82 | | "EULER_DISCRETE" |
83 | | "DDIM" |
84 | | "DPM_SOLVER" |
85 | | "PNDM"; |
86 | sd_version?: |
87 | | "v1_5" |
88 | | "v2" |
89 | | "v3" |
90 | | "SDXL_0_8" |
91 | | "SDXL_0_9" |
92 | | "SDXL_1_0" |
93 | | "SDXL_LIGHTNING" |
94 | | "PHOENIX" |
95 | | "FLUX" |
96 | | "FLUX_DEV"; |
97 | seed?: number; |
98 | tiling?: false | true; |
99 | transparency?: "disabled" | "foreground_only"; |
100 | ultra?: false | true; |
101 | unzoom?: false | true; |
102 | unzoomAmount?: number; |
103 | upscaleRatio?: number; |
104 | width?: number; |
105 | controlNet?: false | true; |
106 | controlNetType?: "POSE" | "CANNY" | "DEPTH"; |
107 | weighting?: number; |
108 | canvasRequest?: false | true; |
109 | canvasRequestType?: "INPAINT" | "OUTPAINT" | "SKETCH2IMG" | "IMG2IMG"; |
110 | canvasInitId?: string; |
111 | canvasMaskId?: string; |
112 | enhancePrompt?: false | true; |
113 | enhancePromptInstruction?: string; |
114 | }, |
115 | ) { |
116 | const url = new URL(`https://cloud.leonardo.ai/api/rest/v1/generations`); |
117 |
|
118 | const response = await fetch(url, { |
119 | method: "POST", |
120 | headers: { |
121 | "Content-Type": "application/json", |
122 | Authorization: "Bearer " + auth.apiKey, |
123 | }, |
124 | body: JSON.stringify(body), |
125 | }); |
126 | if (!response.ok) { |
127 | const text = await response.text(); |
128 | throw new Error(`${response.status} ${text}`); |
129 | } |
130 | return await response.json(); |
131 | } |
132 |
|