Skip to content

Images Generations

POST https://wrouter.ai/v1/images/generations

支援兩種請求形態,按 model 自動路由:

  • OpenAI 形態 — 適用於 dall-e-3gpt-image-1flux-pro
  • 百鍊 / Qwen 形態 — 適用於 qwen-image、阿里通義系列;這是 newapi 閘道器原生文件化的格式

形態 A:OpenAI 形態

業界通用的 Images 協議格式。

引數型別必填說明
modelstringdall-e-3gpt-image-1flux-pro
promptstring文本描述
ninteger生成數量,預設 1
sizestring1024x10241792x10241024x1792
qualitystring"standard" | "hd"
stylestring"vivid" | "natural"(DALL·E 3)
response_formatstring"url"(預設)或 "b64_json"
userstring業務方使用者標識
bash
curl https://wrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $WROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dall-e-3",
    "prompt": "未來感的伺服器機房,藍紫色光線",
    "size": "1024x1024",
    "quality": "hd"
  }'
python
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://wrouter.ai/v1")
img = client.images.generate(
    model="gpt-image-1",
    prompt="A cyberpunk shiba inu wearing sunglasses",
    size="1024x1024",
)
print(img.data[0].url)

形態 B:百鍊 / Qwen 形態

阿里通義的 qwen-image 系列使用 input / parameters 信封:

引數型別必填說明
modelstringqwen-imageqwen-image-plus
inputobject包含 prompt 等核心輸入
parametersobject包含 sizennegative_prompt 等引數
bash
curl https://wrouter.ai/v1/images/generations \
  -H "Authorization: Bearer $WROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen-image",
    "input": {"prompt": "一隻戴墨鏡的柴犬,賽博朋克風"},
    "parameters": {"size": "1024*1024", "n": 1}
  }'

響應

json
{
  "created": 1718000000,
  "data": [
    {"url": "https://cdn.wrouter.ai/.../image.png", "revised_prompt": "..."}
  ]
}

注意事項

  • 生成的圖片 URL 有效期 24 小時,長期使用請客戶端下載到自己儲存
  • 部分模型不支援 n>1,請改為多次呼叫
  • 違反上游內容安全策略的 prompt 會返回 400 + content_policy_violation
  • Qwen-image 系列的 size 使用星號格式(1024*1024),OpenAI 系列使用 x 格式(1024x1024),互不通用