元渊 API元渊 API
Best Practices

NanoBananaPro Native Google Format Aspect Ratio Output

Generate images with specified aspect ratios and resolutions using Google's native format API

Overview

Nano Banana Pro (gemini-3-pro-image-preview) supports various aspect ratios and resolution options, allowing you to precisely control the dimensions of generated images.

Supported Aspect Ratios

Nano Banana Pro supports the following aspect ratios:

  • 1:1 - Square images
  • 16:9 - Standard landscape
  • 9:16 - Standard portrait
  • 4:3 - Traditional landscape
  • 3:4 - Traditional portrait
  • 3:2 - Camera standard (landscape)
  • 2:3 - Camera standard (portrait)
  • 21:9 - Ultra-wide
  • 5:4 - Display ratio (landscape)
  • 4:5 - Display ratio (portrait)

Supported Resolutions

Each aspect ratio supports three resolution levels:

1K Resolution (Quick Preview)

Aspect RatioResolution
1:11024×1024
16:91376×768
9:16768×1376
4:31200×896
3:4896×1200
3:21232×816
2:3816×1232
21:91584×672
5:41136×896
4:5896×1136
Aspect RatioResolution
1:12048×2048
16:92752×1536
9:161536×2752
4:32400×1792
3:41792×2400
3:22464×1632
2:31632×2464
21:93168×1344
5:42272×1792
4:51792×2272

4K Resolution (Ultra HD)

Aspect RatioResolution
1:14096×4096
16:95504×3072
9:163072×5504
4:34800×3584
3:43584×4800
3:24928×3264
2:33264×4928
21:96336×2688
5:44544×3584
4:53584×4544

API Request Format

Basic Request Structure

{
  "contents": [{
    "parts": [
      {"text": "Your image description"}
    ]
  }],
  "generationConfig": {
    "responseModalities": ["IMAGE"],
    "imageConfig": {
      "aspectRatio": "16:9",
      "image_size": "2K"
    }
  }
}

Parameter Description

  • responseModalities: Must be set to ["IMAGE"] to return an image
  • aspectRatio: Aspect ratio, choose from the supported ratios above
  • image_size: Resolution level, options are "1K", "2K", "4K"

Example Code

cURL Example

curl -X POST "https://api.ai.soraliststudio.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [
        {"text": "A cute kitten sitting in a garden, oil painting style, high definition, rich in detail"}
      ]
    }],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "aspectRatio": "16:9",
        "image_size": "2K"
      }
    }
  }'

Python Example

import requests
import base64

API_KEY = "sk-YOUR_API_KEY"
API_URL = "https://api.ai.soraliststudio.com/v1beta/models/gemini-3-pro-image-preview:generateContent"

payload = {
    "contents": [{
        "parts": [
            {"text": "A cute kitten sitting in a garden, oil painting style, high definition, rich in detail"}
        ]
    }],
    "generationConfig": {
        "responseModalities": ["IMAGE"],
        "imageConfig": {
            "aspectRatio": "16:9",
            "image_size": "2K"
        }
    }
}

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

response = requests.post(API_URL, headers=headers, json=payload, timeout=600)

if response.status_code == 200:
    data = response.json()
    image_base64 = data["candidates"][0]["content"]["parts"][0]["inlineData"]["data"]
    
    # Save image
    with open("output.png", "wb") as f:
        f.write(base64.b64decode(image_base64))
    print("Image saved as output.png")

Performance Recommendations

Different resolutions require different processing times. Set appropriate timeout values:

  • 1K Resolution: 360 seconds (6 minutes) - For quick previews
  • 2K Resolution: 600 seconds (10 minutes) - Recommended for daily use
  • 4K Resolution: 1200 seconds (20 minutes) - Ultra HD quality

Bandwidth Optimization

Since image data is transferred using base64 encoding, the data volume is large:

  • Recommended to use metered high-speed bandwidth
  • Avoid network congestion affecting upload and download speeds
  • 4K image base64 data may exceed 10MB

Notes

  1. Higher resolution means longer generation time: Choose the appropriate resolution based on your actual needs
  2. Price impact: Different resolutions may have different prices, check the latest pricing
  3. Network stability: High-resolution image transfers require a stable network connection
  4. Reasonable timeout settings: Set sufficient timeout to avoid request interruption

How is this guide?