Nano Banana: model selection and OpenAI API setup
Nano Banana 2, 2.1, and Pro with BetterToken: compare products, generate and edit with OpenAI Images, set sizes, use Python SDK, save images, and check billing.
Updated October 22, 2026.
Choose a model · Compare images · Quick setup · Sizes and parameters · Edit with reference images · Python SDK · Billing and troubleshooting
With one BetterToken API Key, you can call every image-generation model available on the platform, including Nano Banana 2, 2.1, Pro, and the GPT Image series. Start with one integration for text-to-image, recoloring from a reference, and combining two images, then choose a model for each task and focus on composition, materials, and creative direction.
If you have not chosen a model yet, start with Nano Banana 2 + 1K to explore composition, then use a description or reference image you like to create 2K or 4K assets. In our same-prompt product image samples, Nano 2 had shorter wait times, 2.1 made the subject more prominent, and Pro left more negative space. These differences can help you choose a direction for drafts; the final choice still depends on your product and layout.
Why integrate Nano Banana with BetterToken?
The integration format can differ across tools and services, even for Nano Banana: some use Gemini’s native message structure, some use OpenAI Images, and others put image generation in Chat Completions. Different request fields, reference-image upload methods, and image response locations can leave developers spending time reconciling API differences.
BetterToken provides three ways to call Nano Banana: OpenAI Images, native Gemini image generation, and OpenAI Chat Completions. If your project already uses an OpenAI SDK, choose Images or Chat for the task. If you already have a Google SDK or Gemini workflow, keep the native format. All three use the same BetterToken API Key; see Protocol choices for parameters and scope.
- Compare models without managing another integration. Nano Banana and GPT Image both work with the same Key. In an Images workflow, reuse authentication, the request URL, and Base64 decoding, then adjust parameters supported by each model.
- Go from ideation to edits with a familiar client. Explore with text, upload one reference to change its color, or upload two references to combine a scene. An existing OpenAI Images client does not need a separate Gemini call chain for Nano Banana.
- Check delivery specifications and costs together. Along with the image, the response provides its actual format, pixel dimensions, billing tier, and settlement details so your application can save, lay out, and record costs correctly.
Focus on image quality when choosing a model; when integrating it into your application, use the documented parameter rules and response fields. First compare images made with the same prompt, then add generation and editing to your workflow.
Choose a model for the task
| What you want to do | Suggested starting point | What to check next |
|---|---|---|
| Quickly explore product composition, colors, and style | nano-banana-2, 1K | Check the subject, lighting, and negative space, then increase resolution |
| Compare another material rendering and subject scale | nano-banana-2.1 | Use the same prompt and specifications, and compare it side by side with Nano 2 |
| Find a product image that can accommodate a headline | nano-banana-pro | Specify the negative-space location in the prompt and check the layout |
| Recolor an existing product image or change its background | Images editing with any of the three | Start with a real reference image and check the product structure, labels, and colors one by one |
| Combine two reference images into a scene | Start with the Pro two-image example | Specify what each image contributes and where each element should go |
Change one key variable at a time. Keep the prompt and specifications fixed when comparing models; keep the model fixed when comparing compositions. Otherwise, it is hard to tell whether the model, prompt, or size changed the image.
How do the three Nano models render the same product prompt?
The task: a coral-red ceramic mug on a pale gray stone table, with beige linen and the white words BETTER DAY on the mug, lit from the upper left. Each full image below is 2048 × 2048; crops show the same-size region from each original.
Mug rim and glaze
Typography and layout
Linen and tabletop
| What to compare | Nano Banana 2 | Nano Banana 2.1 | Nano Banana Pro |
|---|---|---|---|
| Material | Rim glaze variation, dark specks, and the clay-colored base stand out | Soft rim transitions, fine specks, and reflections are all visible | More even surface with a continuous highlight |
| Text | Two lines, larger type | One line, wide letter spacing | One line, narrower letterforms and smaller scale |
| Composition | Mug, cloth, and stone-table details all stand out | Mug takes up more of the frame, with a concentrated subject | Smaller mug, with more negative space from the table edge and draped cloth |
In this sample, start with Nano 2 for a handmade ceramic feel, compare 2.1 when you want the product to stand out more, or look at Pro’s negative space if you plan to add a headline. These are patterns in this sample; still specify composition requirements in your prompt.
Compare with GPT Image 2.5
The mugs in the Flare and Sunburst samples have more even surfaces, while their typography and line breaks differ. All five models rendered the short English text “BETTER DAY,” but none maintained consistent typography and layout. Add brand fonts, an exact logo, and longer copy separately after generation.
| Model | Time for a 1K square | Time for a 2K square |
|---|---|---|
| Nano Banana 2 | 16.2 seconds | 27.1 seconds |
| Nano Banana 2.1 | 68.6 seconds | 73.5 seconds |
| Nano Banana Pro | 23.3 seconds | 31.0 seconds |
| GPT Image 2.5 Flare | 41.6 seconds | 62.3 seconds |
| GPT Image 2.5 Sunburst | 37.4 seconds | 38.5 seconds |
These times are from one request per target tier using the same product prompt and include service and network wait. Nano 1K squares are 1024 × 1024; the two GPT models returned 1254 × 1254 at that tier. All 2K images are 2048 × 2048. Nano 2 had the shortest wait in this task and is a useful starting point for iterative drafts; these times are not long-run averages.
Turn your brief into an image description and output specifications
A reusable product-photography prompt should at least specify the subject, material, lighting, background, and what to preserve. For example:
Create a realistic studio product photograph of one coral-red ceramic mug on a pale grey stone table, a folded beige linen cloth beside it. Print the exact white text BETTER DAY on the mug. Soft upper-left light, natural shadows, detailed ceramic glaze and linen fibres. Show the entire mug, simple background, no watermark, no additional objects or text.Replace the subject, color, and material with those of your product. To add a headline, specify which side should remain empty; for a smooth glaze, describe the surface. If you have a photo of the actual product, a reference image can constrain its appearance better than text alone. Still check for changes to the product structure before publishing.
Control resolution with parameters. In all three comparison images where “2K” or “4K” appeared only in the prompt, the response was still 1024 × 1024. Start at 1K to explore, then set image_size: "2K" or "4K". A higher tier generates a new image; to continue an existing composition, use the image you like as a reference and check for detail changes.
Generate your first image with OpenAI Images
Start a new integration with the HTTP example below. If you already use the OpenAI Python client, go directly to the SDK example. Text-to-image and reference editing share authentication and image-saving logic.
| Setting | Value |
|---|---|
| OpenAI SDK Base URL | https://bettertoken.ai/v1 |
| Text-to-image | POST https://bettertoken.ai/v1/images/generations, JSON |
| Reference-image editing | POST https://bettertoken.ai/v1/images/edits, multipart form |
| Authentication | Authorization: Bearer YOUR_API_KEY |
| Model IDs | nano-banana-2, nano-banana-2.1, nano-banana-pro |
| Image response | data[].b64_json contains image data; data[].mime_type gives the actual format |
Get an API Key · View models and pricing
curl: one 2K landscape product image
Set BETTERTOKEN_API_KEY in a macOS or Linux terminal, then run the request. Keep the Key in a server-side environment variable; do not embed it in a public webpage. The request returns synchronously; --max-time 650 allows time for generation.
export BETTERTOKEN_API_KEY="YOUR_API_KEY"
curl --fail-with-body --max-time 650 \ "https://bettertoken.ai/v1/images/generations" \ -H "Authorization: Bearer $BETTERTOKEN_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "nano-banana-2", "prompt": "A product photo of a green ceramic mug on a studio table", "image_size": "2K", "aspect_ratio": "16:9", "n": 1, "response_format": "b64_json" }' -o response.jsonThe image below was generated with these parameters: 2752 × 1536, JPEG, about 35.7 seconds for one request. A landscape composition can work for a cover or an image in an article. When saving, choose the extension based on the actual response format.
Nano Banana 2 · 2K landscape
16:9, actual dimensions 2752 × 1536, JPEG

Save images using the actual format for the file extension
The structure of a successful response is shown below, with the Base64 content replaced by a placeholder:
{ "data": [{ "b64_json": "BASE64_IMAGE_DATA", "mime_type": "image/jpeg" }]}Save the following as save_images.py and run python save_images.py to read the response.json from the previous example. Text-to-image and editing use the same save logic.
import base64import jsonfrom pathlib import Path
result = json.loads(Path("response.json").read_text(encoding="utf-8"))images = result.get("data") or []if not images: raise RuntimeError("No image returned; inspect response.json.")suffixes = {"image/png": ".png", "image/jpeg": ".jpg"}for index, item in enumerate(images, 1): mime = item.get("mime_type") if mime not in suffixes: raise ValueError(f"Unexpected image MIME type: {mime}") path = Path(f"generated-{index}{suffixes[mime]}") path.write_bytes(base64.b64decode(item["b64_json"], validate=True)) print(path)Do not always save as .png. You can omit Nano’s output_format; even when you pass "png", the response may be JPEG. This has occurred in tests with Pro. To use WebP, a specific compression ratio, or a consistent file format, receive the image first and convert it in your application.
Sizes, aspect ratios, and image count: what should you set?
Prefer image_size + aspect_ratio
| Field | Values and meaning |
|---|---|
prompt | Required and cannot be blank; describe the image or requested edits |
image_size | 1K, 2K, or 4K; defaults to 1K when omitted |
aspect_ratio | Set the image ratio; the model chooses when omitted |
n | Accepts integer 1–4; fewer images may be returned than requested. Examples in this guide use 1 |
response_format | Use b64_json; url is not supported |
output_format | Best omitted; accepts only png, and the actual format is still determined by mime_type |
1K is suitable for exploring composition, 2K for inspecting materials and detail, and 4K for leaving pixels for later cropping and large layouts. K is a tier; a rectangular image’s width or height does not have to equal 1024, 2048, or 4096. For example, the 2K 16:9 sample in this guide is 2752 × 1536, while the 4K 1:1 Nano 2.1 sample is 4096 × 4096.
BetterToken returns 4K images that the model generates directly, without upscaling them to meet the target size. An image with the same dimensions can also come from upscaling 1K or 2K. See how to tell native 4K from upscaled 4K.
| Model | Available ratios |
|---|---|
| Supported by all three | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
| Additional ratios for Nano 2 and 2.1 | 1:4, 4:1, 1:8, 8:1 |
Choose 1:1 for a square product card, 3:4 or 9:16 for vertical content, and 16:9 for a landscape cover. The table lists accepted ratios; the examples do not cover every ratio combination.
You can integrate even if your client only accepts size
size is shorthand for the ratio and resolution tier. It accepts auto, a ratio string (for example, 16:9), and the fixed sizes below. A ratio string specifies only the ratio; if image_size is omitted, the tier remains 1K.
size | Equivalent ratio | Tier |
|---|---|---|
1024x1024 | 1:1 | 1K |
1536x1024 / 1024x1536 | 3:2 / 2:3 | 1K |
1536x1152 / 1152x1536 | 4:3 / 3:4 | 1K |
2048x2048 | 1:1 | 2K |
2048x1152 | 16:9 | 2K |
3840x2160 / 2160x3840 | 16:9 / 9:16 | 4K |
size does not guarantee exact pixel dimensions. In a test, Pro accepted 1536x1024 and returned 1264 × 848. If the asset must fit a fixed canvas, choose a close ratio, then scale, pad, or crop it in your application based on its actual dimensions; prefer padding when the entire product must remain visible.
Do not send conflicting settings together, such as size: "1024x1024" with image_size: "2K" or aspect_ratio: "16:9". The simplest approach is to choose one: use a size shorthand, or use only image_size + aspect_ratio.
Remove these parameters when switching from GPT Image
The Nano endpoint currently rejects quality, background, moderation, output_compression, and unlisted extra fields with 400 unsupported_parameter. You cannot replace the model name in a complete GPT Image request and reuse it as is: remove those fields, then choose Nano’s size and ratio.
mask is also not supported by the Nano Images editing endpoint. If you need a transparent background, precise masked editing, or a particular compression format, plan a separate post-processing step or another workflow.
Recolor, combine, and keep editing with reference images
Edit one image: preserve the subject and change a specified attribute
Upload an existing PNG or JPEG file as image, then specify what to change and what to preserve in the prompt. The example changes a blue mug to red; replace reference.png with the path to your local PNG. For JPEG, use the corresponding path and type=image/jpeg.
curl --fail-with-body --max-time 650 \ "https://bettertoken.ai/v1/images/edits" \ -H "Authorization: Bearer $BETTERTOKEN_API_KEY" \ -F 'model=nano-banana-2' \ -F 'prompt=Change the mug to red. Preserve its shape and the background.' \ -F 'image=@reference.png;type=image/png' \ -F 'image_size=1K' \ -F 'aspect_ratio=1:1' \ -F 'n=1' \ -F 'response_format=b64_json' \ -o response.jsonLet curl set the multipart Content-Type and boundary automatically; do not add Content-Type: application/json. Save the response with the earlier save_images.py script.
Nano 2 and Nano 2.1 each recolored a blue mug to red from the same scene, using PNG and JPEG references respectively. Both outputs were 1024 × 1024; the requests took about 15.5 and 57.8 seconds. The main mug shape, tabletop, and background remained. Before using the image to present a product, check the glaze, edges, and labels for changes.
Combine two reference images into one
Upload files using repeated image[] fields and describe the role of each image in upload order. This example places the blue mug from the first image on the left and the red mug from the second image on the right. n=1 is the number of output images, a different concept from the two uploaded references.
curl --fail-with-body --max-time 650 \ "https://bettertoken.ai/v1/images/edits" \ -H "Authorization: Bearer $BETTERTOKEN_API_KEY" \ -F 'model=nano-banana-pro' \ -F 'prompt=Create one photograph with the blue mug from the first image on the left and the red mug from the second image on the right, on the same white table. Preserve both mug shapes. No extra mugs.' \ -F 'image[]=@blue-mug.png;type=image/png' \ -F 'image[]=@red-mug.jpg;type=image/jpeg' \ -F 'image_size=1K' \ -F 'aspect_ratio=3:4' \ -F 'n=1' \ -F 'response_format=b64_json' \ -o response.jsonPro’s result kept both mug shapes recognizable and put them on the requested sides. It was 896 × 1200 and took about 36.6 seconds. For a composite asset, specify which elements to use, where to put them, and what not to add; that is easier to verify than simply asking to “blend the two images.”
Use either image or image[] in a request, not both. Upload actual PNG/JPEG reference files; do not use a local path string or image URL as file content.
Continue editing: use the previous result as the next reference
The Images API does not store conversation history. Save the recolored result first, then use it as image in the next /images/edits request and specify the new instruction, such as “Change only the existing mug handle to gold; preserve the red body and white tabletop.” Each step is a new generation request; check its result before continuing.
For logos, small text, barcodes, or product textures that must remain unchanged, preserve the original asset and restore it in a final layer composite. The color-change comparison below shows why: all three Nano models changed the circles’ color and some of the small text. The small text in the two GPT samples is more legible, but those models also redrew some of the background or edges.
The same two-red-circle reference and instruction to recolor them blue produced different colors and levels of small-text preservation. After a color edit, check non-target areas as well; compositing the original asset is more predictable when some parts must remain exact.
Reuse Images calls with an existing OpenAI Python client
Install openai in your project’s virtual environment. This example uses images.generate; pass Nano-specific parameters through extra_body, which places them at the JSON root in the HTTP request. The code disables automatic SDK retries and saves all returned images according to their MIME type.
python -m pip install openaiimport base64import osfrom pathlib import Pathfrom openai import OpenAI
client = OpenAI( api_key=os.environ["BETTERTOKEN_API_KEY"], base_url="https://bettertoken.ai/v1", timeout=650, max_retries=0,)
def save_response(response, prefix): images = response.data or [] if not images: raise RuntimeError("No image returned.") suffixes = {"image/png": ".png", "image/jpeg": ".jpg"} for index, item in enumerate(images, 1): mime = getattr(item, "mime_type", None) if mime not in suffixes: raise ValueError(f"Unexpected image MIME type: {mime}") path = Path(f"{prefix}-{index}{suffixes[mime]}") path.write_bytes(base64.b64decode(item.b64_json, validate=True)) print(path) billing = getattr(response, "bettertoken_image_billing", None) if billing is not None: print("Billing:", billing)
response = client.images.generate( model="nano-banana-2", prompt="A product photo of a green ceramic mug on a studio table", n=1, response_format="b64_json", extra_body={"image_size": "2K", "aspect_ratio": "16:9"},)save_response(response, "generated")For a single-image edit, reuse client and save_response, and open the file in binary mode:
with open("reference.png", "rb") as source: response = client.images.edit( model="nano-banana-2", image=source, prompt="Change the mug to red. Preserve its shape and the background.", n=1, response_format="b64_json", extra_body={"image_size": "1K", "aspect_ratio": "1:1"}, )save_response(response, "edited")mime_type and bettertoken_image_billing are BetterToken response extensions; do not require the response to contain revised_prompt. See the OpenAI Python SDK documentation for how to access extra request-body parameters and response fields.
Already using Gemini or Chat? Do you need to migrate?
You can keep the protocol familiar to your existing project. BetterToken provides three separate entry points for standalone image tasks, native Gemini messages, and Chat clients. They use the same Key, while their parameters and response structures follow their respective formats.
| Entry point | Where size parameters go | Where images appear | Use it when |
|---|---|---|---|
| OpenAI Images | Root-level image_size, aspect_ratio | data[].b64_json and mime_type | Standalone text-to-image or editing with file references; the primary workflow in this guide |
Native Gemini generateContent | generationConfig.imageConfig.imageSize, aspectRatio | candidates[].content.parts[].inlineData | You already use a Google SDK or Gemini message structure |
| OpenAI Chat Completions | Root-level google.image_config.image_size, aspect_ratio | Image Data URL in choices[0].message.content | You already have a Chat text-to-image integration |
The native Gemini URL is https://bettertoken.ai/v1beta/models/{model}:generateContent; the Chat URL is https://bettertoken.ai/v1/chat/completions. Use the domain root as the Google SDK Base URL and specify the v1beta API version separately. Use the Base URL with /v1 for the OpenAI SDK.
For native Gemini multi-turn editing, preserve the complete model response and message order, including returned signature fields. Nano 2.1 multi-turn editing and compatibility with Google SDK editing have limitations. For step-by-step edits you can control, prefer the single-edit Images flow in this guide: upload the approved image each time and inspect the new result.
Gemini text-to-image guide · Gemini reference-image editing guide
Read actual image dimensions and charges after generation
First check the price for your account’s currency and image tier, then verify delivery against the response. n is the requested count; the number of items in the returned array is the actual delivery count. The endpoint accepts n=1–4, but may return fewer images than requested. This guide uses a single-image flow; if you need a fixed count, submit one at a time and record each result.
After a successful call to /v1/images/generations or /v1/images/edits, the image data and bettertoken_image_billing are returned together in the same JSON response. The latter is a BetterToken extension containing dimensions and settlement details. You can read it with your own API Key; no administrator permissions or separate billing query is required.
Save images from data[] and read actual pixels, billing tier, amount, and currency from bettertoken_image_billing to associate each asset with its actual cost. Use the settlement for your account as the source of truth.
| Field | Use in your application |
|---|---|
currency, settled_amount | Display the settlement currency and total amount for the request |
outputs[].width, outputs[].height | Check actual pixels to decide whether to scale, pad, or crop |
outputs[].billing_resolution | Check the actual billed tier |
outputs[].amount, outputs[].currency | Record the charge and currency for an individual image |
Amounts are returned as decimal strings. Use a decimal monetary type for aggregation and total each currency separately. If the billing extension is missing, mark the amount as pending verification; do not record it as free. Find current prices in the BetterToken model plaza.
Images is a synchronous API. After success, save the image to your own file or object storage before displaying it to the user. It does not return a task_id for later polling. If your application displays a waiting state, keep the request open on your own backend and save the result there.
Troubleshoot errors by changing the right thing
Start with error.message, error.code, and error.param in the response. Resending the same request will not resolve a parameter error.
| Symptom or error | What to do |
|---|---|
unsupported_parameter | Check error.param; remove unsupported fields such as quality, background, or mask |
conflicting_image_parameters | Check for conflicts between size and dimensions or ratio; do not mix image and image[] when editing |
unsupported_image_size | Use a supported size or image_size + aspect_ratio; custom sizes such as 2080x2080 are not accepted |
invalid_image_size / invalid_aspect_ratio | Use uppercase 1K/2K/4K and check the selected model’s ratio range |
unsupported_output_format / unsupported_response_format | Omit output_format and set response_format to b64_json |
missing_reference_image | Upload an actual image file to the editing endpoint; use generations if you only have text |
invalid_image_count / missing_prompt | Start with n=1 and provide a non-empty prompt |
401 | Check the BetterToken API Key, environment variable, and Bearer header |
no_eligible_image_service | No available service matches the model, specifications, or edit combination; keep request details and contact support |
| File cannot open after saving | Check that Base64 was decoded and choose .jpg or .png based on mime_type |
| Timeout or connection closed | Check call records and charges first, keep the request ID, then decide whether to resend |
A client timeout does not mean upstream generation was cancelled. Set compatible wait times for the SDK, reverse proxy, and application backend so the browser does not stop waiting first. If you cannot determine whether the previous request completed, do not retry automatically; it could generate and bill a duplicate.

















