Skip to content

图片生成 ​

端点: POST https://oneapi.zaiwenai.com/v1/images/generations

端点: POST https://oneapi.zaiwenai.com/v1/images/edits

与 OpenAI Images 接口兼容,支持文生图和图片编辑。

图片生成 ​

请求参数 ​

参数类型必填说明
modelstring是模型名称
promptstring是图片描述提示词
ninteger否生成数量,目前固定为 1
response_formatstring否返回格式,目前固定为 b64_json

Curl 示例 ​

bash
curl https://oneapi.zaiwenai.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A cute cat wearing a hat"
  }'

OpenAI Python SDK 示例 ​

python
from openai import OpenAI

client = OpenAI(
    base_url="https://oneapi.zaiwenai.com/v1",
    api_key="$YOUR_API_KEY",
)

response = client.images.generate(
    model="gpt-image-2",
    prompt="A cute cat wearing a hat",
    n=1,
    response_format="b64_json",
)

print(response.data[0].b64_json[:50] + "...")

响应格式 ​

json
{
  "created": 1716841200,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "total_tokens": 10
  }
}

图片编辑 ​

请求参数 ​

参数类型必填说明
imagefile是要编辑的图片文件
modelstring是模型名称
promptstring是编辑指令
ninteger否生成数量,目前固定为 1
response_formatstring否返回格式,目前固定为 b64_json

Curl 示例 ​

bash
curl https://oneapi.zaiwenai.com/v1/images/edits \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -F "image=@original.png" \
  -F "model=gpt-image-2" \
  -F "prompt=Add a rainbow in the sky"

OpenAI Python SDK 示例 ​

python
response = client.images.edit(
    model="gpt-image-2",
    image=open("original.png", "rb"),
    prompt="Add a rainbow in the sky",
    n=1,
    response_format="b64_json",
)

print(response.data[0].b64_json[:50] + "...")

计费说明 ​

图片生成和编辑按次数计费,每次调用消耗固定费用(由模型配置决定)。