Gemini Compat API
The Gemini Compat API is a drop-in replacement for Google’s official Gemini API. It’s fully compatible with Google’s official @google/genai SDK and the Gemini REST interface — just change the base URL and API key, and everything works out of the box.Why Use Compat API?
Official SDK Support
Works with Google’s official
@google/genai (TypeScript) and google-genai (Python) librariesSame API Shape
Uses the same
generateContent / streamGenerateContent endpoints and request/response schemaUnified Billing
Single API key, unified usage tracking and billing through Mountsea
Image Generation
Supports image generation via
gemini-*-image models (auto-routed to Nano Banana)Configuration
Base URL
Authentication
Use your Mountsea API key (Bearer token). It can be passed as either:- HTTP header:
Authorization: Bearer your-api-key - Or via the official SDK’s
apiKeyparameter
Image Model Mapping
When calling Compat API with an image model name, it’s automatically routed to the corresponding Nano Banana model:| Gemini Model ID (input) | Routed to (Nano Banana) |
|---|---|
gemini-2.5-flash-image | NanoBananaFast |
gemini-3.1-flash-image-preview | NanoBanana2 |
gemini-3-pro-image-preview | NanoBananaPro |
You can use either the Gemini model IDs above or the native Nano Banana model IDs (
nano-banana-fast, nano-banana-2, nano-banana-pro) — both work.Using the Official @google/genai SDK
Installation
TypeScript / JavaScript
Python
Using the Gemini REST API
If you don’t want to use the SDK, you can call the endpoint directly. It’s identical in shape to Google’s official REST API.Endpoint
{model}— model ID (e.g.gemini-2.5-flash,gemini-3-pro-image-preview){action}—generateContent(JSON response) orstreamGenerateContent(SSE stream)
Text Generation
Image Generation
Image Editing
Include an image asinline_data in the parts array:
Streaming
ChangegenerateContent to streamGenerateContent to receive a Server-Sent Events (SSE) stream:
Image Generation Config
When requesting image generation (response_modalities includes image), you can configure the output:
| Field | Location | Description | Example |
|---|---|---|---|
aspectRatio / aspect_ratio | generationConfig.imageConfig | Aspect ratio | "1:1", "16:9", "9:16" |
imageSize / image_size | generationConfig.imageConfig | Resolution | "1K", "2K", "4K" |
Both camelCase (
aspectRatio, imageSize) and snake_case (aspect_ratio, image_size) are accepted. These fields can also be placed directly on generationConfig as shortcuts.Supported Aspect Ratios (by Model)
gemini-2.5-flash-image(→ NanoBananaFast):1:1,4:3,3:2,2:3,5:4,4:5,3:4,16:9,9:16,21:9gemini-3-pro-image-preview(→ NanoBananaPro): all standard ratiosgemini-3.1-flash-image-preview(→ NanoBanana2): all standard ratios +1:4,4:1,1:8,8:1
Notes & Limitations
- For image generation, always include
responseModalities: ["image"](or["image", "text"]) ingenerationConfig. - The
inline_data.datafield should be raw base64 (nodata:*;base64,prefix). - Both
inline_data(snake_case) andinlineData(camelCase) are accepted.
Available Endpoint
| Endpoint | Method | Description |
|---|---|---|
/gemini/v1beta/models/{modelAction} | POST | Gemini-compatible generateContent / streamGenerateContent |
Explore the API Documentation
- Compat generateContent — Full API reference for the compat endpoint