npm add @leonardo-ai/sdk
yarn add @leonardo-ai/sdk
To get access to the API and fetch an API key, please sign up for access.
import { Leonardo } from "@leonardo-ai/sdk";
async function run() {
const sdk = new Leonardo({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.dataset.createDataset({
name: "string",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
- createDataset - Create a Dataset
- deleteDatasetById - Delete a Single Dataset by ID
- getDatasetById - Get a Single Dataset by ID
- uploadDatasetImage - Upload dataset image
- uploadDatasetImageFromGen - Upload a Single Generated Image to a Dataset
- getElements - List Elements
- createGeneration - Create a Generation of Images
- deleteGenerationById - Delete a Single Generation
- deleteGenerationsTextureId - Delete Texture Generation by ID
- getGenerationById - Get a Single Generation
- getGenerationsByUserId - Get generations by user ID
- postGenerationsMotionSvd - Create SVD Motion Generation
- postGenerationsTexture - Create Texture Generation
- deleteInitImageById - Delete init image
- getInitImageById - Get single init image
- uploadInitImage - Upload init image
- getUserSelf - Get user information
- createModel - Train a Custom Model
- deleteModelById - Delete a Single Custom Model by ID
- deleteModels3dId - Delete 3D Model by ID
- getModelById - Get a Single Custom Model by ID
- getPlatformModels - List Platform Models
- postModels3dUpload - Upload 3D Model
- createVariationNoBG - Create no background
- createVariationUpscale - Create upscale
- getVariationById - Get variation by ID
- postVariationsUnzoom - Create unzoom
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Example
import { Leonardo } from "@leonardo-ai/sdk";
async function run() {
const sdk = new Leonardo({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
let res;
try {
res = await sdk.dataset.createDataset({
name: "string",
});
} catch (err) {
if (err instanceof errors.SDKError) {
console.error(err); // handle exception
throw err;
}
}
if (res.statusCode == 200) {
// handle response
}
}
run();
The Typescript SDK makes API calls using the axios HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance
object.
For example, you could specify a header for every request that your sdk makes as follows:
import { @leonardo-ai/sdk } from "Leonardo";
import axios from "axios";
const httpClient = axios.create({
headers: {'x-custom-header': 'someValue'}
})
const sdk = new Leonardo({defaultClient: httpClient});
You can override the default server globally by passing a server index to the serverIdx: number
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://cloud.leonardo.ai/api/rest/v1 |
None |
import { Leonardo } from "@leonardo-ai/sdk";
async function run() {
const sdk = new Leonardo({
serverIdx: 0,
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.dataset.createDataset({
name: "string",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
The default server can also be overridden globally by passing a URL to the serverURL: str
optional parameter when initializing the SDK client instance. For example:
import { Leonardo } from "@leonardo-ai/sdk";
async function run() {
const sdk = new Leonardo({
serverURL: "https://cloud.leonardo.ai/api/rest/v1",
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.dataset.createDataset({
name: "string",
});
if (res.statusCode == 200) {
// handle response
}
}
run();
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
bearerAuth |
http | HTTP Bearer |
To authenticate with the API the bearerAuth
parameter must be set when initializing the SDK client instance. For example:
import { Leonardo } from "@leonardo-ai/sdk";
async function run() {
const sdk = new Leonardo({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
const res = await sdk.dataset.createDataset({
name: "string",
});
if (res.statusCode == 200) {
// handle response
}
}
run();