Nano Banana text to image & sizes
For model IDs and choosing an endpoint, see the Nano Banana overview.
aspectRatio and the resolution by imageSize; both go in generationConfig.imageConfig.Text to image example
Python
import base64
from google import genai
from google.genai import types
client = genai.Client(
api_key="YOUR_OFOX_API_KEY",
http_options={"api_version": "v1beta", "base_url": "https://api.ofox.ai/gemini"},
)
resp = client.models.generate_content(
model="google/gemini-3.1-flash-image",
contents="A red apple on a white table",
config=types.GenerateContentConfig(
response_modalities=["IMAGE"],
image_config=types.ImageConfig(aspect_ratio="16:9", image_size="2K"),
),
)
for part in resp.candidates[0].content.parts:
if part.inline_data:
with open("output.png", "wb") as f:
f.write(part.inline_data.data)In the Python SDK, inline_data.data is binary and can be written straight to a file; cURL returns a base64 string that must be decoded first.
Values supported by each model
The 10 common aspect ratios: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9. A ratio not on the list (e.g. 5:3) returns 400 Request contains an invalid argument.
Writing the resolution: use uppercase 1K, 2K, 4K for imageSize, matching Google’s official docs; in our tests OfoxAI also accepts lowercase. The 512 tier has no K unit.
Without imageConfig: the model decides the aspect ratio. Pass it explicitly if you need a fixed ratio.
Measured output sizes
A 4K PNG is about 16 MB, so the base64-encoded response body exceeds 20 MB. Make sure your client, proxies and logging do not truncate large responses.
If you run into errors, see Troubleshooting errors.