Skip to main content
Watch: I Built an AI App Without Leaving Databricks

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

  1. Step 1.

    Get a Gemini API key from Google AI Studio (https://aistudio.google.com/apikey).

  2. 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
    └
  3. 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"
            }
          }
        }
      }
    }
  4. 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.

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.

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.