Images Generations
POST https://wrouter.ai/v1/images/generations支援兩種請求形態,按 model 自動路由:
- OpenAI 形態 — 適用於
dall-e-3、gpt-image-1、flux-pro等 - 百鍊 / Qwen 形態 — 適用於
qwen-image、阿里通義系列;這是 newapi 閘道器原生文件化的格式
形態 A:OpenAI 形態
業界通用的 Images 協議格式。
| 引數 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | ✓ | 如 dall-e-3、gpt-image-1、flux-pro |
prompt | string | ✓ | 文本描述 |
n | integer | 生成數量,預設 1 | |
size | string | 1024x1024、1792x1024、1024x1792 等 | |
quality | string | "standard" | "hd" | |
style | string | "vivid" | "natural"(DALL·E 3) | |
response_format | string | "url"(預設)或 "b64_json" | |
user | string | 業務方使用者標識 |
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 信封:
| 引數 | 型別 | 必填 | 說明 |
|---|---|---|---|
model | string | ✓ | 如 qwen-image、qwen-image-plus |
input | object | ✓ | 包含 prompt 等核心輸入 |
parameters | object | 包含 size、n、negative_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),互不通用