Setup guide - From Gemini and OpenCode docs
Use Gemini in OpenCode
OpenCode's documented Custom provider mechanism (@ai-sdk/openai-compatible, for /v1/chat/completions) pointed at Google's documented Gemini OpenAI-compatible base URL and a current Gemini model id.
Last verified 4 steps4 official sources
Steps
- Step 1.
Get a Gemini API key from Google AI Studio (https://aistudio.google.com/apikey).
- Step 2.
In OpenCode, run the /connect command, scroll down to Other, enter a unique provider ID, then enter your API key (OpenCode docs, Custom provider steps 1-3).
Terminal$ /connect ┌ Add credential │ ◆ Select provider │ ... │ ● Other └ - Step 3.
Create or update opencode.json in your project directory. OpenCode documents this shape; the baseURL and model id below are Google's documented OpenAI-compatible endpoint and model id substituted into it (provider ID 'gemini-openai' is an arbitrary example and must match the ID you entered in /connect).
JSON{ "$schema": "https://opencode.ai/config.json", "provider": { "gemini-openai": { "npm": "@ai-sdk/openai-compatible", "name": "Google Gemini", "options": { "baseURL": "https://generativelanguage.googleapis.com/v1beta/openai/" }, "models": { "gemini-3.8-flash": { "name": "Gemini 3.8 Flash" } } } } } - Step 4.
Run the /models command; the custom provider and models appear in the selection list. To make it the default, set model to provider_id/model_id (OpenCode docs: 'the provider_id is key from the provider part of your config, and the model_id is the key from provider.models').
JSON{ "$schema": "https://opencode.ai/config.json", "model": "gemini-openai/gemini-3.8-flash" }
Caveats
- Combined path: OpenCode documents the custom OpenAI-compatible provider mechanism; Google documents the base URL and model ids. Neither page shows this exact combination.
- OpenCode also lists Google among its built-in providers (via Models.dev and the /connect list, and a 'Google' entry under built-in variants: low/high), but the providers page has no dedicated Google Gemini API section with steps, so the built-in route is not given here.
- Google states 'Support for the OpenAI libraries is still in beta while we extend feature support.'
- OpenCode docs: use @ai-sdk/openai-compatible for /v1/chat/completions; Google documents chat completions on its compatibility layer, not /v1/responses.
More setup guides
Same tool, other providers
Related reading
- Headless AI Coding Agents in CI: Claude Code, Codex CLI, Gemini CLI, and opencode ComparedHeadless AI coding agents in CI compared: Claude Code, Codex CLI, Gemini CLI, and opencode on invocation flags, sandboxing, auth, and output formats.
- Do Your Agent Hooks Fail Open? Claude Code vs Codex vs Cursor vs Gemini CLIA guard hook that crashes, times out or points at a missing script lets the tool call through by default in Claude Code. v2.1.295 adds onFailure: block. Here is what each coding agent does when your policy hook breaks, with real test runs.
- Google AI Pro vs Gemini API: What Developers Actually GetGoogle AI Pro costs $19.99 a month and has no API key, but includes $10 of monthly Cloud credits. When the subscription wins and when to pay per token.
- How to Keep API Keys Away From Your AI Coding Agent: Claude Code vs Codex vs Cursor vs Gemini CLIA deny rule on .env stops cat but not a Python one-liner. Here are the three layers that actually keep secrets out of a coding agent's context - file rules, environment scrubbing and credential masking - and what Claude Code, Codex, Cursor and Gemini CLI give you for each, with real test runs.
- Google Gemini Agent: Coworker Agents With Their Own EmailGoogle's Gemini agent can create coworker agents with their own Workspace account, email and audit trail. What Google announced and what builders should copy.
- Gemini 4 Argon: What Developers Can Actually UseGemini 4 Argon for developers: what Google shipped, what is verified, why access starts narrow, and what to watch before planning a migration around it.
FAQ
How do I use Gemini in OpenCode?
OpenCode's documented Custom provider mechanism (@ai-sdk/openai-compatible, for /v1/chat/completions) pointed at Google's documented Gemini OpenAI-compatible base URL and a current Gemini model id.
Which Gemini model ids work in OpenCode?
The official docs read for this guide list gemini-4-argon, gemini-3.8-flash, gemini-3.6-flash, gemini-3.5-flash-lite, gemini-3.1-pro-preview, gemini-2.5-pro and gemini-2.5-flash. Requests go to https://generativelanguage.googleapis.com/v1beta/openai/.
Is this an official Gemini and OpenCode setup?
The steps draw on both Gemini's and OpenCode's docs. It was last checked against 4 official pages on October 17, 2026.
Sources
Last verified against 4 official pages.
- raw.githubusercontent.comhttps://raw.githubusercontent.com/anomalyco/opencode/dev/packages/web/src/content/docs/providers.mdx
- raw.githubusercontent.comhttps://raw.githubusercontent.com/anomalyco/opencode/dev/packages/web/src/content/docs/models.mdx
- ai.google.devhttps://ai.google.dev/gemini-api/docs/openai
- ai.google.devhttps://ai.google.dev/gemini-api/docs/models
Newsletter
New models, set up the day they ship
One email per week. New model releases, the coding tools that support them and how to wire them up.