Skip to content
Docs

OpenCode

OpenCode is a terminal-based AI coding assistant that runs in your development environment. Here's how to use OpenCode with Vercel AI Gateway to access models from OpenAI, Anthropic, Google, xAI, and more through a unified endpoint.

The Vercel CLI is the recommended way to set this up. vercel ai-gateway coding-agents setup --agent opencode provisions a key and adds the vercel provider to ~/.config/opencode/opencode.json for you, keeping the key in your macOS Keychain instead of plaintext config. The steps below configure the same thing from inside OpenCode.

  1. Go to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a new API key.

  2. Run opencode in your terminal to start OpenCode:

    Terminal
    opencode
  3. Run the /connect command and search for Vercel AI Gateway:

    Terminal
    /connect

    Enter your Vercel AI Gateway API key when prompted.

  4. Run the /models command to select a model:

    Terminal
    /models

    Your requests will now be routed through Vercel AI Gateway.

  5. You can customize models through your OpenCode config. Here's an example of specifying provider routing order in opencode.json:

    opencode.json
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "vercel": {
          "models": {
            "anthropic/claude-sonnet-5": {
              "options": {
                "order": ["anthropic", "vertex"]
              }
            }
          }
        }
      }
    }

    See the provider options documentation for more details on supported routing options.

  6. View your usage, spend, and request activity in the AI Gateway section in the Vercel dashboard sidebar. See the observability documentation for more details.

Last updated July 28, 2026

Was this helpful?

supported.