Docs / Model List / Nano Banana Pro Image model · Google
Nano Banana Pro API Nano Banana Pro is Google's Gemini 3 Pro Image model, served on TokenRa under the ID gemini-3-pro-image-preview. One chat message generates or edits an image, and the Gemini generateContent format works too. Requests are synchronous: each test returned a JPEG in 36–84 seconds.
Model ID gemini-3-pro-image-preview
Input Text, image (edits)
Output JPEG, 1K to 4K
Billing Per request Capabilities
Capabilities & endpoints Both endpoints were called successfully on 2026-11-22, and the OpenAI SDKs work with base_url=https://tokenra.io/v1. The image endpoints /v1/images/generations and /v1/images/edits do not serve this model.
Generate Edit Gemini format
POST https://tokenra.io/v1/chat/completions Tested
OpenAI Chat Completions. A text prompt generates an image; a text part plus an image_url part edits one. The image comes back in choices[0].message.content.
POST https://tokenra.io/v1beta/models/gemini-3-pro-image-preview:generateContent Tested
Google Gemini format. Set the aspect ratio and size in generationConfig.imageConfig; the image comes back as inlineData.
Request
Request parameters Chat Completions: POST /v1/chat/completions Parameter Type Required Description modelstring Yes Model ID: gemini-3-pro-image-preview. messagesarray Yes One user message. To generate, its content is the prompt. To edit, its content is an array with a text part and an image_url part whose url is a base64 data URL (tested with a JPEG). extra_body.google.image_config.aspect_ratiostring No Output aspect ratio, such as 1:1, 16:9 or 9:16. Without it the model chooses: the tests returned 1376×768 and 1408×768. extra_body.google.image_config.image_sizestring No 1K (default), 2K or 4K. 4K with 1:1 returned 4096×4096.
Write the image_config keys in snake_case: aspectRatio or imageSize there is rejected with HTTP 500 convert_request_failed. With the OpenAI Python SDK, pass extra_body={"extra_body": {"google": …}}: the SDK merges its extra_body argument into the JSON body, and the gateway reads the extra_body field from there.
Gemini format: POST /v1beta/models/gemini-3-pro-image-preview:generateContent Parameter Type Required Description contentsarray Yes The prompt: [{"role": "user", "parts": [{"text": "…"}]}]. generationConfig.responseModalitiesarray No ["IMAGE"] returns the image only (tested).generationConfig.imageConfig.aspectRatiostring No Aspect ratio, same values as above. 16:9 was tested. generationConfig.imageConfig.imageSizestring No 1K, 2K or 4K. 2K with 16:9 returned 2752×1536.
Response
Response format Chat Completions {
"id": "chatcmpl-202611220420419771128118268d9d6pZBYtojk",
"object": "chat.completion",
"created": 1795321277,
"model": "gemini-3-pro-image-preview",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": ""
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 1250,
"total_tokens": 1268,
"completion_tokens_details": {"image_tokens": 1120, "reasoning_tokens": 130}
}
}Field Type Description choices[].message.contentstring A Markdown image: . Decode the part after base64, to get the JPEG. usage.completion_tokens_details.image_tokensinteger Image tokens reported by the model: 1120 for 1K and 2K, 2000 for 4K in testing. Billing is per request, not per token. usage.completion_tokens_details.reasoning_tokensinteger The model plans before drawing (109–191 tokens in testing); no reasoning text is returned.
Gemini format {
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"inlineData": {"mimeType": "image/jpeg", "data": "/9j/4AAQSkZJRgABAQEBLAEs..."},
"thoughtSignature": "+ohstAcrEvsgQfXmYQz0ZPIp..."
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 14,
"candidatesTokenCount": 1120,
"thoughtsTokenCount": 43,
"totalTokenCount": 1177
},
"modelVersion": "gemini-3-pro-image-preview"
}Field Type Description candidates[].content.parts[].inlineData.datastring Base64 JPEG. Decode and save it. candidates[].content.parts[].inlineData.mimeTypestring image/jpeg in every test.usageMetadataobject Token counts reported by the model.
Errors
Errors & limits Common errors HTTP error.code Meaning What to do 401— Missing, wrong or deleted API key. The message is Invalid token. Check the Authorization: Bearer header and the key in the console. 400— The body is not valid JSON. Fix the JSON and send Content-Type: application/json. 500invalid_requestA required field is missing, for example messages. Add the field named in the message. Retrying will not help. 403insufficient_user_quotaYour balance or plan quota is used up. Top up in the console, then retry. 503model_not_foundUnknown model ID, or no channel serves it for your group. Check the ID in the model list or with GET /v1/models. 429— Too many requests. Back off exponentially and retry. 5xx— The upstream provider failed or timed out. Retry a few times; keep the request id if it persists.
Limits and notes Each request took 36–84 seconds in testing; 2K and 4K were the slowest. Set the client timeout to at least 180 seconds. Output is JPEG and the size depends on the resolution and on how detailed the picture is: 0.1–0.4 MB without image_size, 1.6–4.3 MB at 2K and 3.4–12.9 MB at 4K (4096×4096) in testing. Base64 adds a third, so a 4K response can exceed 17 MB of JSON. An edit request carries the source image as base64 too: a 2K source made a 4.4 MB request. Billing is per request at the same rate for 1K, 2K and 4K output and for edits. Failed requests were not charged. See the live rate in the Model Square. /v1/images/generations and /v1/images/edits return HTTP 500 convert_request_failed ("only imagen models are supported") for this model. Use one of the two endpoints above.Generate Edit Gemini format
cURL Python JavaScript Java
curl https://tokenra.io/v1/chat/completions \
-H "Authorization: Bearer $TOKENRA_API_KEY" \
-H "Content-Type: application/json" \
-o response.json \
-d '{
"model": "gemini-3-pro-image-preview",
"messages": [
{"role": "user", "content": "A watercolor fox reading a book under a desk lamp"}
],
"extra_body": {
"google": {"image_config": {"aspect_ratio": "1:1", "image_size": "2K"}}
}
}'
# The image is a base64 data URL inside choices[0].message.contentimport base64
import os
import re
from openai import OpenAI
client = OpenAI(api_key=os.environ["TOKENRA_API_KEY"], base_url="https://tokenra.io/v1")
resp = client.chat.completions.create(
model="gemini-3-pro-image-preview",
messages=[{"role": "user", "content": "A watercolor fox reading a book under a desk lamp"}],
extra_body={"extra_body": {"google": {"image_config": {"aspect_ratio": "1:1", "image_size": "2K"}}}},
)
match = re.search(r"data:image/[\w.+-]+;base64,([A-Za-z0-9+/=]+)", resp.choices[0].message.content)
with open("image.jpg", "wb") as f:
f.write(base64.b64decode(match.group(1)))
print("saved image.jpg")import { writeFile } from "node:fs/promises";
const resp = await fetch("https://tokenra.io/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TOKENRA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gemini-3-pro-image-preview",
messages: [{ role: "user", content: "A watercolor fox reading a book under a desk lamp" }],
extra_body: { google: { image_config: { aspect_ratio: "1:1", image_size: "2K" } } },
}),
});
const data = await resp.json();
const match = data.choices[0].message.content.match(/data:image\/[\w.+-]+;base64,([A-Za-z0-9+\/=]+)/);
await writeFile("image.jpg", Buffer.from(match[1], "base64"));
console.log("saved image.jpg");import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NanoBananaPro {
public static void main(String[] args) throws Exception {
String body = """
{"model": "gemini-3-pro-image-preview",
"messages": [{"role": "user", "content": "A watercolor fox reading a book under a desk lamp"}],
"extra_body": {"google": {"image_config": {"aspect_ratio": "1:1", "image_size": "2K"}}}}
""";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://tokenra.io/v1/chat/completions"))
.header("Authorization", "Bearer " + System.getenv("TOKENRA_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
String json = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()).body();
Matcher m = Pattern.compile("data:image/[\\w.+-]+;base64,([A-Za-z0-9+/=]+)").matcher(json);
if (!m.find()) throw new RuntimeException(json);
Files.write(Path.of("image.jpg"), Base64.getDecoder().decode(m.group(1)));
System.out.println("saved image.jpg");
}
}IMG=$(base64 < image.jpg | tr -d '\n')
curl https://tokenra.io/v1/chat/completions \
-H "Authorization: Bearer $TOKENRA_API_KEY" \
-H "Content-Type: application/json" \
-o edited.json \
-d @- <<EOF
{
"model": "gemini-3-pro-image-preview",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "Make the lamp light warmer"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,$IMG"}}
]
}]
}
EOFimport base64
import os
import re
from openai import OpenAI
client = OpenAI(api_key=os.environ["TOKENRA_API_KEY"], base_url="https://tokenra.io/v1")
with open("image.jpg", "rb") as f:
source = "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()
resp = client.chat.completions.create(
model="gemini-3-pro-image-preview",
messages=[{"role": "user", "content": [
{"type": "text", "text": "Make the lamp light warmer"},
{"type": "image_url", "image_url": {"url": source}},
]}],
)
match = re.search(r"data:image/[\w.+-]+;base64,([A-Za-z0-9+/=]+)", resp.choices[0].message.content)
with open("edited.jpg", "wb") as f:
f.write(base64.b64decode(match.group(1)))
print("saved edited.jpg")import { readFile, writeFile } from "node:fs/promises";
const source = "data:image/jpeg;base64," + (await readFile("image.jpg")).toString("base64");
const resp = await fetch("https://tokenra.io/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TOKENRA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gemini-3-pro-image-preview",
messages: [{
role: "user",
content: [
{ type: "text", text: "Make the lamp light warmer" },
{ type: "image_url", image_url: { url: source } },
],
}],
}),
});
const data = await resp.json();
const match = data.choices[0].message.content.match(/data:image\/[\w.+-]+;base64,([A-Za-z0-9+\/=]+)/);
await writeFile("edited.jpg", Buffer.from(match[1], "base64"));
console.log("saved edited.jpg");import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NanoBananaProEdit {
public static void main(String[] args) throws Exception {
String source = Base64.getEncoder().encodeToString(Files.readAllBytes(Path.of("image.jpg")));
String body = """
{"model": "gemini-3-pro-image-preview",
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Make the lamp light warmer"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,%s"}}]}]}
""".formatted(source);
HttpRequest request = HttpRequest.newBuilder(URI.create("https://tokenra.io/v1/chat/completions"))
.header("Authorization", "Bearer " + System.getenv("TOKENRA_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
String json = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()).body();
Matcher m = Pattern.compile("data:image/[\\w.+-]+;base64,([A-Za-z0-9+/=]+)").matcher(json);
if (!m.find()) throw new RuntimeException(json);
Files.write(Path.of("edited.jpg"), Base64.getDecoder().decode(m.group(1)));
System.out.println("saved edited.jpg");
}
}curl "https://tokenra.io/v1beta/models/gemini-3-pro-image-preview:generateContent" \
-H "Authorization: Bearer $TOKENRA_API_KEY" \
-H "Content-Type: application/json" \
-o response.json \
-d '{
"contents": [{"role": "user", "parts": [{"text": "A watercolor fox reading a book under a desk lamp"}]}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"}
}
}'
# The image is base64 in candidates[0].content.parts[].inlineData.dataimport base64
import os
import requests
resp = requests.post(
"https://tokenra.io/v1beta/models/gemini-3-pro-image-preview:generateContent",
headers={"Authorization": f"Bearer {os.environ['TOKENRA_API_KEY']}"},
json={
"contents": [{"role": "user", "parts": [{"text": "A watercolor fox reading a book under a desk lamp"}]}],
"generationConfig": {"responseModalities": ["IMAGE"], "imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"}},
},
timeout=300,
)
parts = resp.json()["candidates"][0]["content"]["parts"]
image = next(part["inlineData"] for part in parts if "inlineData" in part)
with open("image.jpg", "wb") as f:
f.write(base64.b64decode(image["data"]))
print("saved image.jpg")import { writeFile } from "node:fs/promises";
const resp = await fetch("https://tokenra.io/v1beta/models/gemini-3-pro-image-preview:generateContent", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.TOKENRA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
contents: [{ role: "user", parts: [{ text: "A watercolor fox reading a book under a desk lamp" }] }],
generationConfig: { responseModalities: ["IMAGE"], imageConfig: { aspectRatio: "16:9", imageSize: "2K" } },
}),
});
const data = await resp.json();
const image = data.candidates[0].content.parts.find((part) => part.inlineData).inlineData;
await writeFile("image.jpg", Buffer.from(image.data, "base64"));
console.log("saved image.jpg");import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NanoBananaProGemini {
public static void main(String[] args) throws Exception {
String body = """
{"contents": [{"role": "user", "parts": [{"text": "A watercolor fox reading a book under a desk lamp"}]}],
"generationConfig": {"responseModalities": ["IMAGE"],
"imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"}}}
""";
HttpRequest request = HttpRequest.newBuilder(
URI.create("https://tokenra.io/v1beta/models/gemini-3-pro-image-preview:generateContent"))
.header("Authorization", "Bearer " + System.getenv("TOKENRA_API_KEY"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
String json = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()).body();
Matcher m = Pattern.compile("\"data\"\\s*:\\s*\"([A-Za-z0-9+/=]+)\"").matcher(json);
if (!m.find()) throw new RuntimeException(json);
Files.write(Path.of("image.jpg"), Base64.getDecoder().decode(m.group(1)));
System.out.println("saved image.jpg");
}
}Set TOKENRA_API_KEY first. Python: pip install openai (Gemini format: pip install requests). JavaScript: save as .mjs and run with Node.js 18+. Java: JDK 17+, run java ClassName.java.