nano-banana-2

nano-banana-2
图像GoogleNano Banana 2nano-banana-2
谷歌最具性价比的图像生成模型

Authentication

Base URL
https://host.docker.internal:8000
Authorization
Authorization: Bearer YOUR_API_KEY
Content-Type
application/json
Model name
nano-banana-2

Integration protocols

Why this protocol

适合原本使用 Gemini SDK 或 generateContent 接口的用户直接迁移。

Endpoint
POST/v1beta/models/nano-banana-2:generateContent
Authorization: Bearer YOUR_API_KEYContent-Type: application/json

Request / Response JSON

Request examples
Image URLfileData.fileUri
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "修复键盘顶端斑驳痕迹,其他内容不变"
        },
        {
          "fileData": {
            "fileUri": "https://example.com/reference.png"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "imageConfig": {
      "imageSize": "1K"
    },
    "responseModalities": [
      "IMAGE"
    ]
  }
}
Base64 imageinlineData.mimeType + inlineData.data
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "修复键盘顶端斑驳痕迹,其他内容不变"
        },
        {
          "inlineData": {
            "mimeType": "image/jpeg",
            "data": "BASE64_IMAGE_DATA"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "imageConfig": {
      "imageSize": "1K"
    },
    "responseModalities": [
      "IMAGE"
    ]
  }
}
Response example
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8Xw8AAoMBgAqJvhoAAAAASUVORK5CYII="
            }
          }
        ]
      }
    }
  ],
  "modelVersion": "nano-banana-2",
  "usageMetadata": {
    "promptTokenCount": 8,
    "candidatesTokenCount": 16,
    "totalTokenCount": 24
  }
}

Request / Response schema

// INPUT SCHEMA
FieldTypeRequired
contentsarrayY
contents[]objectY
contents[].rolestringY
contents[].partsarrayY
contents[].parts[]objectY
contents[].parts[].textstringY
generationConfigobjectY
generationConfig.imageConfigobjectY
generationConfig.imageConfig.imageSizestringY
// RESPONSE SCHEMA
FieldTypeRequired
output.images[]imageN

Code examples

cURLrequest.sh
curl -X POST "https://host.docker.internal:8000/v1beta/models/nano-banana-2: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"
    }
  }
}'

# Upload reference cURL
curl -X POST "https://host.docker.internal:8000/v1/files/upload" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "kind=image" \
  -F "purpose=reference" \
  -F "file=@demo.png"
Why this protocol

适合需要提交任务并轮询状态的图像、视频、音频生成工作流。

Endpoint
POST/v1/jobs
Authorization: Bearer YOUR_API_KEYContent-Type: application/json

Request / Response JSON

// REQUEST
{
  "model": "nano-banana-2",
  "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-2",
  "created": 1710000000,
  "request_id": "req_example"
}

Request / Response schema

// INPUT SCHEMA
FieldTypeRequired
promptstringY
reference_image_urlsarrayN
image_sizeenumN
aspect_ratioenumN
mime_typeenumN
response_modalitiesarrayN
seedintegerN
callback_urlstringN
// RESPONSE SCHEMA
FieldTypeRequired
output.images[]imageN

Code examples

cURLrequest.sh
curl -X POST "https://host.docker.internal:8000/v1/jobs" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
  "model": "nano-banana-2",
  "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"
  }
}'

# Upload reference cURL
curl -X POST "https://host.docker.internal:8000/v1/files/upload" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "kind=image" \
  -F "purpose=reference" \
  -F "file=@demo.png"

# Poll status cURL
# Replace job_example with the task_id returned by the submit call
curl -X GET "https://host.docker.internal:8000/v1/jobs/job_example" \
  -H "Authorization: Bearer YOUR_API_KEY"