Images Generations
POST https://api.wrouter.io/v1/images/generations支持两种请求形态,按 model 自动路由:
- OpenAI 形态 — 适用于
dall-e-3、gpt-image-1、flux-pro等 - 百炼 / Qwen 形态 — 适用于
qwen-image、阿里通义系列;这是 newapi 网关原生文档化的格式
形态 A:OpenAI 形态
兼容 OpenAI Images API。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
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://api.wrouter.io/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://api.wrouter.io/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://api.wrouter.io/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.io/.../image.png", "revised_prompt": "..."}
]
}注意事项
- 生成的图片 URL 有效期 24 小时,长期使用请客户端下载到自己存储
- 部分模型不支持
n>1,请改为多次调用 - 违反上游内容安全策略的 prompt 会返回 400 +
content_policy_violation - Qwen-image 系列的
size使用星号格式(1024*1024),OpenAI 系列使用x格式(1024x1024),互不通用