This page covers Gemini through Google AI Studio API keys. For Gemini on
Google Cloud’s Vertex AI, see the Google Vertex AI guide.
By default, GoModel routes Gemini chat and Responses requests through Gemini’s
native generateContent API. Switch to the OpenAI-compatible endpoint when
you need compatibility behavior the native adapter does not implement yet
(notably remote image_url values).
GEMINI_API_KEY=...
GEMINI_API_MODE=native # or openai_compatible
Or in config.yaml:
providers:
gemini:
type: gemini
api_key: "${GEMINI_API_KEY}"
api_mode: native
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.
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. Embeddings, files, and batches always use the
OpenAI-compatible surface.
| 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