Use POST /v2/images/generations to create images synchronously. The API waits for completion and returns the finished files in the same response.
What to send
At minimum, send a model and prompt.
Key parameters
Using reference images
Pass up to 20 reference images in the images array. Each item needs a url.
Use reference images when you need tighter control over style, composition, or subject.
How many reference images a model accepts is in its supported_references field. See Models.
Reference image sources
url accepts either form:
- a publicly accessible HTTPS URL
- a base64 data URL, such as
data:image/png;base64,...
Use a data URL when the image only exists on your side and you don’t want to host it first.
Inline images must be PNG, JPEG, or WebP. Bare base64 without the data: prefix is rejected.
A decoded reference image can be up to 10 MiB, and the whole JSON request must fit within 25 MiB. Base64 adds roughly 33% to the original file size, so budget for that before you inline several images. Pass an HTTPS URL instead when you’re close to the limit.
Response handling
A completed image generation returns:
id for the generation
status: "completed"
data, which contains one or more generated files
usage, which contains billing details for the generation
Each item in data includes a signed download URL and a deletes_at timestamp. Generated media is retained for 24 hours, so download the file within that window if you need to keep it in your own system.
See Media responses for the full response shape.
Common failure cases
- Invalid model, aspect ratio, or resolution returns
400.
- Missing or invalid API keys return
401.
- Insufficient balance returns
402.
- Safety failures for prompts or reference images return
422.
- Rate or concurrency limits return
429.
See Errors for error handling details.
Full example
Related pages