Reference Image Input and Editing
API Calls in Multiple Languages
See language setup. Set API_KEY and replace model, file URL, and ID placeholders first. Each version displays the raw response to the same request.
These examples display the raw API response. Continue with this page or the image overview for Base64 decoding, download, and storage. Replace YOUR_IMAGE_BASE64 with the complete PNG Base64 without a Data URI prefix; the Python fragment below shows how to read a local file.
curl --fail-with-body --silent --show-error --max-time 180 \
--request POST \
--url "https://api.tokatlas.ai/v1beta/models/YOUR_ENABLED_GEMINI_IMAGE_MODEL_ID:generateContent" \
--header "x-goog-api-key: $API_KEY" \
--header "Content-Type: application/json" \
--data '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Change the background to pale gray. Preserve the product shape and logo."
},
{
"inlineData": {
"mimeType": "image/png",
"data": "YOUR_IMAGE_BASE64"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
]
}
}'import os
import requests
headers = {
'x-goog-api-key': os.environ["API_KEY"],
'Content-Type': 'application/json',
}
payload = {'contents': [{'role': 'user',
'parts': [{'text': 'Change the background to pale gray. Preserve the '
'product shape and logo.'},
{'inlineData': {'mimeType': 'image/png',
'data': 'YOUR_IMAGE_BASE64'}}]}],
'generationConfig': {'responseModalities': ['TEXT', 'IMAGE']}}
response = requests.request(
'POST', 'https://api.tokatlas.ai/v1beta/models/YOUR_ENABLED_GEMINI_IMAGE_MODEL_ID:generateContent', headers=headers,
json=payload,
timeout=180,
)
response.raise_for_status()
print(response.text)if (!process.env.API_KEY) throw new Error("Set API_KEY first.");
const response = await fetch("https://api.tokatlas.ai/v1beta/models/YOUR_ENABLED_GEMINI_IMAGE_MODEL_ID:generateContent", {
method: "POST",
headers: {
"x-goog-api-key": process.env.API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
"contents": [
{
"role": "user",
"parts": [
{
"text": "Change the background to pale gray. Preserve the product shape and logo."
},
{
"inlineData": {
"mimeType": "image/png",
"data": "YOUR_IMAGE_BASE64"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
]
}
}),
signal: AbortSignal.timeout(180_000),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(await response.text());import java.net.URI;
import java.net.http.*;
import java.time.Duration;
public class Example {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("API_KEY");
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalArgumentException("Set API_KEY first.");
}
String payload = String.join("\n",
"{",
" \"contents\": [",
" {",
" \"role\": \"user\",",
" \"parts\": [",
" {",
" \"text\": \"Change the background to pale gray. Preserve the product shape and logo.\"",
" },",
" {",
" \"inlineData\": {",
" \"mimeType\": \"image/png\",",
" \"data\": \"YOUR_IMAGE_BASE64\"",
" }",
" }",
" ]",
" }",
" ],",
" \"generationConfig\": {",
" \"responseModalities\": [",
" \"TEXT\",",
" \"IMAGE\"",
" ]",
" }",
"}"
);
HttpClient client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30)).build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.tokatlas.ai/v1beta/models/YOUR_ENABLED_GEMINI_IMAGE_MODEL_ID:generateContent"))
.timeout(Duration.ofSeconds(180))
.header("x-goog-api-key", apiKey)
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() >= 300) {
throw new IllegalStateException("HTTP " + response.statusCode() + ": "
+ response.body());
}
System.out.println(response.body());
}
}Use a Local Reference
- Run the text-to-image example in Nano Banana to check the route and key.
- Save an actual PNG as
reference.pngbesidenano_banana.py. - Replace the script's original
parts = ...assignment with the code below. Keep the rest of the script. - Run
python3 nano_banana.pyagain and inspect the saved image for the requested background change and preserved product details.
reference = Path("reference.png")
parts = [
{"text": "Change the background to pale gray. Preserve the product shape and logo."},
{"inlineData": {"mimeType": "image/png",
"data": base64.b64encode(reference.read_bytes()).decode("ascii")}},
]Multiple Images and Formats
Add another inlineData block for each reference and describe its role in the prompt. Use image/jpeg for JPEG and image/webp for WebP. Renaming a file does not convert its format. Follow the selected model's size/count limits and start with one small image.
For OCR, image questions, or document summaries, use Messages File Analysis; these tasks are separate from image generation.
Troubleshooting
For missing files, check the working directory. For encoding errors, check MIME and file bytes. For missing output images, inspect promptFeedback and model capabilities as described in Nano Banana. This native Gemini request uses inlineData, not the legacy image_urls field.
