Text to Image
GPT Image2 Economy Text to Image API
Description
The GPT Image2 Economy Text to Image API generates images from text prompts and can also perform image editing when combined with reference images. Use prompt to describe the subject, composition, materials, lighting, and style, and use parameters such as aspect_ratio, image_size, quality, and output_count to control the output specifications. This endpoint is ideal for quickly generating design assets, product images, concept art, and social media visuals.
Use Cases
- Generate product images, visual concepts, marketing images, or social media assets from text.
- Adjust backgrounds, styles, compositions, or local details based on reference images.
- Generate multiple candidate images in a single request for creative exploration and asset selection.
Endpoint Information
| Item | Description |
|---|---|
| Create task | POST /images/text2image |
| Query task | GET /images/text2image/{task_id} |
| Authentication | Bearer Token |
The full request URL consists of the base URL and the endpoint path; see API Basics.
Create Task
Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
prompt | string | Yes | - | Image generation or editing description, up to 10,000 characters |
reference_image_urls | string[] | No | - | List of reference image URLs, up to 8 images; when provided, the request is processed as image editing |
output_count | integer | No | 1 | Number of output images, range 1-4 |
aspect_ratio | string | No | 1:1 | Image aspect ratio. Allowed values: 1:1, 3:2, 2:3, 3:4, 4:3, 16:9, 9:16, 21:9, 9:21 |
image_size | string | No | 1K | Image size tier. Allowed values: 1K, 2K, 4K (case-insensitive) |
quality | string | No | low | Quality tier. Allowed values: low, medium, high |
output_mime_type | string | No | image/jpeg | Output format. Allowed values: image/png, image/jpeg, image/webp |
callback_url | string | No | - | Callback URL invoked when the task completes; must be an HTTP/HTTPS URL, up to 500 characters |
Constraints:
promptis required;reference_image_urlssupports up to 8 images;output_countsupports1-4;image_sizesupports1K,2K, and4K.
Request Example
bash
Copycurl -X POST '<BASE_URL>/images/text2image' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API_TOKEN>' \
-d '{
"prompt": "A clean, premium product shot of a ceramic mug, white background, soft studio lighting, sharp details",
"aspect_ratio": "16:9",
"image_size": "2K",
"quality": "high",
"output_count": 1,
"output_mime_type": "image/png"
}'
Reference-Image Editing Example
bash
Copycurl -X POST '<BASE_URL>/images/text2image' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API_TOKEN>' \
-d '{
"prompt": "Replace the background with a bright modern photo studio, keeping the main product unchanged",
"reference_image_urls": [
"https://example.com/source-product.png"
],
"image_size": "2K",
"quality": "medium",
"output_count": 1,
"output_mime_type": "image/png"
}'
Success Response
json
Copy{
"code": 200,
"data": {
"task_id": "550e8400-e29b-41d4-a716-446655440000",
"created_at": 1778313600,
"status": "TASK_PENDING"
},
"timestamp": 1778313600
}
| Field | Type | Description |
|---|---|---|
task_id | string | Task ID, used to query the result |
created_at | number | Task creation time, Unix timestamp in seconds |
status | string | Task status; see Task Status |
Query Task
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
task_id | string | Yes | Task ID returned by the create-task endpoint |
Request Example
bash
Copycurl -X GET '<BASE_URL>/images/text2image/550e8400-e29b-41d4-a716-446655440000' \
-H 'Authorization: Bearer <API_TOKEN>'
Success Response
json
Copy{
"code": 200,
"data": {
"task_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "TASK_SUCCEEDED",
"image_urls": [
"https://example.com/generated_1.png"
],
"mime_types": [
"image/png"
],
"generated_count": 1,
"partial": false
},
"timestamp": 1778313700
}
| Field | Type | Description |
|---|---|---|
task_id | string | Task ID |
status | string | Task status; see Task Status |
image_urls | string[] | Returned on success; list of image URLs |
mime_types | string[] | Returned on success; list of image MIME types |
generated_count | integer | Returned on success; number of images actually generated |
partial | boolean | Returned on success; indicates whether generation was only partially successful |
Notes
- We recommend using Batch Upload first to obtain stable, accessible URLs for reference images.
- When
reference_image_urlsis omitted, images are generated from text; when provided, the request is processed as reference-image editing. - We recommend that
promptexplicitly describe the subject, composition, background, materials, lighting, and style — avoid single-keyword prompts. - If you need a task completion notification, pass a
callback_url; otherwise, retrieve the task status via the query endpoint.
Related Documents
On this page