Generate and edit images via Gemini “Nano Banana” native image models over the REST API using curl (text-to-image, image editing, multi-turn image editing, high-res up to 4K, reference images, grounding, prompting guides, base64 decode workflows). Always write decoded images into ./nanobanana-output/.
Use this whenever the user asks to create, generate, make, draw, design, visualize, or edit any image/visual.
Nano Banana = Gemini’s native image generation models:
All generated images include a SynthID watermark.
export GEMINI_API_KEY="YOUR_KEY_HERE"
Base endpoint:
https://generativelanguage.googleapis.com/v1beta/models/<MODEL>:generateContentAll decoded images must be saved into:
./nanobanana-output/
Always ensure it exists before decoding:
mkdir -p ./nanobanana-output
response.json (REQUIRED)Gemini returns images as base64 in:
.candidates[0].content.parts[].inline_data.dataExample part:
{
"inline_data": {
"mime_type": "image/png",
"data": "BASE64..."
}
}
You must decode into real files inside ./nanobanana-output/.
mkdir -p ./nanobanana-output
jq -r '
.candidates[0].content.parts[]
| select(.inline_data != null)
| .inline_data.data
' response.json | head -n 1 | base64 -d > ./nanobanana-output/output.png
Verify:
file ./nanobanana-output/output.png
mkdir -p ./nanobanana-output
jq -r '
.candidates[0].content.parts[]
| select(.inline_data != null)
| .inline_data.data
' response.json \
| awk '{print NR ":" $0}' \
| while IFS=":" read -r idx b64; do
echo "$b64" | base64 -d > "./nanobanana-output/image_${idx}.png"
done
Outputs:
./nanobanana-output/image_1.png./nanobanana-output/image_2.pngCheck MIME type:
jq -r '
.candidates[0].content.parts[]
| select(.inline_data != null)
| .inline_data.mime_type
' response.json
If JPEG:
jq -r '
.candidates[0].content.parts[]
| select(.inline_data != null)
| .inline_data.data
' response.json | head -n 1 | base64 -d > ./nanobanana-output/output.jpg
Print any text parts:
jq -r '
.candidates[0].content.parts[]
| select(.text != null)
| .text
' response.json
Decode images as above into ./nanobanana-output/.
mkdir -p ./nanobanana-output
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [{"text": "A photorealistic nano banana dessert on a marble table"}]
}],
"generationConfig": {
"responseModalities": ["TEXT","IMAGE"]
}
}' \
| tee response.json \
| jq -r '.candidates[0].content.parts[] | select(.inline_data!=null) | .inline_data.data' \
| head -n 1 \
| base64 -d > ./nanobanana-output/output.png
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [{"text": "Create a nano banana dish in a futuristic restaurant"}]
}],
"generationConfig": {
"responseModalities": ["TEXT","IMAGE"],
"imageConfig": { "aspectRatio": "1:1" }
}
}' > response.json
Decode:
mkdir -p ./nanobanana-output
jq -r '.candidates[0].content.parts[] | select(.inline_data!=null) | .inline_data.data' \
response.json | base64 -d > ./nanobanana-output/generated.png
BASE64_IMG="$(base64 -w 0 < cat.jpg)"
curl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"contents\": [{
\"parts\": [
{\"text\": \"Add sunglasses to the cat. Keep lighting realistic.\"},
{\"inline_data\": {\"mime_type\": \"image/jpeg\", \"data\": \"$BASE64_IMG\"}}
]
}],
\"generationConfig\": {
\"responseModalities\": [\"TEXT\",\"IMAGE\"]
}
}" > response.json
Decode into output directory:
mkdir -p ./nanobanana-output
jq -r '.candidates[0].content.parts[] | select(.inline_data!=null) | .inline_data.data' \
response.json | base64 -d > ./nanobanana-output/edited.jpg
Always replay prior turns and decode intermediate outputs into:
./nanobanana-output/step1.png./nanobanana-output/step2.pngcurl -s -X POST \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "A premium hero shot of a smart speaker on white background"}]
}],
"generationConfig": {
"responseModalities": ["TEXT","IMAGE"],
"imageConfig": {
"aspectRatio": "16:9",
"imageSize": "4K"
}
}
}' > response.json
Decode:
mkdir -p ./nanobanana-output
jq -r '.candidates[0].content.parts[] | select(.inline_data!=null) | .inline_data.data' \
response.json | base64 -d > ./nanobanana-output/hero_4k.png
List newest outputs:
ls -lt ./nanobanana-output | head
responseModalities.jq -r raw output..inline_data.mime_type.Generate or edit images via Gemini 3 Pro Image (Nano Banana Pro).
Batch-generate images via OpenAI Images API. Random prompt sampler + `index.html` gallery.
Generate spectrograms and feature-panel visualizations from audio with the songsee CLI.
Extract frames or short clips from videos using ffmpeg.
Search GIF providers with CLI/TUI, download results, and extract stills/sheets.
Category:media-generate