Skip to navigation

Generate images

Creates images from a prompt. Every image is returned inline as base64 in data[].b64_json, never as a link. size, quality and n go to the model as sent; a value it doesn’t offer is rejected with 400 and isn’t charged.

Authentication

AuthorizationBearer

Your API key, sk-..., from Console → API keys.

Request

This endpoint expects an object.
modelstringRequired
promptstringRequired
nintegerOptional>=1
How many images. Each model has its own maximum.
sizestringOptional

Such as 1024x1024, on models that offer it.

qualitystringOptional

Such as low, medium or high, on models that offer it.

stylestringOptional
backgroundenumOptional
Allowed values:
output_formatenumOptional
Allowed values:
userstringOptional
metadatamap from strings to stringsOptional

Response

The images, inline as base64 in data[].b64_json.

createdintegerOptional
datalist of objectsOptional
usageobjectOptional
Token usage, for models billed by tokens.

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
422
Unprocessable Entity Error
429
Too Many Requests Error
502
Bad Gateway Error
503
Service Unavailable Error