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.
- Gemini Trains on Your Chats Unless Keep Activity Is OffA Tell HN says paying for Gemini does not stop chat training. What Google documents about Keep Activity, human review and 3-year retention, and what developers should do before pasting code.
- Gemini 4 Carbon: Benchmarks, Pricing, and AccessGemini 4 Carbon is Google's new frontier model: 59 on the AA Intelligence Index, $2/$10 intro pricing, but cyber-defender access only. What builders do now.
- AI API 429, 529 and 503 Errors: Retry Rules That Match the DocsWhich 429, 529 and 503 errors to retry across OpenAI, Claude, Gemini and Bedrock, how to read Retry-After, and a typed wrapper that skips quota errors.
- AI Model Shutdown Dates 2026-2027: Calendar and Migration PlanEvery scheduled AI model API shutdown through mid 2027 by month: GPT-4o on Jan 14, whisper-1 on Feb 26, Claude Sonnet 4.5 on Nov 30, plus how to migrate.
- Gemini Live and TTS Preview Models Retire November 17: Moving to Gemini 3.8 Live and 3.8 Flash TTSThe Gemini API shuts down two Live API preview models and three TTS preview models on November 17, 2026. Replacement ids, what changes in the session config and TTS request, prices before and after, and the code change.
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.