> ## Documentation Index
> Fetch the complete documentation index at: https://gomodel-feat-http-socks5.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini

> Configure Google Gemini via AI Studio in GoModel, choose native or OpenAI-compatible routing, and understand image_url behavior.

This page covers Gemini through **Google AI Studio** API keys. For Gemini on
Google Cloud's Vertex AI, see the [Google Vertex AI guide](/providers/vertex).

By default, GoModel routes Gemini chat, Responses, embeddings, and
[image](/advanced/images-api) requests through Gemini's native APIs
(`generateContent`, `batchEmbedContents`, Imagen `predict`). Switch to the
OpenAI-compatible endpoint when you need compatibility behavior the native
adapter does not implement yet (notably remote `image_url` values).

## Configure

```bash theme={null}
GEMINI_API_KEY=...
GEMINI_API_MODE=native        # or openai_compatible
```

Or in `config.yaml`:

```yaml theme={null}
providers:
  gemini:
    type: gemini
    api_key: "${GEMINI_API_KEY}"
    api_mode: native
```

<Note>
  `USE_GOOGLE_GEMINI_NATIVE_API` is still honored as a legacy global toggle
  when per-provider `GEMINI_API_MODE` is unset. Prefer `GEMINI_API_MODE`.
</Note>

Native AI Studio mode can also materialize GoModel's post-routing prompt-cache
plans as five-minute Gemini cached-content objects. Reuse is scoped to the API
key selected for the session; sessionless traffic with rotating keys skips
object creation so a resource is never reused under the wrong credential.
Vertex currently receives the original request without cached-content objects.

## Base URLs

GoModel keeps separate internal bases for native Gemini and the
OpenAI-compatible API:

* native chat/models: `https://generativelanguage.googleapis.com/v1beta`
* OpenAI-compatible: `https://generativelanguage.googleapis.com/v1beta/openai`

`GEMINI_BASE_URL` overrides them. When the value ends in `/openai`, GoModel
uses it for the OpenAI-compatible client and derives the native base by
stripping `/openai`. Files and batches always use the OpenAI-compatible
surface; chat, embeddings, and images follow the API mode.

## Embeddings

In native mode, embeddings are served through `models/{model}:batchEmbedContents`.
`dimensions` maps to `outputDimensionality` and `encoding_format: "base64"` is
honored. Gemini reports no embedding token usage on either API surface, so
embedding responses carry zero token counts and the usage row is flagged with
a cost-calculation caveat.

## Image generation and edits

In native mode the [OpenAI-compatible image endpoints](/advanced/images-api)
work with Gemini image models (`gemini-2.5-flash-image`, ..., via
`generateContent`). Google retired Imagen from the AI Studio API in August
2026; Imagen is still served on [Vertex AI](/providers/vertex). Image edits
require native mode and a Gemini image model; masks are not supported. See the
[Images API provider notes](/advanced/images-api#google-gemini) for parameter
mapping and pricing details.

## Image input

| Mode                | OpenAI-style `image_url`                                                     |
| ------------------- | ---------------------------------------------------------------------------- |
| `native` (default)  | inline `data:` URLs only — remote `https://...` URLs are rejected            |
| `openai_compatible` | OpenAI-style remote URLs pass through to Google's OpenAI-compatible endpoint |

For URL-hosted images in native mode, Google's own examples fetch the URL
first and send the bytes to `generateContent`.

## Not yet integrated

* Automatic fetching of remote `image_url` values in native mode.
* Uploading remote images through the Gemini Files API before a chat request.

## References

* [Gemini image understanding](https://ai.google.dev/gemini-api/docs/image-understanding)
* [Gemini OpenAI compatibility](https://ai.google.dev/gemini-api/docs/openai)
