NanoBanana Pro
NanoBanana Pro is Gemini’s image generation service. It supports multiple aspect ratios (1:1, 16:9, 9:16, etc.) and resolutions (1K, 2K, 4K). All resolutions share the same price; 4K is slower to generate and not recommended. See Pricing.
Endpoint: POST https://aiberm.com/v1beta/models/gemini-3-pro-image-preview:generateContent
Key points: Send the image description in request body contents; set responseModalities, imageConfig (aspect ratio, resolution) in generationConfig. The generated image is in candidates[0].content.parts as inline_data.
Example code
Python uses snake_case (e.g. response_modalities); REST/cURL uses camelCase (e.g. responseModalities). They mean the same.
1from google import genai2from google.genai import types3 4base_url = "https://aiberm.com"5api_key = "YOUR_API_KEY"6prompt = "Generate a cute sea otter image"7model = "gemini-3-pro-image-preview"8output_file = "gemini_sdk_generated.png"9 10# Image generation config11response_modalities = ["IMAGE"] # or ["TEXT", "IMAGE"]12aspect_ratio = "16:9" # "1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9"13image_size = "2K" # "1K", "2K", "4K" (gemini-3-pro-image-preview only)14 15# Generation params16temperature = 1.017top_p = 0.9518max_output_tokens = 819219enable_google_search = False # Enable Google Search(adds latency & cost; disable for image-only)20 21client = genai.Client(22 api_key=api_key,23 http_options=types.HttpOptions(api_version="v1beta", base_url=base_url)24)25 26config = types.GenerateContentConfig(27 response_modalities=response_modalities,28 temperature=temperature,29 top_p=top_p,30 max_output_tokens=max_output_tokens,31 system_instruction="You are a helpful assistant.",32 image_config=types.ImageConfig(33 aspect_ratio=aspect_ratio,34 image_size=image_size if "pro-image" in model else None35 )36)37if enable_google_search:38 config.tools = [{"google_search": {}}]39 40response = client.models.generate_content(41 model=model,42 contents=[prompt],43 config=config44)45 46for part in response.parts:47 if part.text is not None:48 print(part.text)49 elif part.inline_data is not None:50 part.as_image().save(output_file)51 print(f"Image saved: {output_file}")cURL image parameters
Below are parameter names (camelCase) for cURL; use snake_case in Python (e.g. aspectRatio → aspect_ratio).
imageConfig (generationConfig.imageConfig or SDK ImageConfig):
- aspectRatio
string—1:1,2:3,3:2,3:4,4:3,4:5,5:4,9:16,16:9,21:9 - imageSize
string—1K,2K,4K(gemini-3-pro-image-preview only)
Other common generationConfig fields:
- responseModalities
string[]—["IMAGE"]or["TEXT", "IMAGE"] - temperature
number— 0–2, higher = more random - topP
number— 0–1, diversity - maxOutputTokens
number— e.g. 8192 - systemInstruction
object— e.g.{"parts": [{"text": "..."}]} - tools
array— e.g.[{"google_search": {}}]
Enabling Google Search
Only the Gemini-style API supports Google Search. Pass tools in the config; the model will use real-time web info when needed.
Not recommended by default: Adds latency and cost; unnecessary for image-only use. Turn off if you don’t need search.
Python (SDK):
config = types.GenerateContentConfig(
# ... other params like response_modalities, image_config
tools=[{"google_search": {}}]
)
response = client.models.generate_content(model=model, contents=[prompt], config=config)
cURL (REST):
Add tools at the top level of the request body:
curl -X POST "https://aiberm.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "Your question"}]}],
"generationConfig": { ... },
"tools": [{"google_search": {}}]
}'
FAQ
- No image in response: Ensure model is
gemini-3-pro-image-previewand the prompt is a clear image description. - Decode error: Use only the base64 string after
data:image/...;base64,and remove newlines before decoding.