Gemini Native Image Generation

POST/v1beta/models/{model}:generateContent
Use gemini-nano-banana-2.1-c with single-turn generateContent. Returns native Base64 images with 1K/2K resolution tiers.

Updated

Download Markdown

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.

InputExampleMapped result
imageSize1K / 2KEnabled tiers only; no 4K
aspectRatio1:1, 2:3, 3:2, 4:3, 3:4, 16:9, 9:16Must 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:requiredstring

Public model ID. The example uses gemini-nano-banana-2.1-c; availability depends on your key.

Examplegemini-nano-banana-2.1-c

Request Body

application/json
contents:requiredarray

Exactly 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:optionalobject

Base64 image with mimeType and raw Base64 data, without a data URL prefix. inline_data / mime_type are accepted.

contents[].parts[].fileData:optionalobject

A 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:optionalarray

Defaults to ["IMAGE"]. ["TEXT","IMAGE"] is allowed; IMAGE is required.

generationConfig.imageConfig.imageSize:optionalstring

Only model-enabled 1K and 2K are supported; default 1K. Explicit 4K is rejected.

Allowed1K2K
Example1K
generationConfig.imageConfig.aspectRatio:optionalstring

Supported ratios are listed below. When omitted, text-to-image uses the default ratio; reference editing lets the upstream choose.

Allowed1:12:33:24:33:416:99:16
generationConfig.candidateCount:optionalinteger

Forced to 1. Other supported native generationConfig properties are preserved. Do not send conflicting camelCase and snake_case objects.

systemInstruction / safetySettings:optionalobject / array

Native fields are preserved; their effect depends on the model. They do not restore chat history.

Response

200

A successful request returns a JSON response. The complete example is shown in the code panel.

Related endpoints