Skip to main content

Official SDKs

Official SDKs for five languages

Install one package and call image, video and audio models from your own server. The SDK handles authentication and waiting for results, so you only write the request and read the answer.

What the SDK does for you

You write one function call. The SDK signs the request, uploads your files, waits for the result and hands it back as typed data.

  1. Your codeOne function call
  2. Official SDKSigns requests, uploads files, waits for results
  3. Image, video and audio modelsSame models and prices as the website
Without an SDK you send the same requests yourself over HTTPS. The SDK just removes the boilerplate.

Good for

  • Backend servicesGenerate media inside your own API or job queue.
  • Scripts and batch jobsCreate many tasks from a spreadsheet or a scheduled job.
  • Apps with a serverKeep the key on the server and send finished files to users.

Get started in three steps

  1. Step 1

    Create an API key

    Make one in the console and store it as SPICY_API_KEY on your server.

  2. Step 2

    Install the package

    Pick your language below and run the install line.

  3. Step 3

    Create a task, read the result

    Send a prompt, wait for the task, then save the file it returns.

Pick your language

Every SDK is published to its language's main registry and talks to the same API. Switch tabs to see the install line and a complete request.

TypeScript

@spicyapi/sdk

Requires Node.js 22.13+

Your server creates tasks and stores results. Install, export the key, run.

Install · bash
npm install @spicyapi/sdk
export SPICY_API_KEY="injected from your secret manager"
Create a task and read the result · ts
import { randomUUID } from "node:crypto";
import { SpicyClient } from "@spicyapi/sdk";

const client = new SpicyClient();
const model = await client.getModel("MODEL_ID_FROM_CATALOG");
const task = await client.run(
  { model: model.model, input: { prompt: "A cinematic night portrait" } },
  { idempotencyKey: randomUUID() },
);
console.log(task.state, task.output?.assets?.[0]?.url);

What happens after you submit

Image and video generation keeps running after the create call returns. Save the task ID, then let a webhook or a bounded status check tell you when it is done.

  1. createTaskSubmit with an idempotency key; one generation is accepted once.
  2. taskIdThe response comes back immediately while the task keeps running.
  3. Webhook / recordInfoA signed webhook first; bounded polling only to recover.
  4. output.assetsReady-to-use URLs. Keep your own copy of anything that matters.

Calling from a browser or mobile app

A key inside a client app is a public key. Keep it on your server: @spicyapi/proxy adds the credential to requests from your front end, so the app never sees it.

  • Key inside the appAnyone can read it and spend your balance.
    1. App with the key inside
    2. SpicyAPI
  • Key on your serverThe app talks to your server, and the proxy adds the key.
    1. Browser or phone
    2. Your server + proxy
    3. SpicyAPI
@spicyapi/proxy
npm install @spicyapi/proxy
next.js
// app/api/spicy/proxy/route.ts
export { GET, POST } from "@spicyapi/proxy/nextjs";
export const runtime = "nodejs";

Before you go live

  • 01Confirm the model is currently available.
  • 02Validate the exact fields shown on its model page.
  • 03Keep the API key on the server.
  • 04Show the expected cost before submission.
  • 05Persist taskId outside the browser session.
  • 06Verify webhook signatures or bound status checks.
  • 07Treat an accepted task as final and non-cancelable.

Fix common errors

Most first-time problems are one of these three. Each card shows what you see and the one thing to change.

  • 401

    Invalid API key

    No key or a wrong one reached the API. Set SPICY_API_KEY in the same environment your code runs in.

  • wait

    Task still running

    Videos can take a few minutes. Wait with a time limit or use a webhook. Resubmitting without the same Idempotency-Key creates a second paid task.

  • link

    Result link expired

    Download links are short-lived. Ask for a fresh link for the task instead of storing the old one.

Questions people ask