AI GPT ImageAI GPT Image

GPT Image 2 Text to Image

Get API Keygpt-image-2-text-to-image

GPT Image 2 Text to Image API Documentation

Generate image content using the gpt-image-2-text-to-image model

Overview

This document describes how to use the gpt-image-2-text-to-image model for image generation.

The integration flow consists of two steps:

  1. Create a generation task
  2. Query task status and results

Authentication

All API requests require a Bearer Token in the request header:

Authorization: Bearer YOUR_API_KEY

Get API Key:

  1. Open the API Keys page
  2. Click Create API Key
  3. Add the key to the request header: Authorization: Bearer YOUR_API_KEY

1. Create Generation Task

API Information

  • URL: POST https://aigptimage.com/api/v1/jobs/createTask
  • Content-Type: application/json

Request Parameters

ParameterTypeRequiredDescription
modelstringYesPublic model ID. Must be exactly gpt-image-2-text-to-image
inputobjectYesInput parameters object

Model Parameter

The model parameter specifies which public image model to use.

PropertyValueDescription
Formatgpt-image-2-text-to-imageExact public model identifier
TypestringMust be passed as a string
RequiredYesMandatory for all create task requests

Note: The model value must match exactly and use the public model ID shown on this page.

input Object Parameters

prompt

  • Type: string
  • Required: Yes
  • Description: Text prompt used to describe the image to generate
  • Max Length: 20000 characters

aspect_ratio

  • Type: string
  • Required: No
  • Description: Output image aspect ratio
  • Common Options: auto, 1:1, 4:5, 3:4, 2:3, 16:9, 9:16, 21:9
  • Default Value: model default

resolution

  • Type: string
  • Required: No
  • Description: Output resolution used for generation and billing
  • Options: 1K, 2K, 4K
  • Default Value: 1K

quality

  • Type: string
  • Required: No
  • Description: Optional quality parameter passed through to the image backend

output_format

  • Type: string
  • Required: No
  • Description: Optional output image format passed through to the image backend

Request Example

{
  "model": "gpt-image-2-text-to-image",
  "input": {
    "prompt": "A cinematic product photo of a transparent speaker on a reflective black table",
    "aspect_ratio": "1:1",
    "resolution": "1K"
  }
}

Response Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_xxxxxxxxxxxxx"
  }
}

Response Parameters

ParameterTypeDescription
codeintegerResponse status code. 200 means success
msgstringResponse message
data.taskIdstringTask ID used to query task status

Real Example

Create task:

curl -X POST "https://aigptimage.com/api/v1/jobs/createTask" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -H "X-Request-ID: xxxxxxxxxxxx" \
  -d '{
    "model": "gpt-image-2-text-to-image",
    "input": {
      "prompt": "Generate an analysis and usage instruction diagram for the equipment name narrow-grip pulldown machine. Requirements: 3:4 aspect ratio, 4k resolution."
    }
  }'

Create task response:

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "3ebe82c2-3abc-4015-9608-901baca54948"
  }
}

2. Query Task Status

API Information

  • URL: GET https://aigptimage.com/api/v1/jobs/recordInfo
  • Parameter: taskId (URL query parameter)

Request Example

GET https://aigptimage.com/api/v1/jobs/recordInfo?taskId=task_xxxxxxxxxxxxx

Response Example

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_xxxxxxxxxxxxx",
    "model": "gpt-image-2-text-to-image",
    "state": "waiting",
    "param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"A cinematic product photo of a transparent speaker on a reflective black table\",\"aspect_ratio\":\"1:1\",\"resolution\":\"1K\"}}",
    "resultJson": null,
    "failCode": null,
    "failMsg": null,
    "costTime": null,
    "completeTime": null,
    "createTime": 1757584164490
  }
}

Response Parameters

ParameterTypeDescription
codeintegerResponse status code. 200 means success
msgstringResponse message
data.taskIdstringTask ID
data.modelstringPublic model ID
data.statestringTask status: waiting, success, fail
data.paramstringOriginal create task request parameters as JSON string
data.resultJsonstring | nullResult JSON string. For image tasks it contains resultUrls when successful
data.failCodestring | nullFailure code when the task fails
data.failMsgstring | nullFailure message when the task fails
data.costTimeinteger | nullTask duration in milliseconds after completion
data.completeTimeinteger | nullCompletion timestamp in milliseconds
data.createTimeintegerCreation timestamp in milliseconds

Success Result Structure

For image generation tasks, resultJson usually has this structure:

{
  "resultUrls": ["https://your-cdn.example.com/result-1.png"]
}

Real Query Example

Query task:

curl "https://aigptimage.com/api/v1/jobs/recordInfo?taskId=3ebe82c2-3abc-4015-9608-901baca54948" \
  -H "Authorization: Bearer sk-xxxxxxxxxx"

Query task response:

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "3ebe82c2-3abc-4015-9608-901baca54948",
    "model": "gpt-image-2-text-to-image",
    "state": "success",
    "param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"Generate an analysis and usage instruction diagram for the equipment name narrow-grip pulldown machine. Requirements: 3:4 aspect ratio, 4k resolution.\"}}",
    "resultJson": "{\"resultUrls\":[\"https://cdn.aigptimage.com/generation/image/3ebe82c2-3abc-4015-9608-901baca54948/1.png\"]}",
    "failCode": null,
    "failMsg": null,
    "costTime": 59699,
    "completeTime": 1777467267840,
    "createTime": 1777467208141
  }
}

Usage Flow

  1. Call POST /api/v1/jobs/createTask
  2. Extract taskId from the response
  3. Poll GET /api/v1/jobs/recordInfo?taskId=...
  4. Wait until state becomes success or fail
  5. Read output image URLs from resultJson when the task succeeds

Notes

  • API calls use the same credit balance and billing rules as the web app
  • Rate limits depend on the API key tier
  • resolution affects both output size and credit consumption

Error Codes

Status CodeDescription
200Request successful
400Invalid request parameters
401Authentication failed or API key is invalid
402Insufficient credits
404Task or resource not found
409Active task limit exceeded or request conflict
422Parameter validation failed
429Request rate limit exceeded
500Internal server error