Skip to main content
Last updated: 2026-09-18

Async Image Generation

One image generation usually takes 20–120 seconds. The synchronous endpoints keep the HTTP connection open the whole time, which runs into gateway/proxy read timeouts, and the base64 payloads are large. Async mode splits the call in two:
  1. Submit: the request returns 202 with a task ID in under a second.
  2. Poll: GET /v1/tasks/{id} until it completes; result then carries an https URL for each image (permanently archived on media.crazyrouter.com). Base64 is never returned by default.
Model names, request bodies and billing are identical to the synchronous calls. Async only changes when you get the result; the same API key can mix sync and async requests freely. Failed tasks are not billed.

Supported models

Do not change a single byte of the body, headers or query string. Only swap the action suffix :generateContent for :asyncGenerateContent.
cURL
Returns 202:
model in the response is the resolved underlying model (e.g. gemini-3.1-flash-image-preview), matching your usage logs; you still submit with nano-banana-2. Reference-image editing works exactly like the sync call: put inlineData (base64) or fileData (URL) parts in contents.
:asyncGenerateContent accepts image-output models only; a text model returns 400 async mode is only available for image models. The streaming action :streamGenerateContent has no async form.

Option 2: OpenAI image endpoints with a Prefer header

Add the HTTP header Prefer: respond-async to an otherwise unchanged /v1/images/generations or /v1/images/edits request. Equivalently, send the body field "async": true (JSON) or the form field async=true (multipart).
The response carries Preference-Applied: respond-async and the same 202 body as Option 1.

Polling a task

You can only read tasks submitted by your own account; any other ID returns 404. Poll every 2–3 seconds and treat 10 minutes without completion as a failure.

Status values

Completed response (Gemini family)

result is the native Gemini GenerateContentResponse; the only change is that each inlineData part becomes a fileData part pointing at the image URL:

Completed response (OpenAI family)

result has the same shape as the synchronous /v1/images/* response; images are in data[].url:
If you really need base64, add ?inline=true to the poll request and the archived image is read back into inlineData / b64_json (not recommended — slow for large images).

Failed response

retryable: true means you may submit a new task; nothing is retried automatically.

Idempotent submission

Network retries can submit the same task twice. Send an Idempotency-Key: <any string> header with the submit request; the same account + key returns the same task ID (the second call answers 200 instead of 202) with no duplicate generation or charge.

Sync vs. async at a glance