Installation, initialisation, and method coverage for the @livepeer/ai JavaScript SDK and livepeer-ai Python SDK.
Two official SDKs wrap the Livepeer AI Gateway REST API: @livepeer/ai for JavaScript and TypeScript, and livepeer-ai for Python. Both are generated programmatically from the ai-runner OpenAPI specification and cover the same set of pipeline endpoints.
@livepeer/ai is in alpha. Pin your dependency to a specific version to avoid unintended breaking changes on update.
import { Livepeer } from '@livepeer/ai';const livepeer = new Livepeer({ httpBearer: '<YOUR_GATEWAY_TOKEN>',});
For development against the public community Gateway at dream-gateway.livepeer.cloud, no bearer token is required. Pass an empty string or omit the field for unauthenticated access.Text-to-image example:
import { Livepeer } from '@livepeer/ai';const livepeer = new Livepeer({ httpBearer: '',});const result = await livepeer.generate.textToImage({ modelId: 'ByteDance/SDXL-Lightning', prompt: 'A fox sitting on a moonlit rooftop', width: 1024, height: 1024,});console.log(result.imageResponse?.images?.[0]?.url);
Error handling:The SDK throws typed errors. SDKValidationError indicates the response did not match the expected schema. HTTPError covers Gateway-level HTTP errors.
import { Livepeer } from '@livepeer/ai';import { HTTPError, SDKValidationError } from '@livepeer/ai/models/errors';try { const result = await livepeer.generate.textToImage({ ... });} catch (err) { if (err instanceof SDKValidationError) { console.error(err.pretty()); } else if (err instanceof HTTPError) { console.error(err.statusCode, err.body); }}
Custom Gateway URL:
const livepeer = new Livepeer({ serverURL: 'https://your-gateway.example.com', httpBearer: '<YOUR_TOKEN>',});