0

Perform instant refine on a LCM image

by
Published Apr 8, 2025

This endpoint will perform instant refine on a LCM image

Script leonardoai Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Leonardoai = {
3
  apiKey: string;
4
};
5
/**
6
 * Perform instant refine on a LCM image
7
 * This endpoint will perform instant refine on a LCM image
8
 */
9
export async function main(
10
  auth: Leonardoai,
11
  body: {
12
    imageDataUrl: string;
13
    prompt: string;
14
    guidance?: number;
15
    strength?: number;
16
    requestTimestamp?: string;
17
    style?:
18
      | "ANIME"
19
      | "CINEMATIC"
20
      | "DIGITAL_ART"
21
      | "DYNAMIC"
22
      | "ENVIRONMENT"
23
      | "FANTASY_ART"
24
      | "ILLUSTRATION"
25
      | "PHOTOGRAPHY"
26
      | "RENDER_3D"
27
      | "RAYTRACED"
28
      | "SKETCH_BW"
29
      | "SKETCH_COLOR"
30
      | "VIBRANT"
31
      | "NONE";
32
    steps?: number;
33
    width?: number;
34
    height?: number;
35
    seed?: number;
36
  },
37
) {
38
  const url = new URL(
39
    `https://cloud.leonardo.ai/api/rest/v1/lcm-instant-refine`,
40
  );
41

42
  const response = await fetch(url, {
43
    method: "POST",
44
    headers: {
45
      "Content-Type": "application/json",
46
      Authorization: "Bearer " + auth.apiKey,
47
    },
48
    body: JSON.stringify(body),
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56