跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt

Use this file to discover all available pages before exploring further.

概述

创建给定图像的变体。需要 multipart/form-data 内容类型。

请求体

同步请求超时: 某些路由到的图片提供商会以内联方式返回最终图片,并等待生成完成。高分辨率或高质量请求可能接近一分钟甚至更久,因此请将 HTTP 客户端超时设置为至少 120s。如果创建响应包含 status: "pending"task_idpoll_url,请改为跟随返回的 poll_url 轮询。
image
file
必填
用作变体基础的图像。必须是有效的 PNG 文件,小于 50MB,且为正方形。
model
string
默认值:"dall-e-2"
用于图像变体的模型。目前仅支持 dall-e-2
n
integer
默认值:"1"
要生成的图像数量。必须在 1 到 10 之间。
size
string
生成图像的尺寸。必须是 256x256512x5121024x1024 之一。
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 "image=@cat.png" \
  -F "n=2" \
  -F "size=1024x1024"
{
  "created": 1706000000,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

注意事项

图像变体仅适用于 DALL-E 2。模型将生成与原始图像在风格和内容上相似的新图像。