原生 OpenAI 格式
Endpoint
POST /v1/chat/completions
Header 参数
| Name | Type | Required | Description | Example |
|---|---|---|---|---|
Authorization | string | No | Bearer {your_token} |
请求体参数
| Field | Type | Required | Title | Description |
|---|---|---|---|---|
model | string | Yes | 模型名称 | 可选:NanoBanana,NanoBananaPro-1K,NanoBananaPro-2K,NanoBananaPro-4K,NanoBanana2-0.5K,NanoBanana2-1K,NanoBanana2-2K,NanoBanana2-4K |
--aspect_ratio | string | Yes | 宽高比 | 可选:1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
--output_format | string | Yes | 图片类型 | 可选:"jpeg",“png”,“webp” |
messages | array | No | Example field | Appears in a request example; no separate field description is provided. |
extra_body | object | No | Example field | Appears in a request example; no separate field description is provided. |
stream | boolean | No | Example field | Appears in a request example; no separate field description is provided. |
请求示例
文生图
{
"model": "NanoBananaPro-1K",
"messages": [
{
"role": "user",
"content": "a cute cat"
}
],
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9"
}
}
},
"stream": true
}
curl -X POST "{BASE_URL}/v1/chat/completions" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "NanoBananaPro-1K",
"messages": [
{
"role": "user",
"content": "a cute cat"
}
],
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9"
}
}
},
"stream": true
}'
图生图
{
"model": "NanoBananaPro-1K",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "在同一画布下,生成此物品的三视图,必须白色背景"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/xxxxxxx.jpg"
}
}
]
}
],
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9"
}
}
},
"stream": true
}
curl -X POST "{BASE_URL}/v1/chat/completions" \
-H "Authorization: Bearer sk-***" \
-H "Content-Type: application/json" \
-d '{
"model": "NanoBananaPro-1K",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "在同一画布下,生成此物品的三视图,必须白色背景"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/xxxxxxx.jpg"
}
}
]
}
],
"extra_body": {
"google": {
"image_config": {
"aspect_ratio": "16:9"
}
}
},
"stream": true
}'
响应字段
| Field | Type | Required | Title | Description |
|---|
响应示例
生成成功
{
"id": "chatcmpl_3a72451d018247b6a14adb45275c2433",
"object": "chat.completion.chunk",
"created": 1773835762,
"model": "NanoBananaPro-8K",
"choices": [
{
"index": 0,
"delta": {
"role": "assistant",
"content": "https://xxx.xxx.cn/output/38fa5bcb-d055-40b0-9f04-5ef259c9131c-u2_307ace79-d89b-4075-9e71-8180774947c4.jpeg"
},
"finish_reason": "stop"
}
],
"media": {
"outputs": [
"https://xxx.xxx.cn/output/38fa5bcb-d055-40b0-9f04-5ef259c9131c-u2_307ace79-d89b-4075-9e71-8180774947c4.jpeg"
]
}
}