POST
/
v1
/
images
/
generations
Image generation - async submit (OpenAI Images compatible)
curl --request POST \
  --url https://coder.api.visioncoder.cn/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-image-2",
  "prompt": "一只戴着宇航员头盔的橘猫,赛博朋克风格",
  "n": 1,
  "size": "1:1",
  "resolution": "1k",
  "image_urls": [
    "<string>"
  ]
}
'
{
  "code": 200,
  "data": {
    "id": "task_01HZY3K8Q2W7X9V4",
    "status": "submitted"
  }
}
图片生成为异步任务:本接口提交后立即返回任务 ID(状态为 submitted),随后通过 任务结果查询 GET /v1/tasks/{task_id} 轮询获取生成结果。

调用示例

curl https://coder.api.visioncoder.cn/v1/images/generations \
  -H "Authorization: Bearer $VISIONCODER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "一只戴着宇航员头盔的橘猫,赛博朋克风格",
    "n": 1,
    "size": "1:1",
    "resolution": "1k"
  }'
图生图:通过 image_urls 传入参考图(URL 或 base64,最多 14 张)即切换为图生图模式:
{
  "model": "gpt-image-2",
  "prompt": "把这张照片变成水彩画风格",
  "image_urls": ["https://example.com/photo.png"]
}

响应示例

{
  "code": 200,
  "data": {
    "id": "task_01HZY3K8Q2W7X9V4",
    "status": "submitted"
  }
}
拿到 data.id 后,请轮询 GET /v1/tasks/{task_id} 获取生成结果,建议间隔 2-5 秒。

加群 & 客服

AI 技术交流群二维码
专属客服二维码

Authorizations

Authorization
string
header
required

Use the API key created at https://coder.visioncoder.cn/key as the Bearer token. Anthropic clients can pass the same key via the x-api-key header.

Body

application/json

OpenAI Images-compatible generation request. The task runs asynchronously: this endpoint returns a task ID, and the result is fetched via GET /v1/tasks/{task_id}.

model
string
required

Image model ID, e.g. gpt-image-2. Call GET /v1/models for the live list.

Example:

"gpt-image-2"

prompt
string
required

Text description of the image to generate. Chinese and English are both supported.

Example:

"一只戴着宇航员头盔的橘猫,赛博朋克风格"

n
integer
default:1

Number of images to generate (1-10).

Required range: 1 <= x <= 10
size
string

Aspect ratio such as 1:1, 16:9, auto; pixel sizes like 1024x1024 are also accepted.

Example:

"1:1"

resolution
enum<string>
default:1k

Output resolution tier.

Available options:
1k,
2k,
4k
image_urls
string[]

Reference images (URL or base64). Providing this switches to image-to-image mode; up to 14 images.

Maximum array length: 14

Response

200 - application/json

Task submitted. Poll GET /v1/tasks/{task_id} with the returned id to fetch the result.

code
integer
required

Status code; 200 means the task was submitted successfully.

Example:

200

data
ImagesTaskData · object
required