跳转到主要内容

概述

该端点保留给旧版 OpenAI 兼容的变体客户端。它不是当前 image-to-image 工作流的推荐路径;能用新流程时,请使用 /v1/images/edits + gpt-image-2,或在 /v1/images/generations 中使用 nano-banana-pro 等 image-to-image 模型。请求必须使用 multipart/form-data

请求体

同步请求超时: 某些路由到的图片提供商会以内联方式返回最终图片,并等待生成完成。高分辨率或高质量请求可能接近一分钟甚至更久,因此请将 HTTP 客户端超时设置为至少 120s。如果创建响应包含 status: "pending"task_idpoll_url,请改为跟随返回的 poll_url 轮询。
image
file
必填
用作变体基础的图像。必须是有效的 PNG 文件,小于 50MB,且为正方形。
model
string
必填
旧版变体兼容路由的必填模型 ID。没有隐式默认模型;当前 image-to-image 工作流请优先使用 /v1/images/edits/v1/images/generations 搭配当前模型。
n
integer
默认值:"1"
要生成的图像数量。必须在 1 到 10 之间。
size
string
旧版变体兼容路由生成图片的尺寸。支持的取值取决于所选模型。
response_format
string
默认值:"url"
返回生成图像的格式。必须是 urlb64_json
user
string
代表终端用户的唯一标识符,用于滥用监控。

响应

created
integer
图像创建时间的 Unix 时间戳。
data
array
生成的图像变体数组。每个对象包含:
  • url (string): 变体图像的 URL(如果 response_format 是 url
  • b64_json (string): Base64 编码的图像(如果 response_format 是 b64_json
curl -X POST "https://api.tokenlab.sh/v1/images/variations" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=your-legacy-variation-model" \
  -F "image=@cat.png" \
  -F "n=2" \
  -F "size=1024x1024"
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.tokenlab.sh/v1"
)

response = client.images.create_variation(
    model="your-legacy-variation-model",
    image=open("cat.png", "rb"),
    n=2,
    size="1024x1024"
)

for image in response.data:
    print(image.url)
import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://api.tokenlab.sh/v1'
});

const response = await client.images.createVariation({
  model: 'your-legacy-variation-model',
  image: fs.createReadStream('cat.png'),
  n: 2,
  size: '1024x1024'
});

response.data.forEach(image => console.log(image.url));
{
  "created": 1706000000,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

注意事项

这是旧版兼容端点,不在当前推荐图片模型目录中。新接入请使用 /v1/images/edits + gpt-image-2,或在 /v1/images/generations 中设置 operation: "image-to-image" 并选择当前 image-to-image 模型。