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
| Item | Value |
|---|---|
| Method | POST |
| Path | /v1/images/generations |
| Content-Type | application/json |
| Authentication | Authorization: Bearer YOUR_API_KEY |
| Platform requirement | General API keys require an OpenAI platform group with image generation enabled. Task API keys can use this synchronous image endpoint. |
API Key Behavior
| Key type | Behavior |
|---|---|
| General API key / OpenAI group | Uses the synchronous OpenAI Images gateway with the existing behavior. |
| Task API key | Uses 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
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | No | Image 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. |
prompt | string | Yes | Image generation prompt. |
size | string | No | Output size, such as 1024x1024. |
n | integer | No | Number of images. Defaults to 1 and must be greater than 0. |
response_format | string | No | Response format. General API keys commonly use b64_json; Task API keys support url and b64_json, defaulting to url. |
stream | boolean | No | Whether to stream the response when supported by the selected model. Task API keys do not support stream=true on this endpoint. |
quality | string | No | OpenAI Images API parameter. Availability depends on the selected model. |
background | string | No | OpenAI Images API parameter. Availability depends on the selected model. |
output_format | string | No | OpenAI Images API parameter. Availability depends on the selected model. |
output_compression | integer | No | OpenAI Images API parameter. Availability depends on the selected model. |
moderation | string | No | OpenAI Images API parameter. Availability depends on the selected model. |
style | string | No | OpenAI 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": "..."
}
]
}| Field | Description |
|---|---|
created | Unix timestamp when the response was created. |
data[].b64_json | Base64 image payload when response_format is b64_json. |
data[].url | Image 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
| Status | Cause |
|---|---|
400 | Request body is invalid, the model is not an image model, or required parameters are missing. |
401 | API key is missing or invalid. |
403 | Balance, quota, or group permission check failed. |
404 | Current API key group cannot call the OpenAI Images API. |
429 | Rate limit or concurrency limit was reached. |
500 / 502 / 503 | Gateway or upstream provider failed. |
504 | The 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.