GPT Image 2 Text-to-Image


OpenAI 的 GPT Image 2 原生图像模型可根据自然语言提示词生成高质量图像。它提供开箱即用的 REST 推理 API,性能出色、无冷启动且价格实惠。

openai/gpt-image-2/text-to-image

OpenAI 的 GPT Image 2 文生图模型可根据自然语言提示词生成高质量图像。提供开箱即用的 REST 推理 API,性能出色、无冷启动且价格实惠。

1. 身份验证

API 使用 API Key 进行身份验证。

获取 API Key

请前往 https://icreat.ai/hub/keys 获取 API Key。

2. 调用 API

提交请求

使用 cURL 发送 HTTP 请求以创建任务:

curl --fail-with-body --connect-timeout 10 --max-time 60 \
  -X POST https://api.icreat.ai/v1/task/submit/openai/gpt-image-2/text-to-image \
  -H "Authorization: Bearer ${ICREAT_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
  "prompt": "将背景更换为夜晚霓虹灯闪烁的城市街道。",
  "image": ["https://cdn.example.com/source/dog.png"],
  "size": "1024x1024",
  "quality": "high"
}'

服务器将返回类似以下内容的响应:

{ "task_id": "task-xxx" }

使用 task_id 轮询任务状态并获取结果。

3. 查询任务状态

curl --connect-timeout 10 --max-time 60 \
  -X POST "https://api.icreat.ai/v1/task/query-status" \
  -H "Authorization: Bearer ${ICREAT_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
  "task_id": "task-xxx"
}'

服务器将返回任务状态。当状态为 SUCCEEDED 时,即可获取结果。

4. 获取结果

curl --connect-timeout 10 --max-time 60 \
  -X POST "https://api.icreat.ai/v1/task/get-result" \
  -H "Authorization: Bearer ${ICREAT_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
  "task_id": "task-xxx"
}'

服务器将返回该任务的输出结果。

5. 参数说明

API 接受以下输入参数:

5.1 prompt

  • 类型: string
  • 是否必填:
  • 说明: 文本提示词,最大长度为 32,000 个字符。

5.2 image

  • 类型: string[]
  • 是否必填:
  • 说明: 参考图片 URL 列表。列表不为空时表示进行图生图生成,支持 1–10 张图片。

5.3 size

  • 类型: string
  • 是否必填:
  • 说明: 生成图像的尺寸。
  • 可选值:

1024x10242048x20482880x28801280x7202560x14403840x2160720x12801440x25602160x38401152x8642304x17283264x2448864x11521728x23042448x32641248x8322496x16643504x2336834x12481664x24962336x35041120x8962240x17923200x2560896x11201792x22402560x32001456x6243024x12963696x1584

5.4 quality

  • 类型: string
  • 是否必填:
  • 说明: 控制生成结果对原始输入图像的还原度。
  • 可选值: highmediumlow

6. 输入示例

6.1 文生图

{
  "prompt": "一只戴着太阳镜的柴犬,赛博朋克风格。",
  "size": "1024x1024",
  "quality": "high"
}