OpenAI

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

图生图

317 / 32,000

预览
更多设置(4 项)
生成结果演示示例登录后试用

按 token 计费 · 默认设置约 $0.15 / 张 · 每次冻结 $0.151

GPT Image 2 图生图示例
示例 · 由以下输入生成

Turn this into a winter wedding invitation: change the date line to read "DECEMBER 12, 2027 · ZERMATT", replace the eucalyptus with snowy pine sprigs and small pinecones, and make the ribbon deep burgundy velvet. Keep "Emma & Lucas", the gold script, the card design, the marble and the camera angle exactly the same.

价格

文字输入 /M
$5.00
图片输入 /M
$8.00
图片输出 /M
$30.00
缓存读取 /M
$2.00

默认设置(质量 high、1 张)约 $0.15 / 张;质量、尺寸、张数越高,用量越多。

每次请求会先临时冻结 $0.151,按实际用量扣费,通常在一分钟内完成:多余部分退回,超出部分从余额扣除,余额可能因此变为负数;余额为负时新请求暂停,充值后先抵扣欠款。

生成失败不收费。

API 接入

用这个模型 ID 提交生成请求。

POST/v1/model-tasks
openai/gpt-image-2/image-to-image
请求体
{
  "model": "openai/gpt-image-2/image-to-image",
  "input": {
    "prompt": "Turn this into a winter wedding invitation: change the date line to read \"DECEMBER 12, 2027 · ZERMATT\", replace the eucalyptus with snowy pine sprigs and small pinecones, and make the ribbon deep burgundy velvet. Keep \"Emma & Lucas\", the gold script, the card design, the marble and the camera angle exactly the same.",
    "background": "auto",
    "image_size": "auto",
    "image_urls": [
      "https://pub-a7287c8d5de944d984e22a5bd3ab9bbe.r2.dev/uploads/capability-demo-4ffa20a3b8f2c3e00ceb12f6d50e9559.png"
    ],
    "num_images": 1,
    "output_format": "png",
    "quality": "high"
  }
}

输入 Schema

参数类型是否必填默认值
image_urlsarray必填—
promptstring必填—
backgroundstring可选auto
image_sizeobject | string可选auto
mask_urlstring可选—
num_imagesinteger可选1
output_formatstring可选png
qualitystring可选high

返回结果

接口会返回生成结果,或返回可轮询的异步任务;具体响应方式与结果字段见下方示例和 Schema。

异步任务
提交响应
HTTP 202
/v1/model-tasksapplication/json
{
  "id": "task_example",
  "model": "openai/gpt-image-2/image-to-image",
  "status": "queued"
}
状态响应
HTTP 200
/v1/model-tasks/{id}application/json
{
  "id": "task_example",
  "model": "openai/gpt-image-2/image-to-image",
  "status": "completed",
  "output": {
    "images": [
      {
        "url": "https://api.musespan.com/v1/model-tasks/task_example/artifacts/0"
      }
    ]
  }
}
文件下载
HTTP 200
/v1/model-tasks/{id}/artifacts/{index}生成的图片(如 image/png)

任务完成后,output 里的文件地址就指向此接口,序号从 0 开始。下载时要带上同一个 API Key(Authorization 请求头)。

错误响应
HTTP 400
/v1/model-tasksapplication/json
{
  "error": {
    "code": "invalid_input",
    "message": "The input does not match this model's input schema. Check the model's API documentation.",
    "type": "invalid_request_error"
  }
}

调用示例

异步任务提交后返回任务 ID,轮询至 status 为 completed 后,按返回结果获取生成内容。API Key 在控制台获取。

# Use a new directory for each new generation. Rerunning here continues this task.
set -eu
test -s model-task-id.txt || python3 -c "import uuid; print(uuid.uuid4())" > model-task-id.txt
REQUEST_ID=$(cat model-task-id.txt)
# Idempotent: resending the same bytes with the same ID never charges twice.
curl --fail-with-body --retry 3 --retry-connrefused --request POST 'https://api.musespan.com/v1/model-tasks' \
  --header "Authorization: Bearer $MUSESPAN_API_KEY" \
  --header "X-Request-Id: $REQUEST_ID" \
  --header "Content-Type: application/json" \
  --data '{"model":"openai/gpt-image-2/image-to-image","input":{"prompt":"Turn this into a winter wedding invitation: change the date line to read \"DECEMBER 12, 2027 · ZERMATT\", replace the eucalyptus with snowy pine sprigs and small pinecones, and make the ribbon deep burgundy velvet. Keep \"Emma & Lucas\", the gold script, the card design, the marble and the camera angle exactly the same.","background":"auto","image_size":"auto","image_urls":["https://pub-a7287c8d5de944d984e22a5bd3ab9bbe.r2.dev/uploads/capability-demo-4ffa20a3b8f2c3e00ceb12f6d50e9559.png"],"num_images":1,"output_format":"png","quality":"high"}}'
# Poll every 5 seconds for up to 25 minutes until status is completed or failed.
# Still queued (with queue_position) 5 minutes after submission: failed with queue_timeout, not charged.
# No result 15 minutes after acceptance (or no confirmation 15 minutes after submission): failed with generation_timeout, not charged.
# Any failure is final: generate again in a new directory (a new X-Request-Id).
# A 404 means the POST did not arrive: rerun this script to resend it with the same ID.
curl --fail-with-body 'https://api.musespan.com/v1/model-tasks/'"$REQUEST_ID"'' --header "Authorization: Bearer $MUSESPAN_API_KEY"