GuideImage GenerationOpenai
Image Generation
OpenAI image generation API reference: create images from prompts with dall-e-3 or gpt-image models, covering size, background, quality and response format.
Create images from a prompt using the native OpenAI format.
📌 Basics
- Endpoint:
POST /v1/images/generations/ - Request domain:
https://anyrouter.win - Authentication:
Bearer Token - Content type:
application/json
📥 Request Parameters (Request Body)
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| model | string | No | dall-e-2 | Model to use: dall-e-2, dall-e-3, or gpt-image-1, gpt-image-1.5, gpt-image-2. |
| prompt | string | Yes | - | Text description of the image. Up to 32k characters for GPT-image-1. |
| n | integer | No | 1 | Number of images (1-10). dall-e-3 only supports 1. |
| size | string | No | 1024x1024 | Size. gpt-image-1 supports 1024x1024, 1536x1024, 1024x1536, or auto. |
| background | string | No | auto | Background transparency (gpt-image-1 only): transparent, opaque, auto. |
| moderation | string | No | auto | Content moderation level: low (less restrictive) or auto. |
| quality | string | No | - | Quality of the generated image (HD/Standard). |
| style | string | No | - | Image style. |
📤 Response
Status code: 200 OK
| Field | Type | Description |
|---|---|---|
| created | integer | Unix timestamp when the request was created. |
| data | array | List of image objects. |
| └─ url | string | Hosted URL of the image. |
| └─ b64_json | string | Base64-encoded image data. |
| usage | object | Usage statistics. |
| └─ total_tokens | integer | Total tokens consumed by this request. |
📝 Request Example
{
"model": "gpt-image-1",
"prompt": "A cute baby sea otter",
"n": 1,
"size": "1024x1024",
"background": "transparent"
}📝 Response Example
{
"created": 1713833628,
"data": [
{
"url": "https://example.com/generated_image.png",
"b64_json": ""
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}💡 Notes
- Transparency support: When
backgroundis set totransparent, make sure the backend returns a format that supports an alpha channel, such aspngorwebp. - Model differences: Different models (DALL-E vs GPT-image) have different limits on
sizeandn; choose a model based on your actual business needs.
Edit Images
OpenAI image edit endpoint guide: inpaint or extend an image with a prompt and mask, covering form-data parameters, PNG alpha requirements and a cURL example.
Image Editing
Guide to Qwen-Image-Edit models: edit single images, fuse multiple images or control structure from reference images and prompts, with parameters and examples.