Deprecated, still works

This page describes a native (non-OpenAI) interface. It still works, but it is deprecated. New integrations should use the unified API.

The unified entry for text models is POST /v1/chat/completions; use GET /v1/models for the models that are available. The native protocol on this page has no unified interface of the same shape.

What the unified API offers for this: Open the API guide

Chat

Gemini Protocol

Google Gemini native generateContent protocol. Currently used by the Nano image models (images are returned synchronously); Gemini text chat models are not offered yet.

Authorization

AuthorizationstringheaderRequired
API key, sent as a Bearer token in the Authorization header.
Example:Bearer <API_KEY>
Image Generation

Image Generation (Nano · sync)NEW

Synchronous image generation on the native Gemini generateContent endpoint is available: pass an image model with generationConfig.responseModalities including "IMAGE", and a single request returns the base64 image directly — no taskId, no polling. The public "Nano tier" is backed by these Gemini image models. Two request formats are supported: default JSON (native Gemini protocol) and multipart/form-data upload (upload reference images directly via the image file field for image-to-image — see the example below).

Sync image generation
POST/ v1beta/ models/ {model}:generateContent

Supported Models

gemini-2.5-flash-image (Nano, 1K) / gemini-3-pro-image-preview (Nano Pro, 1K/2K/4K) / gemini-3.1-flash-image-preview (Nano 2, 1K/2K/4K).

Request body

application/json
{model}pathRequired
Model id in the URL path (tier mapping): gemini-2.5-flash-image (Nano, 1K) / gemini-3-pro-image-preview (Nano Pro, 1K/2K/4K) / gemini-3.1-flash-image-preview (Nano 2, 1K/2K/4K)
contentsarrayRequired
Native Gemini contents array; each item has role and parts[]. Text-to-image usually needs a single role="user" item.
contents[].rolestring
Role; use "user" for image generation
contents[].parts[].textstringRequired
Text prompt describing the image to generate
contents[].parts[].inlineDataobject
Reference image for image-to-image (inline base64): { "mimeType": "image/png", "data": "<base64>" }; omit for text-to-image. You can also pass a URL via fileData.fileUri below.
contents[].parts[].fileData.fileUristring
https URL of a reference image for image-to-image (alternative to inline base64); the server downloads and inlines it. https only, up to 4 reference images; if any download fails the whole request errors and is not charged.
generationConfigobjectRequired
Generation config object; see the sub-fields below
generationConfig.responseModalitiesstring[]Required
Output modalities; must include "IMAGE" for image output (e.g. ["TEXT","IMAGE"]); omitting it returns text only
generationConfig.candidateCountnumber
Number of images: 1-4, default 1. Charged per image (xN) and settled by the number of successful images (failures refunded)
generationConfig.imageConfig.imageSizestring
Resolution: 1K / 2K / 4K, default 1K (Nano is 1K only; Nano Pro / Nano 2 support 2K/4K)
generationConfig.imageConfig.aspectRatiostring
Output ratio: 1:1 / 16:9 / 9:16 / 4:3 / 3:4 / 3:2 / 2:3 / 5:4 / 4:5 / 21:9, default 1:1; follow the official Google imageConfig spec
Besides Authorization: Bearer <API_KEY>, x-goog-api-key is also accepted (your APIKey; either one, not both). Generating multiple images is charged per image (candidateCount) and settled by the number that succeed; a reference image can be inline base64 or an https URL via fileData.fileUri. multipart/form-data submission: fields prompt (required for text-to-image / edit instruction for image-to-image), image (reference file, repeatable up to 4), n (count, max 4, maps to candidateCount); model comes from the URL path only, image models + non-stream only, request body capped at 20MB (over → 413); request format (JSON / multipart) and response format (base64 / add ?respFormat=url for a CDN link) are orthogonal, and billing is identical to the JSON path.

💰 See the pricing page for prices →