API Reference

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, resolution, and quality.

Authorization: Bearer <your-api-key>
# or
x-api-key: <your-api-key>

Base URL: https://modelmux.dev

Generate an image

POST/api/v1/generations

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, quality (GPT Image only), 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": 10,
  "provider": "fal",
  "createdAt": 1733011200000
}

Poll status

GET/api/v1/generations/:id

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": "fal",
  "outputUrl": "/api/storage/file?key=generated/…",
  "creditsUsed": 10,
  "model": "nano-banana-pro",
  "resolution": "2k",
  "aspectRatio": "16:9",
  "completedAt": 1733011230000
}

Statuses: pendingprocessing completed | failed (with errorMessage).

Fetch the image

GET/api/v1/generations/:id/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.png

Models & pricing

Cost is charged in credits. Pass the model id below; quality tiers apply to GPT Image only.

Model idResolutionsCredits
nano-banana1K5
nano-banana-21K · 2K · 4K5
nano-banana-pro1K · 2K · 4K10
gpt-image-21K · 2K · 4K2–80 (by resolution × quality)

GPT Image 2 credits: 1K = 2/10/18, 2K = 5/20/40, 4K = 10/32/80 (standard / medium / high). Aspect ratios: 1:1, 2:3, 3:2, 3:4, 4:3, 9:16, 16:9.

Errors & status codes

Errors are JSON: { "error": string, "code": string }.

StatusMeaning
200Success
400Bad input (invalid body, unsupported model/resolution)
401Missing or invalid API key
404Generation not found / image not ready
413Reference image too large
415Unsupported reference file type (must be an image)
429Rate limit exceeded
500Unexpected 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 -g

Export MODELMUX_API_KEY where the agent runs, then ask it to “generate an image of …”.

Ready to start?

New accounts get free credits to try every model.

Create your API key