TypeScript SDK setup
Guide
Keep your API key on your server. See SDK timeouts and recovery.
TypeScript
Section titled “TypeScript”Requires Node.js 20+ or Bun. The archive includes compiled JavaScript, types, client source, README, and license.
npm install https://docs.omnapi.com/sdk/omnapi-typescript-0.3.0.tgzimport { OmnapiClient, OmnapiError } from "@omnapi/sdk";
const client = new OmnapiClient({ apiKey: process.env.OMNAPI_KEY!, fetch: (url, init) => fetch(url, { ...init, signal: init?.signal ?? AbortSignal.timeout(30_000), }),});
// Load this key and body from your durable job record on retries.const idempotencyKey = process.env.OMNAPI_REQUEST_KEY!;if (!idempotencyKey) throw new Error("Set and persist OMNAPI_REQUEST_KEY first");try { const receipt = await client.composeProducerMusic( { soundPrompt: "warm indie pop, brushed drums", model: "Lyria 3.5", length: 120 }, { idempotencyKey }, ); // Persist receipt.taskId before waiting. On restart, call getTask with that ID. const task = await client.waitForTask(receipt.taskId, { timeoutMs: 30 * 60_000 }); if (task.status !== "COMPLETED") throw new Error(`Task ended: ${task.status}`); const song = task.resources?.find(resource => resource.type === "MUSIC"); console.log(song?.url);} catch (error) { if (error instanceof OmnapiError) { console.error(error.status, error.code, error.requestId); // Inspect details for taskId, and rateLimit.retryAfter for backoff. } throw error;}This excerpt assumes a durable job store. The downloadable HTTP programs show the persistence step in full. Do not regenerate a key after an uncertain POST.