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

ItemDescription
Create taskPOST /images/text2image
Query taskGET /images/text2image/{task_id}
AuthenticationBearer Token

The full request URL consists of the base URL and the endpoint path; see API Basics.

Create Task

Request Parameters

ParameterTypeRequiredDefaultDescription
promptstringYes-Image generation or editing description, up to 10,000 characters
reference_image_urlsstring[]No-List of reference image URLs, up to 8 images; when provided, the request is processed as image editing
output_countintegerNo1Number of output images, range 1-4
aspect_ratiostringNo1:1Image aspect ratio. Allowed values: 1:1, 3:2, 2:3, 3:4, 4:3, 16:9, 9:16, 21:9, 9:21
image_sizestringNo1KImage size tier. Allowed values: 1K, 2K, 4K (case-insensitive)
qualitystringNolowQuality tier. Allowed values: low, medium, high
output_mime_typestringNoimage/jpegOutput format. Allowed values: image/png, image/jpeg, image/webp
callback_urlstringNo-Callback URL invoked when the task completes; must be an HTTP/HTTPS URL, up to 500 characters

Constraints: prompt is required; reference_image_urls supports up to 8 images; output_count supports 1-4; image_size supports 1K, 2K, and 4K.

Request Example

bash
Copy
curl -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
Copy
curl -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
}
FieldTypeDescription
task_idstringTask ID, used to query the result
created_atnumberTask creation time, Unix timestamp in seconds
statusstringTask status; see Task Status

Query Task

Path Parameters

ParameterTypeRequiredDescription
task_idstringYesTask ID returned by the create-task endpoint

Request Example

bash
Copy
curl -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
}
FieldTypeDescription
task_idstringTask ID
statusstringTask status; see Task Status
image_urlsstring[]Returned on success; list of image URLs
mime_typesstring[]Returned on success; list of image MIME types
generated_countintegerReturned on success; number of images actually generated
partialbooleanReturned 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_urls is omitted, images are generated from text; when provided, the request is processed as reference-image editing.
  • We recommend that prompt explicitly 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.
Previous
Montage to Video
Next
Text to Subject
On this page
Text to Image | bach.art | bach.art