nano-banana-2.1; replace the model in the URL or SDK call to use either of the other two.
Connection details
Create a BetterToken API Key · model plaza · Nano Banana model launch
Generate your first image
SetBETTERTOKEN_API_KEY in your terminal, then run the request. It waits for generation and saves the full JSON response to response.json.
- macOS / Linux
- Windows PowerShell
imageSize to 2K or 4K for higher resolution. Start with 1K, 1:1, and one image. Do not add automatic generation retries with --retry.
Common parameters
For product photography, describe the subject, material, lighting, and background. For posters, specify the exact text and layout. For edits, state what should change and what should stay unchanged. Use these fields in native HTTP requests; Python SDK names use snake_case. Place image settings insidegenerationConfig.imageConfig.
Google-supported aspect ratios
Nano Banana 2 and 2.1 support 14 ratios; Pro supports 10. Start with1:1 for your first request.
Google aspect-ratio and image-size reference
The output limit does not guarantee an image count. The model may return one image even if asked for more. For a fixed number of images, send separate requests.
Read and save the image
Images are incandidates[].content.parts[].inlineData. The example below shows the response shape; BASE64_IMAGE_DATA is a placeholder. Read all final image parts and skip intermediate parts marked thought: true.
mimeType: an image may be JPEG, so do not always save it as .png.
Complete Python SDK example
Use Python 3.10 or later. This example targetsgoogle-genai==2.30.1. Install it in a project virtual environment; older SDK releases may omit image_size from the request.
/v1 or /v1beta. timeout is in milliseconds; attempts=1 disables automatic retries. The save_images helper saves every final image.
Send a reference image
Run the following after the Python example to send a new editing request. Replacereference.jpg with your local file. For PNG, use mime_type="image/png". Add further reference images as parts in the same user message.
inlineData: {"mimeType": "image/jpeg", "data": "BASE64_IMAGE_DATA"}. Encode the original file bytes without a data:image/...;base64, prefix. This integration uses neither multipart nor Files uploads or fileData.
Continue editing
Run this after a successful generation or reference edit. Preserve the entire model responsecontent, including part order and thoughtSignature. Do not rebuild it from the image alone or invent or alter signatures.
history, append the new user instruction, then append the returned model content. Do not use the Interactions field previous_interaction_id with this endpoint.
API support
- Use non-streaming
generateContent. Files /fileData, Batch, Interactions, and streaming are not supported by this integration. responseMimeType,responseSchema, and custom image compression formats are not supported. Use only the twoimageConfigfields listed above.- Omit
cachedContent, function calling, code execution, file search, Maps, URL context, and audio input or generation settings.
Using an existing OpenAI Chat client
You can callPOST /v1/chat/completions with Base URL https://bettertoken.ai/v1. Use the Gemini native endpoint above for new integrations, reference images, and multi-turn editing. In Chat requests, omit n or set it to integer 1.
With raw HTTP, put google.image_config at the JSON root. In the Python OpenAI SDK, pass it through extra_body, which the SDK merges into the root. Do not use generationConfig here.
openai==1.66.2 in the same virtual environment, then run:
choices[0].message.content, not the Images API data[] array. Do not reconstruct signed edit history from this text; use the native editing example.
Common errors
Images are delivered in the current response. This workflow has no background image retrieval or task polling endpoint. Save successful results promptly, allow enough time in both SDK and proxy, and disable automatic retries.

