Gateway Protocols多标准协议兼容
OpenAIAnthropicGeminiOpenRouter
Chat / Responses / Messages / Claude MessagesPOST /v1/images/generations
文生图
OpenAI 标准文生图;同步结果由 Gateway 先落 COS,再返回 data[].url;异步扩展可通过 async 或 callbackUrl 使用。
接口信息
输入参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 图片模型编码。 |
prompt | string | 是 | 图片生成提示词。 |
n | integer | 否 | 生成数量。 |
size | string | 否 | 宽高比或尺寸,例如 1:1。 |
image_size | string | 否 | 分辨率档位,例如 1K / 2K / 4K。 |
async | boolean | 否 | true 时返回任务 ID,需查询任务结果。 |
callbackUrl | string | 否 | 异步任务完成后的回调地址。 |
输出参数
| 参数 | 类型 | 返回 | 说明 |
|---|---|---|---|
created | integer | 同步时 | 同步出图创建时间。 |
data[].url | string | 成功时 | 生成图片 URL;同步结果默认先上传 COS 后返回该字段。 |
data[].b64_json | string | 兼容保留 | base64 图片内容;仅兼容旧链路或特定 response_format,不建议依赖。 |
usage | object | 否 | 图片生成 token 用量统计。 |
task_id | string | 是 | 网关本地任务 ID;同步/异步均返回,可用于查询任务结果。 |
taskId | string | 是 | 同 task_id,返回给下游使用的网关本地任务 ID。 |
status | string | 异步时 | 任务状态,提交后通常为 pending。 |
补充说明
- 回调接口:请求中传 callbackUrl 后,Gateway 会在图片任务成功后向该地址发起 POST,Content-Type 为 application/json。
- 回调 body 与 GET /v1/images/tasks/{taskId} 的成功响应一致,顶层直接包含 task_id、taskId、status、data、usage、error 等字段。
- 灰度兼容:Portal 预览同时兼容旧版 { result: { data: [...] } } 包装和新版顶层 data[].url。
错误代码
| HTTP 状态码 | 错误 | 说明 |
|---|---|---|
400 | Bad Request | 参数格式错误,例如文生图传入参考图字段。 |
401 | Unauthorized | Client Key 无效或未提供。 |
402 | Payment Required | 余额不足或配额超限。 |
示例
请求示例
{
"model": "your-image-model",
"prompt": "A cute cat in watercolor style",
"n": 1,
"size": "1:1",
"image_size": "1K"
}响应示例
{
"created": 1710000000,
"task_id": "img-202406010001",
"taskId": "img-202406010001",
"data": [
{
"url": "https://example.com/generated/image.png"
}
],
"usage": {
"input_tokens": 7148,
"output_tokens": 7024,
"total_tokens": 14172,
"input_tokens_details": {},
"output_tokens_details": {}
}
}