Skip to content

OpenAI Generations

/v1/images/generations is the OpenAI Images API compatible synchronous image generation endpoint. The HTTP request completes after the image result is ready.

Interface

ItemValue
MethodPOST
Path/v1/images/generations
Content-Typeapplication/json
AuthenticationAuthorization: Bearer YOUR_API_KEY
Platform requirementGeneral API keys require an OpenAI platform group with image generation enabled. Task API keys can use this synchronous image endpoint.

API Key Behavior

Key typeBehavior
General API key / OpenAI groupUses the synchronous OpenAI Images gateway with the existing behavior.
Task API keyUses Task API models and pricing, waits synchronously for up to 120 seconds, then returns an OpenAI Images style response.

Task API keys support POST /v1/images/generations and POST /v1/images/edits, including /images/generations and /images/edits aliases without the /v1 prefix. They do not support /v1/responses or conversational endpoints. If the synchronous wait times out and the response includes task_id, use the Task API to query the final status.

Request Parameters

ParameterTypeRequiredDescription
modelstringNoImage model. Defaults to gpt-image-2. General API keys must use an OpenAI Images compatible model; Task API keys may use any available Task API image model.
promptstringYesImage generation prompt.
sizestringNoOutput size, such as 1024x1024.
nintegerNoNumber of images. Defaults to 1 and must be greater than 0.
response_formatstringNoResponse format. General API keys commonly use b64_json; Task API keys support url and b64_json, defaulting to url.
streambooleanNoWhether to stream the response when supported by the selected model. Task API keys do not support stream=true on this endpoint.
qualitystringNoOpenAI Images API parameter. Availability depends on the selected model.
backgroundstringNoOpenAI Images API parameter. Availability depends on the selected model.
output_formatstringNoOpenAI Images API parameter. Availability depends on the selected model.
output_compressionintegerNoOpenAI Images API parameter. Availability depends on the selected model.
moderationstringNoOpenAI Images API parameter. Availability depends on the selected model.
stylestringNoOpenAI Images API parameter. Availability depends on the selected model.

Request Example

bash
curl https://api.llmapi.site/v1/images/generations \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-image-2",
    "prompt": "a product photo of a ceramic coffee cup on a white table",
    "size": "1024x1024",
    "n": 1,
    "response_format": "b64_json"
  }'

Response — 200 OK

json
{
  "created": 1779912000,
  "data": [
    {
      "b64_json": "..."
    }
  ]
}
FieldDescription
createdUnix timestamp when the response was created.
data[].b64_jsonBase64 image payload when response_format is b64_json.
data[].urlImage URL when URL responses are available.

With a Task API key, url returns an authenticated image asset URL when URL responses are available. Use response_format: "b64_json" when the client needs inline image bytes.

Errors

StatusCause
400Request body is invalid, the model is not an image model, or required parameters are missing.
401API key is missing or invalid.
403Balance, quota, or group permission check failed.
404Current API key group cannot call the OpenAI Images API.
429Rate limit or concurrency limit was reached.
500 / 502 / 503Gateway or upstream provider failed.
504The Task API key synchronous wait timed out. The response includes task_id when the final status can be queried later.

Task API key timeout example:

json
{
  "error": {
    "type": "TASK_SYNC_TIMEOUT",
    "message": "task did not complete before synchronous wait timeout",
    "task_id": "task_..."
  }
}

Boundaries

  • This endpoint is only for OpenAI Images API compatible requests.
  • Use Task API for long-running or production long-running jobs.
  • A Task API key can use the OpenAI Images compatible generation and edit endpoints, but it cannot call text or conversation endpoints.