OpenAI 生成图片
/v1/images/generations 是 OpenAI Images API 兼容的同步生图接口。调用方会在同一个 HTTP 请求中等待上游返回。
接口说明
| 项目 | 值 |
|---|---|
| Method | POST |
| Path | /v1/images/generations |
| Content-Type | application/json |
| 认证 | Authorization: Bearer YOUR_API_KEY |
| 平台要求 | OpenAI 平台分组,且分组启用生图能力 |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 否 | 图片模型。未传时默认 gpt-image-2。必须是 gpt-image-* 系列。 |
prompt | string | 是 | 生图提示词。 |
size | string | 否 | 输出尺寸,例如 1024x1024。 |
n | integer | 否 | 生成图片数量,默认 1,必须大于 0。 |
response_format | string | 否 | 响应格式,常用 b64_json。 |
stream | boolean | 否 | 是否流式返回,按上游能力透传。 |
quality | string | 否 | OpenAI 原生图片参数,按上游能力透传。 |
background | string | 否 | OpenAI 原生图片参数,按上游能力透传。 |
output_format | string | 否 | OpenAI 原生图片参数,按上游能力透传。 |
output_compression | integer | 否 | OpenAI 原生图片参数,按上游能力透传。 |
moderation | string | 否 | OpenAI 原生图片参数,按上游能力透传。 |
style | string | 否 | OpenAI 原生图片参数,按上游能力透传。 |
请求示例
bash
curl https://llmapi.site/v1/images/generations \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-image-2",
"prompt": "a product photo of a ceramic coffee cup on a white table",
"size": "1024x1024",
"n": 1,
"response_format": "b64_json"
}'响应示例
json
{
"created": 1779912000,
"data": [
{
"b64_json": "..."
}
]
}常见错误
非 OpenAI 分组调用:
json
{
"error": {
"type": "not_found_error",
"message": "Images API is not supported for this platform"
}
}模型不是图片模型:
json
{
"error": {
"type": "invalid_request_error",
"message": "images endpoint requires an image model"
}
}适用边界
- 本接口只适用于 OpenAI Images API 兼容请求。
- Gemini native 图片请求应使用
/v1beta/models/{model}:generateContent。 - 长耗时或生产批量任务建议使用异步生图接口。