Content updated: 2026-09-18
Asynchronous Image Generation
Generating an image with a model typically takes 20 to 120 seconds. The synchronous interface requires the client to keep the HTTP connection open while waiting for results, which is prone to gateway/proxy read timeouts, and the returned base64 can also be very large. The asynchronous mode splits this step into two calls:- Submission: The request immediately returns
202and a task ID (in less than 1 second). - Polling: Use the task ID to look up
GET /v1/tasks/{id}; when done,resultcontains the image’s https URL (permanently archived atmedia.crazyrouter.com), and no base64 is returned.
The model name, request body, and billing are all exactly the same as synchronous requests. Asynchronous mode just changes “when you receive the result”—the same API Key can submit some requests synchronously and others asynchronously. Failed tasks are not billed.
Supported Models
Method 1: Gemini Path Alias (Recommended for Gemini Clients)
No need to change a single byte in the request body, headers, or query parameters—just change the action suffix from:generateContent to :asyncGenerateContent.
cURL
202:
The returned
model is the parsed underlying model name (such as gemini-3.1-flash-image-preview), consistent with the billing log; this does not affect submitting using nano-banana-2. For reference image editing, the syntax is the same as for synchronous: put inlineData (base64) or fileData (URL) in parts.:asyncGenerateContent only accepts image output models; invoking with a text model will return 400 async mode is only available for image models. Streaming action :streamGenerateContent is not supported asynchronously.
Method 2: OpenAI Image Endpoint with Prefer Header
Add an HTTP header Prefer: respond-async to the existing /v1/images/generations or /v1/images/edits request, with everything else unchanged. You can also use the request body field "async": true (JSON) or form field async=true (multipart), with the same effect.
Preference-Applied: respond-async header, and the body is the same as in Method 1 (202 + task ID).
Querying Tasks
404. It is recommended to poll once every 2–3 seconds, and if it is not complete after 10 minutes, consider the task failed.
Status
Response When Complete (Gemini Series)
result is the native Gemini GenerateContentResponse, only replacing inlineData with fileData, which points to the image URL:
Response When Complete (OpenAI Series)
result has the same response structure as synchronous /v1/images/*, and the image is in data[].url:
?inline=true when querying, and the server will read back the archived image and re-convert it to inlineData / b64_json (not recommended—slow for large images).
Response When Failed
retryable: true means you can submit a new task; the system will not retry automatically.
Idempotent Submission
Network retries may cause the same task to be submitted multiple times. With theIdempotency-Key: <any string> header on your submission request, the same account and same Key will return the same task ID (the second time you get 200 instead of 202), so the image won’t be generated or billed multiple times.