鉴权与连接
- Base URL
https://backend:8000- Authorization
Authorization: Bearer YOUR_API_KEY- Content-Type
application/json- 模型名 (model)
nano-banana-pro
接入协议
为什么选这个协议
适合原本使用 Gemini SDK 或 generateContent 接口的用户直接迁移。
接口地址
POST/v1beta/models/nano-banana-pro:generateContent
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
请求示例
图片链接方式fileData.fileUri
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "修复键盘顶端斑驳痕迹,其他内容不变"
},
{
"fileData": {
"fileUri": "https://example.com/reference.png"
}
}
]
}
],
"generationConfig": {
"imageConfig": {
"imageSize": "1K"
},
"responseModalities": [
"IMAGE"
]
}
}Base64 方式inlineData.mimeType + inlineData.data
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "修复键盘顶端斑驳痕迹,其他内容不变"
},
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "BASE64_IMAGE_DATA"
}
}
]
}
],
"generationConfig": {
"imageConfig": {
"imageSize": "1K"
},
"responseModalities": [
"IMAGE"
]
}
}响应示例
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": {
"mimeType": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8Xw8AAoMBgAqJvhoAAAAASUVORK5CYII="
}
}
]
}
}
],
"modelVersion": "nano-banana-pro",
"usageMetadata": {
"promptTokenCount": 8,
"candidatesTokenCount": 16,
"totalTokenCount": 24
}
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| contents | array | Y |
| contents[] | object | Y |
| contents[].role | string | Y |
| contents[].parts | array | Y |
| contents[].parts[] | object | Y |
| contents[].parts[].text | string | Y |
| generationConfig | object | Y |
| generationConfig.imageConfig | object | Y |
| generationConfig.imageConfig.imageSize | string | Y |
// RESPONSE SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| output.images[] | image | N |
代码示例
cURLrequest.sh
curl -X POST "https://backend:8000/v1beta/models/nano-banana-pro:generateContent" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "修复键盘顶端斑驳痕迹,其他内容不变"
},
{
"fileData": {
"fileUri": "https://example.com/reference.png"
}
}
]
}
],
"generationConfig": {
"imageConfig": {
"imageSize": "1K"
}
}
}'
# 上传参考文件 cURL
curl -X POST "https://backend:8000/v1/files/upload" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "kind=image" \
-F "purpose=reference" \
-F "file=@demo.png"为什么选这个协议
适合需要提交任务并轮询状态的图像、视频、音频生成工作流。
接口地址
POST/v1/jobs
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
// REQUEST
{
"model": "nano-banana-pro",
"input": {
"prompt": "修复键盘顶端斑驳痕迹,其他内容不变",
"reference_image_urls": [
"https://example.com/reference.png"
],
"image_size": "1K",
"aspect_ratio": "1:1",
"mime_type": "image/png",
"response_modalities": [
"TEXT",
"IMAGE"
],
"seed": 12345,
"callback_url": "https://example.com/webhook"
}
}// RESPONSE
{
"id": "job_example",
"object": "job",
"status": "processing",
"model": "nano-banana-pro",
"created": 1710000000,
"request_id": "req_example"
}请求字段 / 响应字段
// INPUT SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| prompt | string | Y |
| reference_image_urls | array | N |
| image_size | enum | N |
| aspect_ratio | enum | N |
| mime_type | enum | N |
| response_modalities | array | N |
| seed | integer | N |
| callback_url | string | N |
// RESPONSE SCHEMA
| 字段 | 类型 | 必填 |
|---|---|---|
| output.images[] | image | N |
代码示例
cURLrequest.sh
curl -X POST "https://backend:8000/v1/jobs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "nano-banana-pro",
"input": {
"prompt": "修复键盘顶端斑驳痕迹,其他内容不变",
"reference_image_urls": [
"https://example.com/reference.png"
],
"image_size": "1K",
"aspect_ratio": "1:1",
"mime_type": "image/png",
"response_modalities": [
"TEXT",
"IMAGE"
],
"seed": 12345,
"callback_url": "https://example.com/webhook"
}
}'
# 上传参考文件 cURL
curl -X POST "https://backend:8000/v1/files/upload" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "kind=image" \
-F "purpose=reference" \
-F "file=@demo.png"
# 查询任务状态 cURL
# 将 job_example 替换为提交任务返回的 task_id
curl -X GET "https://backend:8000/v1/jobs/job_example" \
-H "Authorization: Bearer YOUR_API_KEY"