0

Perform inpainting on a LCM image

by
Published Apr 8, 2025

This endpoint will perform a inpainting 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 inpainting on a LCM image
7
 * This endpoint will perform a inpainting on a LCM image
8
 */
9
export async function main(
10
  auth: Leonardoai,
11
  body: {
12
    imageDataUrl: string;
13
    maskDataUrl: string;
14
    prompt: string;
15
    guidance?: number;
16
    strength?: number;
17
    requestTimestamp?: string;
18
    style?:
19
      | "ANIME"
20
      | "CINEMATIC"
21
      | "DIGITAL_ART"
22
      | "DYNAMIC"
23
      | "ENVIRONMENT"
24
      | "FANTASY_ART"
25
      | "ILLUSTRATION"
26
      | "PHOTOGRAPHY"
27
      | "RENDER_3D"
28
      | "RAYTRACED"
29
      | "SKETCH_BW"
30
      | "SKETCH_COLOR"
31
      | "VIBRANT"
32
      | "NONE";
33
    steps?: number;
34
    width?: number;
35
    height?: number;
36
    seed?: number;
37
  },
38
) {
39
  const url = new URL(`https://cloud.leonardo.ai/api/rest/v1/lcm-inpainting`);
40

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