Gemini Native Image Generation
/v1beta/models/{model}:generateContentUpdated
Download MarkdownNano Banana 2.1: choose a format, compare output, and check limits →
Model and response format
These are UnifyLLM compatibility rules for gemini-nano-banana-2.1-c. Use https://api.unifyllm.top with the endpoint paths shown below. Check the corresponding documentation for other image models.
- Native output uses candidates[].content.parts[].inlineData Base64. Thought parts and opaque signatures are preserved; skip thought=true parts when extracting the image.
- One upstream generation submission per request; paid POST requests are not automatically retried.
- Default reference limits are 14 images and 40 MB of original bytes combined; platform or account limits may be tighter. Supported PNG/JPEG/WebP images must be readable.
Resolution and aspect ratio
Dimensions select a resolution tier and composition; exact pixels are not promised. The public gateway test on 2026-11-27 requested 1920x1080 and received 2752×1536. The result is not resized or cropped.
| Input | Example | Mapped result |
|---|---|---|
| imageSize | 1K / 2K | Enabled tiers only; no 4K |
| aspectRatio | 1:1, 2:3, 3:2, 4:3, 3:4, 16:9, 9:16 | Must be enabled for the model |
Single-turn input and reference limits
- Only generateContent is supported, not streamGenerateContent. contents must contain one current user content; multi-turn state is not restored.
- URL references must be publicly accessible; private addresses are rejected. Replace example.com URLs and Base64 placeholders. Do not put API keys in image URLs.
- responseModalities must include IMAGE. inlineData/inline_data aliases are accepted; conflicting aliases are rejected.
- The default whole-request limit is 64 MB including Base64 and JSON overhead. The original-image limit is not the final encoded request size.
Usage, errors, and saving results
- usage / usageMetadata is returned only when provided upstream. Images use input_tokens/output_tokens; Chat uses prompt_tokens/completion_tokens. Missing usage is not a zero-cost statement.
- 400 usually means invalid parameters or model capabilities; 401 is authentication; 413 is request size; 429 is capacity or rate limiting. Upstream rejection, timeout, no valid image, or storage failure may return 500. Keep the request ID and error for diagnosis.
- Generation can take time. Chat stream=true starts only after successful generation and storage, without waiting-period progress. Read SSE through data: [DONE]; do not parse the entire stream as one JSON object.
- URLs are not permanent archives: cleanup or signature changes can invalidate them. Download promptly and preserve id, sig, and the original query string.
Path Parameters
model:requiredstringPublic model ID. The example uses gemini-nano-banana-2.1-c; availability depends on your key.
gemini-nano-banana-2.1-cRequest Body
application/jsoncontents:requiredarrayExactly one current user content; role may be omitted. Include non-empty text and optional reference images in parts. Multi-turn history is not supported.
contents[].parts[].inlineData:optionalobjectBase64 image with mimeType and raw Base64 data, without a data URL prefix. inline_data / mime_type are accepted.
contents[].parts[].fileData:optionalobjectA public HTTP(S) or image data URL in fileUri. Account-scoped Files API file_id is unsupported. file_data / file_uri are accepted.
generationConfig.responseModalities:optionalarrayDefaults to ["IMAGE"]. ["TEXT","IMAGE"] is allowed; IMAGE is required.
generationConfig.imageConfig.imageSize:optionalstringOnly model-enabled 1K and 2K are supported; default 1K. Explicit 4K is rejected.
1K2K1KgenerationConfig.imageConfig.aspectRatio:optionalstringSupported ratios are listed below. When omitted, text-to-image uses the default ratio; reference editing lets the upstream choose.
1:12:33:24:33:416:99:16generationConfig.candidateCount:optionalintegerForced to 1. Other supported native generationConfig properties are preserved. Do not send conflicting camelCase and snake_case objects.
systemInstruction / safetySettings:optionalobject / arrayNative fields are preserved; their effect depends on the model. They do not restore chat history.
Response
200A successful request returns a JSON response. The complete example is shown in the code panel.