Guides

Image generation

Generate and edit images through the OpenAI Images-compatible API, with models such as `gpt-image-2`, `gpt-image-2.5-flare`, `gpt-image-2.5-sunburst`, `nano-banana-2`, `nano-banana-2.1` and `nano-banana-pro`.

Text to image

curl https://api.flyrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $FLYROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  --max-time 660 \
  -d '{
    "model": "nano-banana-2",
    "prompt": "An orange cat typing on a keyboard, flat illustration",
    "resolution": "2K",
    "size": "16:9"
  }'

Generation usually takes from tens of seconds to a few minutes, and the API waits until the image is ready before responding, so set your client timeout to 10 minutes or more. The response has the same shape as OpenAI's:

json
{
  "created": 1761800000,
  "data": [
    { "url": "https://api.flyrouter.ai/v1/tasks/task_abc/artifacts/image-0/content?access=..." }
  ]
}

The image URL carries an access token, so you can download or display it directly without an API key. Download images you want to keep to your own storage. To get the image data directly, add "response_format": "b64_json" and each image is returned as Base64 in data[].b64_json.

Parameters

ParameterDescription
modelRequired. The image model ID
promptRequired. What to draw
resolutionOutput resolution, default 1K. GPT Image supports 1K/2K/4K; nano-banana-2 also supports 0.5K
sizeAspect ratio, such as 1:1, 16:9 or 9:16. GPT Image accepts only ratios, not pixel sizes like 1024x1024
nNumber of images. gpt-image-2.5-* supports 1–4; other models support 1
image_urlsArray of reference image URLs (Data URLs also work) for image-to-image or blending
response_formaturl (default) or b64_json

Prices vary by resolution; see the model pricing page.

Edit an image

Use POST /v1/images/edits to upload an image and describe the change. The request is multipart/form-data, the image field is image (use image[] for several), and each file can be up to 20 MB:

Terminal
curl https://api.flyrouter.ai/v1/images/edits \
  -H "Authorization: Bearer $FLYROUTER_API_KEY" \
  --max-time 660 \
  -F model="nano-banana-2" \
  -F image="@photo.png" \
  -F prompt="Replace the background with a starry sky"

Getting results after a timeout

In rare cases generation takes longer than 10 minutes. The API then returns 504 with error code task_timeout, and the error message includes the task ID (for example task_abc). The task still finishes in the background, so you can fetch it later:

Terminal
# Task status: SUCCESS means done, FAILURE means it failed
curl https://api.flyrouter.ai/v1/tasks/task_abc -H "Authorization: Bearer $FLYROUTER_API_KEY"

# Download links for the results
curl https://api.flyrouter.ai/v1/tasks/task_abc/artifacts -H "Authorization: Bearer $FLYROUTER_API_KEY"

Each item returned by artifacts has a content_url, which is the image download URL.

Not supported

  • Streaming responses (stream: true).
  • Failed generations return 400 with error code image_generation_failed and are not billed.
FlyRouter

One key, every top AI model