TypeScript SDK
npm install @halationlab/sdkThe SDK is for server-side code. Never use an API key in a browser.
Quickstart
Section titled “Quickstart”// Generates a 5-second video with the TypeScript SDK and prints its download URL. Spends at most 400 tokens.import { HalationLab } from '@halationlab/sdk';
const hl = new HalationLab({ apiKey: process.env.HALATIONLAB_API_KEY });
// run() starts the generation and waits until it is completed, failed or canceled.const generation = await hl.generations.run({ model: 'seedance-2.5', input: { prompt: 'A red fox running through snow', duration: 5, aspect_ratio: '16:9' }, max_cost: 400,});
console.log(generation.status, generation.cost.charged, generation.outputs[0]?.url);hl.generations.run() starts a generation and waits until it is final. Every write sends an Idempotency-Key for you, so retries are safe.
Resources
Section titled “Resources”| Resource | Methods |
|---|---|
hl.generations |
create, get, list, cancel, run (create, then wait until final) |
hl.quotes |
create |
hl.models |
list, get |
hl.projects |
Create, read, list, update and archive projects |
hl.assets |
create (import from a URL or data URI), get, list, delete, transform, upload (a local file, in one call) |
hl.uploads |
The upload steps, for when you need them yourself |
hl.account |
get |
hl.webhookEndpoints |
Create, list and delete webhook endpoints |
hl.events |
list |
hl.webhooks |
verify(body, headers, secret) |
Methods follow the API reference: request fields and response objects have the same names as in the API.
Errors
Section titled “Errors”Failed requests throw HalationLabError with type, code, status, param and requestId, from the error object.
// The TypeScript SDK: a client, a few reads and typed errors.import { HalationLab, HalationLabError } from '@halationlab/sdk';
const hl = new HalationLab({ apiKey: process.env.HALATIONLAB_API_KEY });
const account = await hl.account.get();console.log(account.credential.name, account.balance?.available);
const models = await hl.models.list({ task: 'text-to-video' });for (const model of models.data) console.log(model.id, model.name);
try { await hl.models.get('not-a-model');} catch (e) { if (!(e instanceof HalationLabError)) throw e; console.log(e.status, e.type, e.code, e.param, e.requestId);}Uploads and webhooks
Section titled “Uploads and webhooks”// Uploads a local file with the TypeScript SDK, which hashes it, sends the parts and waits for the asset.import { HalationLab } from '@halationlab/sdk';
const hl = new HalationLab({ apiKey: process.env.HALATIONLAB_API_KEY });
const asset = await hl.assets.upload(process.argv[2] ?? 'product.png');console.log(asset.id, asset.status);// Verifies a webhook with the TypeScript SDK. Pass the raw body exactly as received, not re-serialised JSON.import { HalationLab } from '@halationlab/sdk';
const hl = new HalationLab({ apiKey: process.env.HALATIONLAB_API_KEY });
export async function handle(rawBody: string, headers: Record<string, string>) { // Rejects if the signature or timestamp is not valid. const event = await hl.webhooks.verify(rawBody, headers, process.env.HL_WEBHOOK_SECRET!); return event;}