> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mage.space/llms.txt
> Use this file to discover all available pages before exploring further.

# Mage API

> Run Mage image, video, and audio models from your own code through one authenticated, asynchronous API: submit a generation, poll its status, download the result. Every request is paid in Gems.

The Mage API runs the same models as the app from your own code. You submit a generation to a model's endpoint, get back a request id with a status link, poll it, and download the result. Every request is paid in Gems from your account.

Open the [API dashboard](https://www.mage.space/api) by choosing **API** (Beta) in Mage's navigation. Its **API Keys**, **Billing**, and **Stats** tabs bring key management, Gems billing, and usage together. The floating navigation also opens [MCP](https://www.mage.space/mcp) to connect your assistant and the [Playground](https://www.mage.space/playground) to explore and try models.

To compare models by what they make before you write code, browse [every model on Mage](https://www.mage.space/models), or start from the [developer hub](https://www.mage.space/developers) for the image, video, and audio APIs, the SDKs, and the MCP server.

> [card] [Run your first request](https://docs.mage.space/api/quickstart.md)
>
> Create a key and complete a generation from submission to result.

> [card] [Get an API key](https://www.mage.space/api?tab=api-keys)
>
> Open API → API Keys, select Create API key, and name it in the popup. Copy
> the one-time key, then use the quick start shown below it.

## Make a request

Every model shares the same authentication, the same request lifecycle, and the same field names. The JSON body depends on the model.

```bash cURL theme={null}
curl --request POST \
  --url https://api.mage.space/v1/flux2/generate \
  --header "Authorization: Bearer $MAGE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{ "prompt": "Editorial portrait in soft daylight", "aspect_ratio": "4:5" }'
```

```ts TypeScript SDK theme={null}
import Mage from '@mage-space/sdk';

const mage = new Mage(); // reads MAGE_API_KEY

const request = await mage.generate('flux2', {
  prompt: 'Editorial portrait in soft daylight',
  aspect_ratio: '4:5',
});
```

```python Python SDK theme={null}
from mage_space import Mage

mage = Mage()  # reads MAGE_API_KEY

request = mage.generate("flux2", {
    "prompt": "Editorial portrait in soft daylight",
    "aspect_ratio": "4:5",
})
```

The API answers at once with the request's id, its state, and the links to check or cancel it. The SDKs' `run` goes one step further: it waits for the result and returns the finished request.

```json theme={null}
{
  "request_id": "d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff",
  "status": "in_progress",
  "architecture": "flux2",
  "model_id": "flux2-dev",
  "created_at": "2026-09-17T14:52:48.000Z",
  "updated_at": "2026-09-17T14:52:49.000Z",
  "billing": { "mode": "gems", "gems_charged": 40 },
  "result": null,
  "error": null,
  "status_url": "https://api.mage.space/v1/requests/d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff/status",
  "cancel_url": "https://api.mage.space/v1/requests/d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff/cancel"
}
```

## Choose your path

> [card] [Ship to production](https://docs.mage.space/api/requests.md)
>
> The request lifecycle, polling, cancellation, errors, and limits.

> [card] [Send images, video, and audio](https://docs.mage.space/api/inputs.md)
>
> URLs, data URLs, and uploads for files larger than a request body.

> [card] [Pick a model](https://docs.mage.space/api/models/overview.md)
>
> Every model with its fields, tokens, defaults, and price.

## SDKs and integrations

> [card] [TypeScript SDK](https://docs.mage.space/api/sdks/typescript.md)
>
> `npm install @mage-space/sdk`. Typed configs for every model.

> [card] [Python SDK](https://docs.mage.space/api/sdks/python.md)
>
> `pip install mage-space`. Sync and asyncio clients.

> [card] [ComfyUI](https://docs.mage.space/api/integrations/comfyui.md)
>
> Every Mage model as ComfyUI nodes. No GPU needed.

The SDKs submit and wait for results, send an idempotency key with every submission so a retry never charges twice, and upload large files for you. They are open source in the [mage-space GitHub organization](https://github.com/mage-space).

## Base URL

Every endpoint lives under `https://api.mage.space/v1`. Fields, models, and endpoints are added within `v1`; anything that would break an existing client ships as a new version. See [versioning](https://docs.mage.space/api/versioning.md).

> [!NOTE]
>
> Results and inputs are kept for 30 days. Download what you want to keep.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.