Stem splitting, in Node.js.
A typed Node and TypeScript client for AI Stem Splitter. Install from npm or JSR, run on Node, Bun, or Deno, and ship a working stem-separation feature in a literal 12-line script — submit a track, poll until ready, and write the 4 stems to disk before the next standup demo.
Install
Authenticate
Generate a key from your developer settings, drop it in your environment as AISTEMSPLITTER_API_KEY, and pass it to the client constructor. The SDK never logs the key and the page never renders more than the public-safe ast_live_ prefix in tooltips.
import { AiStemSplitter } from "@aistemsplitter/sdk";
const client = new AiStemSplitter({
apiKey: process.env.AISTEMSPLITTER_API_KEY!,
});Hello world
Twelve lines, end-to-end. Submit a track, wait for the htdemucs_ft model to finish, and write the four stems — vocals, drums, bass, other — to disk. Paste this into a single .mjs file, set your key, and run it before the standup demo.
import { AiStemSplitter } from "@aistemsplitter/sdk";
import { writeFile } from "node:fs/promises";
const client = new AiStemSplitter({
apiKey: process.env.AISTEMSPLITTER_API_KEY!,
});
// 1. Submit a split job
const job = await client.createSplit({
input: { type: "direct_url", url: "https://example.com/song.mp3" },
stemModel: "htdemucs_ft",
});
// 2. Wait until completion (polls under the hood)
const result = await client.waitForSplit(job.id);
// 3. Download all six stems
for (const [name, url] of Object.entries(result.stems)) {
const audio = await fetch(url).then((r) => r.arrayBuffer());
await writeFile(`./${name}.wav`, Buffer.from(audio));
}Methods
Six typed methods cover the full job lifecycle. Each one is a real TypeScript signature on the published package — autocomplete in your editor, no fetch wrappers to write, no schema to memorize.
Submit a new split job; returns a job id and queued status.
Fetch the current status of a split job.
Poll until the job succeeds, fails, or the timeout elapses.
Paginated list of recent split jobs for the API key.
Get a pre-signed PUT URL for direct browser/server uploads.
Verify the HMAC-SHA256 signature on an incoming webhook payload.
Webhooks
Polling gets you to the demo. Webhooks get you to production. Drop a signed callback URL into createSplit, then verify the HMAC-SHA256 signature with one SDK call in your existing Express or Hono handler.
import { AiStemSplitter } from "@aistemsplitter/sdk";
import { Hono } from "hono";
const app = new Hono();
const client = new AiStemSplitter({
apiKey: process.env.AISTEMSPLITTER_API_KEY!,
});
app.post("/webhooks/aistemsplitter", async (c) => {
const raw = await c.req.text();
const event = client.verifyWebhook(c.req.header(), raw); // throws if invalid
switch (event.type) {
case "split.succeeded":
// event.data.stems → six URLs
break;
case "split.failed":
// event.data.error → { code, message }
break;
}
return c.text("ok");
});FAQ
Does @aistemsplitter/sdk work in Bun and Deno without polyfills?
Yes. The package is dual-published to npm and JSR, so Bun installs via `bun add jsr:@aistemsplitter/sdk` and Deno via `deno add jsr:@aistemsplitter/sdk`. There are no @types/node polyfills, no Buffer shimming required, and no node:fs imports in the client core — the typed surface uses the Web Fetch + Web Streams APIs, which Node 18+, Bun, and Deno all implement natively.
How do I verify webhook signatures in Express, Hono, or Next.js?
Call ast.verifyWebhook({ headers, body }) — it computes the HMAC-SHA256 over the raw body, constant-time-compares against the aistemsplitter-signature header, and throws on tamper. The Webhooks section above shows runnable Express and Hono handlers; for Next.js App Router, use the Hono pattern in a route.ts handler with `await request.text()` to read the raw body before verification.
Is the TypeScript surface real, or `any` everywhere?
Real. Every method on AistemsplitterClient has a typed input + Promise return: createSplit(input: CreateSplitInput) → Promise<Split>, getSplit(id: string) → Promise<Split>, waitForSplit, listSplits, presignUpload, verifyWebhook. The Split + Stem + WebhookEvent types are exported from the package root, so you can import them into your own handlers and storage layer without re-deriving the shape.
How do I handle errors and retries from the SDK?
All methods throw typed errors: AistemsplitterApiError (4xx/5xx with code + message + requestId), AistemsplitterRateLimitError (429 with retryAfter seconds), AistemsplitterNetworkError (transport-level). waitForSplit retries polls automatically with exponential backoff until the SDK timeout (default 5 min) — wrap createSplit / presignUpload in your own retry helper if you need at-least-once submission semantics.
Can I run this in the browser?
No — the SDK is a server-side client. Browser use would expose your API key (any code that reaches the user's machine can read it) and run into CORS on the upload endpoints. Mint a short-lived signed URL on your server with presignUpload and hand only that URL to the browser; do the actual createSplit + waitForSplit calls from a server route, n8n workflow, or background worker.
Next steps
Ship 4 stems before the standup.
Free signup, no credit card. Credit packs that never expire — $0.08–$0.14 per minute depending on volume.