TokenLab

圖像

建立圖像變體

建立給定圖像的變體

POST
/v1/images/variations

概述

此端點保留給舊版 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_id 或 poll_url,請改為依照返回的 poll_url 輪詢。

imagefile必填

Multipart 來源圖片。檔案與完整請求主體均不得超過 50 MiB。支援的格式與尺寸取決於所選模型,其目前詳情必須明確列出 /v1/images/variations。

modelstring必填

舊版變體相容路由的必填模型 ID。沒有隱含預設模型;目前 image-to-image 工作流請優先使用 /v1/images/edits 或 /v1/images/generations 搭配目前模型。

ninteger預設值: 1

要產生的圖片數量(1-10,依模型而定)。

sizestring

舊版變體相容路由生成圖片的尺寸。支援的取值取決於所選模型。

response_formatstring

回傳生成圖像的格式。必須是 url 或 b64_json。

userstring

代表終端使用者的唯一識別碼,用於濫用監控。

回應

createdinteger

圖像建立時間的 Unix 時間戳。

dataarray

生成的圖像變體陣列。

每個物件包含:

  • 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"

回應

回應
{
  "created": 1706000000,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

注意事項

這是舊版相容端點,不在目前推薦圖片模型目錄中。新接入請使用 /v1/images/edits + gpt-image-2,或在 /v1/images/generations 中設定 operation: "image-to-image" 並選擇目前 image-to-image 模型。

授權

BearerAuth
AuthorizationBearer <token>

API Key 驗證。請在 Dashboard > API > API Keys 建立或管理 API 金鑰。

位置: header

請求標頭

X-TokenLab-Delivery-Policy?string

單次請求傳遞策略。會覆寫 API key 與 Workspace 的預設值。系統會自動優先嘗試 TokenLab Verified,並可能在輸出、請求接受或建立持久性資源前切換至 Official 模式一次。

可選值

  • "auto"
  • "verified"
  • "official"

請求主體

multipart/form-data

回應

application/json

application/json

application/json

application/json

application/json

application/json