Skip to main content
POST
Gemini text-to-image API
Generate an image from a text description with Nano Banana Pro, 2, or 2.1. POST /v1beta/models/{model}:generateContent Text-to-image and image editing use the same endpoint. Image editing adds a reference image to the request.

Try a request

Enter your BetterToken API Key in x-goog-api-key, select model, and edit the text in contents. Start with 1K and 1:1, then click Send.
Clicking Send makes a real generation request and may incur charges. Wait for the synchronous response. After a timeout or disconnection, check usage records and the request result before sending it again.
All three offer 1K, 2K, and 4K. Nano Banana 2 and 2.1 support 14 aspect ratios; Pro supports 10. X-BetterToken-Max-Images is a delivery and billing cap, not a guaranteed image count. Aspect ratios
BetterToken API does not support search-assisted image generation, including Google Web Search and Image Search grounding. Do not add search tools.
Text-to-image requires only a text description; no reference image is needed. Use non-streaming generateContent. Files, Batch, Interactions, and streaming are not supported.

Read the response

Images are returned in candidates[].content.parts[].inlineData. Iterate over the parts, skip thought: true, decode data, and choose the file extension from mimeType. Do not assume the image is always the first part or always PNG.

Authorizations

x-goog-api-key
string
header
required

BetterToken API Key.

Headers

X-BetterToken-Max-Images
integer
default:1

Maximum number of returned and billable images, not a guaranteed count. Defaults to 1.

Required range: 1 <= x <= 4

Path Parameters

model
enum<string>
default:nano-banana-2.1
required

BetterToken Model ID. Choose one of the three Nano Banana models.

Available options:
nano-banana-pro,
nano-banana-2,
nano-banana-2.1

Body

application/json
contents
object[]
required

Conversation contents. Keep the complete model content and thoughtSignature for follow-up edits.

Minimum array length: 1
generationConfig
object

Image generation settings.

Response

Generation response. Inspect final image parts and finishReason.

candidates
object[]
promptFeedback
object
usageMetadata
object