Gemini 3.1 Flash Image

Gemini 3.1 Flash Image (NanoBanana 2) via Vertex AI - Advanced image generation model powered by Google Cloud

maker
google
category
image
input → output
text → image
runs via
api, javascript and python sdk, belt cli, mcp
updated
2026-05-29
price
$0.045–$0.151/image (0.5K–4K), +$0.50/M input tokens, +$0.014/query Google Search

api reference

about

gemini 3.1 flash image (nanobanana 2) via vertex ai - advanced image generation model powered by google cloud

get an api key

create one in settings → api keys. the examples read it from INFERENCE_API_KEY.

bash
1export INFERENCE_API_KEY="inf_your_key"

1. calling the api

install the client

nothing to install. any http client works; the examples use curl, and jq to read responses. every response wraps its result in a data field.

run and get result

send "wait": true to hold the connection until the task finishes. without it the call returns right away with the task still running.

bash
12# "wait": true holds the connection until the task finishes.3# the response is {"data": {"id", "status", "status_text", "output", ...}}4curl -X POST https://api.inference.sh/apps/run \5  -H "Authorization: Bearer $INFERENCE_API_KEY" \6  -H "Content-Type: application/json" \7  -d '{8    "app": "google/gemini-3-1-flash-image",9    "input": {10      "prompt": "prompt"11    },12    "wait": true13  }'

stream live updates

get real-time progress updates as the task runs. ideal for showing progress bars, partial results, or long-running tasks. send "stream": true and the response is a server-sent event stream that ends when the task does.

bash
12# "stream": true answers with server-sent events until the task finishes3curl -N -X POST https://api.inference.sh/apps/run \4  -H "Authorization: Bearer $INFERENCE_API_KEY" \5  -H "Content-Type: application/json" \6  -d '{7    "app": "google/gemini-3-1-flash-image",8    "input": {9      "prompt": "prompt"10    },11    "stream": true12  }'

run in the background

start the task and get its id back right away, then check on it later. for long tasks, or when you'd rather be called back, see webhooks.

bash
1# without "wait" the call returns the task right away (status 1, "received")2TASK_ID=$(curl -s -X POST https://api.inference.sh/apps/run \3  -H "Authorization: Bearer $INFERENCE_API_KEY" \4  -H "Content-Type: application/json" \5  -d '{6    "app": "google/gemini-3-1-flash-image",7    "input": {8      "prompt": "prompt"9    }10  }' | jq -r '.data.id')1112# later: read its state. done when status is 10 (completed), 11 (failed) or 12 (cancelled)13curl -s https://api.inference.sh/tasks/$TASK_ID \14  -H "Authorization: Bearer $INFERENCE_API_KEY" | jq '.data | {status, status_text, output}'

2. authentication

the api uses api keys for authentication. see the authentication docs for detailed setup instructions.

3. files

file inputs are automatically handled by the sdk. you can pass local paths, urls, or base64 data.

automatic upload

pass urls directly or use data uris for inline content.

bash
1# pass URLs or data URIs as input values2curl -X POST https://api.inference.sh/apps/run \3  -H "Authorization: Bearer $INFERENCE_API_KEY" \4  -H "Content-Type: application/json" \5  -d '{6    "app": "google/gemini-3-1-flash-image",7    "input": {8      "image": "https://example.com/image.png",9      "audio": "data:audio/mp3;base64,..."10    },11    "wait": true12  }'

manual upload

you can also upload files manually and use the returned url.

bash
1# 1. create the file: the response has an upload_url and the file's uri2FILE=$(curl -s -X POST https://api.inference.sh/files \3  -H "Authorization: Bearer $INFERENCE_API_KEY" \4  -H "Content-Type: application/json" \5  -d '{"files": [{"filename": "image.png", "content_type": "image/png"}]}')67# 2. PUT the bytes to upload_url8curl -X PUT "$(echo "$FILE" | jq -r '.data[0].upload_url')" \9  -H "Content-Type: image/png" \10  --data-binary @image.png1112# 3. pass the uri as an input value13echo "$FILE" | jq -r '.data[0].uri'

4. webhooks

get notified when a task completes by providing a webhook url. when the task reaches a terminal state (completed, failed, or cancelled), a POST request is sent to your url with the task result.

bash
1curl -X POST https://api.inference.sh/apps/run \2  -H "Authorization: Bearer $INFERENCE_API_KEY" \3  -H "Content-Type: application/json" \4  -d '{5    "app": "google/gemini-3-1-flash-image",6    "input": {7        "prompt": "prompt"8    },9    "webhook": "https://your-server.com/webhook"10  }'

webhook payload

your endpoint receives a JSON POST with the task result:

json
1{2  "event": "task.completed",3  "timestamp": "2024-01-15T10:30:05Z",4  "data": {5    "id": "task_abc123",6    "short_id": "abc123",7    "status": 10,8    "status_text": "completed",9    "output": { ... },10    "created_at": "2024-01-15T10:30:00Z",11    "updated_at": "2024-01-15T10:30:05Z"12  }13}
eventstringtask.completed, task.failed or task.cancelled
timestampstringiso timestamp of the delivery
data.idstringtask id
data.short_idstringshort task id
data.statusnumberterminal status (10=completed, 11=failed, 12=cancelled, 13=rejected)
data.status_textstringthe status as a word: completed, failed or cancelled
data.outputobjecttask output (when completed)
data.errorstringerror message (when failed, omitted otherwise)
data.session_idstringsession id (when the task ran in a session, omitted otherwise)
data.created_atstringiso timestamp
data.updated_atstringiso timestamp

5. schema

input

promptstring*

the prompt for image generation or editing. describe what you want to create or change.

imagesarray

optional list of input images for editing (up to 14 images). when provided, the model will edit these images based on the prompt. when not provided, the model will generate new images from the text prompt. supported formats: jpeg, png, webp

num_imagesinteger

number of images to generate.

default: 1min:1max:4
aspect_ratiostring

aspect ratio for the output image. supports extreme ratios like 1:4, 4:1, 1:8, 8:1. use 'auto' to automatically match the first input image's aspect ratio. default: 1:1

default: "1:1"
options:"auto""21:9""16:9""8:1""4:1""3:2""4:3""5:4""1:1""4:5""3:4""2:3""1:4""1:8""9:16"
resolutionstring

output resolution. options: 1k, 2k, 4k. default: 1k

default: "1K"
options:"512""1K""2K""4K"
output_formatstring

output format for the generated images.

default: "png"
options:"png""jpeg""webp"
enable_google_searchboolean

enable google search grounding for real-time information (weather, news, etc.)

default: false
safety_tolerancestring

safety filter threshold. options: block_none, block_low_and_above, block_medium_and_above, block_only_high

default: "BLOCK_NONE"
options:"BLOCK_NONE""BLOCK_LOW_AND_ABOVE""BLOCK_MEDIUM_AND_ABOVE""BLOCK_ONLY_HIGH"
retry_countinteger

number of automatic retries on 429 rate limit errors using exponential backoff with jitter. set to 0 to disable retries. example: retry_count=2 means up to 3 total attempts (1 initial + 2 retries).

default: 2min:0max:5

output

descriptionstring

text description or response from the model

imagesarray*

the generated or edited images

ready to run Gemini 3.1 Flash Image?

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.