0

Get 3D Model by ID

by
Published Apr 8, 2025

This endpoint gets the specific 3D model

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 3D Model by ID
7
 * This endpoint gets the specific 3D model
8
 */
9
export async function main(
10
  auth: Leonardoai,
11
  id: string,
12
  offset: string | undefined,
13
  limit: string | undefined,
14
  body: { id?: string },
15
) {
16
  const url = new URL(`https://cloud.leonardo.ai/api/rest/v1/models-3d/${id}`);
17
  for (const [k, v] of [
18
    ["offset", offset],
19
    ["limit", limit],
20
  ]) {
21
    if (v !== undefined && v !== "" && k !== undefined) {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: "Bearer " + auth.apiKey,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39