Install
Package @looptake/sdk on npm. ESM, no dependencies, types included. Runs on Node 20 and later and in browsers. In a browser, call it from your own backend or with a key that only you hold: a key in a public page can be read by anyone.
Install
npm i @looptake/sdkQuick start
Quote, run and wait
import Looptake from '@looptake/sdk';
const looptake = new Looptake({ apiKey: process.env.LOOPTAKE_API_KEY });
const quote = await looptake.models.quote({ model: 'bytedance/seedance-2.5', seconds: 4 });
console.log(`${quote.credits} credits`);
const run = await looptake.lab.runs.create({
kind: 'video',
models: ['bytedance/seedance-2.5'],
prompt: 'Phone footage at night: a raccoon wipes the steam wand and sighs at the camera.',
});
const done = await looptake.waitFor(run);
console.log(done.items.map((item) => item.outputs[0]?.url));Methods
120 endpoints, one method each, grouped by resource. Path ids come first, then the parameters, then the request options. A method returns the response's data. A paginated method returns { data, pagination }.
| Method | Endpoint |
|---|---|
models.list(params?) | GET /models |
models.quote(params) | POST /models/quote |
lab.runs.create(params) | POST /lab/runs |
lab.runs.get(id) | GET /lab/runs/{id} |
lab.runs.list(params?) | GET /lab/runs |
posts.create(params) | POST /posts |
workspaces.archive(id) | POST /workspaces/{id}/archive |
Every method has its own parameter and response types, such as LabRunsCreateParams and LabRunsCreateResponse. They are generated from the same registry as the API reference.
Errors
A non-2xx answer throws LooptakeError. err.type is the API's error.type; branch on it, never on the message. err.status is the HTTP status. The types are in Errors and rate limits.
Branch on the type
import { LooptakeError } from '@looptake/sdk';
try {
await looptake.lab.runs.create({ kind: 'video', models: ['bytedance/seedance-2.5'], prompt });
} catch (err) {
if (err instanceof LooptakeError && err.type === 'insufficient_credits') {
// Nothing was charged. Top up, then send the same call again.
}
throw err;
}Retries and idempotency
429 rate_limited: waits forRetry-After, then retries. A wait longer than five minutes throws.429 usage_limit_reached: throws at once.- A 5xx or a network error: retried for reads, deletes and calls with an
Idempotency-Key. - The 28 endpoints that spend credits or publish get a random
Idempotency-Key, the same on every retry.
Set the key yourself to keep it across process restarts.
Your own key
await looptake.posts.create(post, { idempotencyKey: `launch-${post.suggestionId}` });Wait for a run
waitFor(run) takes a lab run or its id and polls lab.runs.get until the status is succeeded or failed. The first poll is after 2 seconds and the interval grows to 15 seconds. After timeoutMs (default 10 minutes) it throws LooptakeTimeoutError with the last state. The run keeps going.
Wait
const done = await looptake.waitFor(run.id, {
timeoutMs: 15 * 60_000,
onPoll: (current) => console.error(current.status),
});Options
A method's last argument takes idempotencyKey, signal, headers, timeoutMs and maxRetries. Pass fetch to the client to use your own.
Client options
const looptake = new Looptake({
apiKey: 'lt_live_…',
baseUrl: 'https://looptake.com/api/v1', // the default
timeoutMs: 60_000, // per attempt
maxRetries: 2,
});