Skip to main content

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.
No code changes needed — if you already use @google/genai or call Gemini’s REST API, simply point your SDK to https://api.mountsea.ai/gemini with your Mountsea API key.

Why Use Compat API?

Official SDK Support

Works with Google’s official @google/genai (TypeScript) and google-genai (Python) libraries

Same API Shape

Uses the same generateContent / streamGenerateContent endpoints and request/response schema

Unified 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 apiKey parameter

Image Model Mapping

When calling Compat API with an image model name, it’s automatically routed to the corresponding Nano Banana model:
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

Where:
  • {model} — model ID (e.g. gemini-2.5-flash, gemini-3-pro-image-preview)
  • {action}generateContent (JSON response) or streamGenerateContent (SSE stream)

Text Generation

Image Generation

Image Editing

Include an image as inline_data in the parts array:

Streaming

Change generateContent 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:
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:9
  • gemini-3-pro-image-preview (→ NanoBananaPro): all standard ratios
  • gemini-3.1-flash-image-preview (→ NanoBanana2): all standard ratios + 1:4, 4:1, 1:8, 8:1

Notes & Limitations

Currently the Compat endpoint returns 1 image per request. The candidateCount field is accepted for compatibility but has no effect — it’s treated as 1.
  • For image generation, always include responseModalities: ["image"] (or ["image", "text"]) in generationConfig.
  • The inline_data.data field should be raw base64 (no data:*;base64, prefix).
  • Both inline_data (snake_case) and inlineData (camelCase) are accepted.

Available Endpoint

Explore the API Documentation