Docs
Generate and edit images with the best AI models over a simple HTTP API. Generation is asynchronous: submit a request, poll until it’s done, then fetch the image.
Authentication
All requests require an API key. Create one in Settings → API Keys and send it as a bearer token (or an x-api-key header). Credits are the spend cap — each image costs credits by model and resolution.
Authorization: Bearer <your-api-key>
# or
x-api-key: <your-api-key>Base URL: https://modelmux.dev
Generate an image
Enqueues a generation and returns immediately with status: "pending" and an historyId. Credits are charged when the job runs and refunded automatically if it fails. The request body is selected by Content-Type.
Send application/json. Fields: prompt (required), model, resolution, aspectRatio.
curl -X POST https://modelmux.dev/api/v1/generations \
-H 'Authorization: Bearer <your-api-key>' \
-H 'Content-Type: application/json' \
-d '{
"prompt": "a red fox in fresh snow, golden hour",
"model": "nano-banana-pro",
"resolution": "2k",
"aspectRatio": "16:9"
}'Response (202-style, pending)
{
"historyId": "V1StGXR8_Z5jdHi6B-myT",
"status": "pending",
"model": "nano-banana-pro",
"aspectRatio": "16:9",
"resolution": "2k",
"creditsCharged": 13,
"provider": "kie",
"createdAt": 1733011200000
}Poll status
Poll with the historyId every few seconds until status is completed (or failed). Most images finish in seconds; large/4K jobs take longer.
curl https://modelmux.dev/api/v1/generations/V1StGXR8_Z5jdHi6B-myT \
-H 'Authorization: Bearer <your-api-key>'{
"historyId": "V1StGXR8_Z5jdHi6B-myT",
"status": "completed",
"provider": "kie",
"outputUrl": "/api/storage/file?key=generated/…",
"creditsUsed": 13,
"model": "nano-banana-pro",
"resolution": "2k",
"aspectRatio": "16:9",
"completedAt": 1733011230000
}Statuses: pending → processing → completed | failed (with errorMessage).
Fetch the image
Once completed, stream the raw image bytes (key-authenticated). Save it to a file or pipe it onward.
curl https://modelmux.dev/api/v1/generations/V1StGXR8_Z5jdHi6B-myT/image \
-H 'Authorization: Bearer <your-api-key>' \
-o output.pngModels & pricing
Cost is charged in credits, by model and resolution. Pass the model id below; credits line up with the resolutions in the same order.
| Model id | Resolutions | Credits |
|---|---|---|
| nano-banana | 1K | 4 |
| nano-banana-2-lite | 1K | 3 |
| nano-banana-2 | 1K · 2K · 4K | 7 · 10 · 14 |
| nano-banana-pro | 1K · 2K · 4K | 13 · 13 · 22 |
| gpt-image-2 | 1K · 2K · 4K | 8 · 12 · 18 |
For how to choose between models, see Models.
Parameters
| Field | Values | Default |
|---|---|---|
| prompt | string, 5–2000 characters | required |
| model | nano-banana | nano-banana-2-lite | nano-banana-2 | nano-banana-pro | gpt-image-2 | nano-banana-2-lite |
| resolution | 1k | 2k | 4k — must be supported by the model | 1k |
| aspectRatio | 1:1 | 2:3 | 3:2 | 3:4 | 4:3 | 9:16 | 16:9 | 1:1 |
Passing a resolution the model does not support returns 400. Check the table above, or fetch the catalog programmatically.
Discover models programmatically
Agents and clients can read the full catalog — ids, resolutions, aspect ratios, credit costs and defaults — from one unauthenticated endpoint. Prefer this over hardcoding model ids.
curl https://modelmux.dev/api/v1/modelsErrors & status codes
Errors are JSON: { "error": string, "code": string }.
| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad input (invalid body, unsupported model/resolution) |
| 401 | Missing or invalid API key |
| 404 | Generation not found / image not ready |
| 413 | Reference image too large |
| 415 | Unsupported reference file type (must be an image) |
| 429 | Rate limit exceeded |
| 500 | Unexpected server error |
If a generation failed, the credit is refunded automatically — check errorMessage on the status response.
MCP server
Use ModelMux from any MCP client (Claude Desktop, Cursor, …) via the modelmux-mcp server — it generates an image, polls until ready, and returns it.
{
"mcpServers": {
"modelmux": {
"command": "npx",
"args": ["-y", "modelmux-mcp"],
"env": { "MODELMUX_API_KEY": "<your-api-key>" }
}
}
}Agent skill (Claude Code)
Install the modelmux skill to generate and edit images from Claude Code (and other agents) with bundled recipes.
# project scope → .claude/skills/modelmux/
npx skills add modelmux/skills -a claude-code
# or global → ~/.claude/skills/modelmux/
npx skills add modelmux/skills -a claude-code -gExport MODELMUX_API_KEY where the agent runs, then ask it to “generate an image of …”.