@mage-space/sdk is the official TypeScript client for the Mage API. It wraps every endpoint, types the config of every model, submits a generation and waits for the result in one call, and retries safely without paying twice.
The SDK is in beta at
0.x, so a minor version may still change it. The API
itself is versioned separately and stays stable within v1.Install
fetch. The package is ESM-only with no runtime dependencies; Node.js 20.19 and later can also require() it.
Quick start
Create a key in API → API Keys and export it asMAGE_API_KEY.
run submits the generation, polls it with the backoff the API recommends, and resolves to the completed request. The output is at result.url and is kept for 30 days, so download what you want to keep.
Models
The first argument is the model’s architecture id, as in its endpoint path:mango for images, cherry for video, seed_audio for audio, and every other model. model_id selects a variant.
MangoConfig and CherryConfig, are exported, and ARCHITECTURES lists the models this version of the SDK knows.
A model released after your version of the SDK still works: pass its id as a string, and the config is checked only against the fields every model shares.
Submit and poll separately
Usegenerate when you want the request id before the output is ready, for example to store it and collect the result later.
requests.wait polls from 2 seconds, multiplies the delay by 1.5 after each read up to 15 seconds, adds jitter, and resolves to the final request whatever its status. Its timeout also cuts short a status read in progress; the request keeps running on Mage. requests.get(id) reads a request once, and requests.cancel(id) stops a live one. Gems are not returned for a cancelled request.
Inputs and uploads
Media fields take anhttps URL or a data URL. For a file larger than about 3 MB, or one that is not at a public URL, upload it first and send the URL the upload returns.
upload creates the ticket, checks the size, and sends the file with the headers storage expects. It takes a Blob, an ArrayBuffer, or a typed array such as a Buffer; a Blob supplies its own content type. Uploads expire after 30 days, at clip.url_expires_at. See Inputs and uploads for formats and limits.
Characters and references
Save a character or a reference once, then mention its@handle in any prompt.
mage.references works the same way for objects, locations, poses, outfits, and audio clips.
Errors
Retries and idempotency
Reads, cancels, deletes, and uploads are retried up to twice on network errors and on408, 429, and 5xx responses, with exponential backoff.
generate and run send an Idempotency-Key with every submission, so a retried submission is never charged twice. The SDK makes a new key per call and reuses it when it retries that call itself, which it does only when no response arrived or on a 408 or 5xx that recorded no request. Pass your own key to make retries across processes safe too; see Retrying a submit safely.
Configuration
signal to abort it.
Reference
Source and releases
The SDK is MIT-licensed on GitHub and published to npm. Its model types come from this API reference: when the reference changes, a pull request updates them, so new models and options arrive as new releases. Each release is published with npm provenance, and its changes are in the repository’s changelog.Python SDK
The same API for Python, with sync and asyncio clients.
ComfyUI
Every Mage model as ComfyUI nodes.

