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:- Submit: the request returns
202with a task ID in under a second. - Poll:
GET /v1/tasks/{id}until it completes;resultthen carries an https URL for each image (permanently archived onmedia.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
Option 1: Gemini path alias (recommended for Gemini clients)
Do not change a single byte of the body, headers or query string. Only swap the action suffix:generateContent for :asyncGenerateContent.
cURL
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).
Preference-Applied: respond-async and the same 202 body as Option 1.
Polling a task
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:
?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 anIdempotency-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.