0

Get texture generations by 3D Model ID

by
Published Apr 8, 2025

This endpoint gets the specific texture generations by the 3d model id.

Script leonardoai Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Leonardoai = {
3
  apiKey: string;
4
};
5
/**
6
 * Get texture generations by 3D Model ID
7
 * This endpoint gets the specific texture generations by the 3d model id.
8
 */
9
export async function main(
10
  auth: Leonardoai,
11
  modelId: string,
12
  offset: string | undefined,
13
  limit: string | undefined,
14
  body: { limit?: number; modelId?: string; offset?: number },
15
) {
16
  const url = new URL(
17
    `https://cloud.leonardo.ai/api/rest/v1/generations-texture/model/${modelId}`,
18
  );
19
  for (const [k, v] of [
20
    ["offset", offset],
21
    ["limit", limit],
22
  ]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
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