Skip to main content
The Spine TypeScript SDK (spine-sdk) is a typed, documented client for the Spine API. It wraps all five public endpoints, polls runs with configurable intervals, and narrows response types through discriminated unions so TypeScript guides you through every run state.

Install

npm install spine-sdk
Works on Node.js 18 or newer, modern browsers, Deno, Bun, and Cloudflare Workers without any extra configuration — it uses the platform’s native fetch and FormData. Full type declarations ship in the package, so TypeScript picks them up out of the box.

First request

import { Spine } from 'spine-sdk';

const client = new Spine({ apiKey: process.env.SPINE_API_KEY! });

const run = await client.runs.create({
  prompt: 'Summarise the Q4 AI chip market in 3 paragraphs.',
  template: 'memo',
});

const terminal = await client.runs.waitForCompletion(run.run_id);

if (terminal.status === 'completed') {
  console.log(terminal.result.final_output);
  for (const artifact of terminal.result.artifacts) {
    console.log(artifact.name, artifact.download_url);
  }
}
Prefer the SPINE_API_KEY environment variable so keys stay out of your source code:
export SPINE_API_KEY=sk_spine_...

What’s in the box

Typed run states

Run is a discriminated union narrowed by status. The compiler forces you to handle each state before touching result, progress, or errors.

Auto-polling

client.runs.waitForCompletion() polls to a terminal state with configurable interval, timeout, and AbortSignal cancellation.

Typed errors

SpineBadRequestError, SpineAuthError, SpineNotFoundError, SpineServerError, SpineTimeoutError, and more — branch on the exact failure.

Runs everywhere

Node, browsers, Deno, Bun, Cloudflare Workers. One package, zero runtime dependencies.

Next steps

Quickstart

Full end-to-end example with uploads, polling, and artifact download.

Runs and polling

All the options on runs.create, waitForCompletion, and manual polling.

Canvas introspection

Walk the block graph and task tree produced by a run.

Errors and retries

Error hierarchy and how to tune the built-in retry policy.