stream: true, the Text-to-Image and Image Edit endpoints push results image by image via SSE, followed by a summary event.
- Only
response_format: "url"is supported - Events arrive in completion order; use
image_indexto identify each image - Errors before the response headers are returned (invalid parameters, authentication, rate limiting, insufficient balance, etc.) return a regular HTTP error, the same as non-streaming calls; later errors are returned as an
errorevent whoseerror.http_codematches the HTTP status code of the non-streaming call - While waiting, an SSE comment line
: keepaliveis sent every 15 seconds and can be ignored; the response headers are returned with the first keepalive (about 15 seconds) at the latest - The stream ends with either
completedorerror, both carryingusageandrequest_id
Event Types
Both endpoints use the same event structure; only thetype prefix differs:
Each event consists of an
event: line and a data: line, where data is JSON. Events are separated by a blank line:
partial_succeeded
A single image was generated successfully. Pushed once for each successful image.string
required
Event type:
image_generation.partial_succeeded or image_edit.partial_succeeded.integer
Unix timestamp (seconds) when the event was produced.
string
Model name.
integer
required
Image index, starting from 0, range [0, n-1].
string
required
Image URL. Download the image and store it yourself.
string
Actual image size, formatted as
WIDTHxHEIGHT.string
Image format:
png, jpeg, or webp.string
The prompt actually used to generate this image. When prompt enhancement is on, this is the enhanced prompt; when off, it equals the
prompt in the request.Example
partial_failed
A single image failed or was withheld by the content safety check. Other images are not affected and continue to be pushed.string
required
Event type:
image_generation.partial_failed or image_edit.partial_failed.integer
Unix timestamp (seconds) when the event was produced.
string
Model name.
integer
required
Image index, starting from 0.
string
required
Internal error code, e.g.
1026. See Error Codes.string
required
Error detail.
Example
completed
Pushed after all images are done when at least one image succeeded; it is then the last event in the stream. Carries usage and statistics for the request.string
required
Event type:
image_generation.completed or image_edit.completed.integer
Unix timestamp (seconds) when the event was produced.
string
Model name.
object
Token usage of this request, used for billing.
string
Request trace ID for troubleshooting.
Example
error
The top-level error of the request; the stream ends after it. Pushed only when no image succeeded; the request is not billed and everyusage field is 0:
- All images failed after generation was submitted: pushed after the
partial_failedevents for allnimages.error.http_codeis422if every image was withheld by the content safety check,402if every image failed due to insufficient balance, otherwise500 - The whole request failed before generation was submitted (e.g. the input failed the content safety check or a reference image could not be processed) after the response headers were returned: the
errorfield is the same aserrorin the HTTP error response of a non-streaming request
error event does not include created or data; the failure reason of each image is in the partial_failed events pushed before it.
string
required
Always
error.object
required
Error information.
object
Token usage of this request; same structure as
usage in the completed event, with every field 0.string
Request trace ID for troubleshooting.
Example
Full Example
Withn: 3 and stream: true, where the third image is withheld by the content safety check: