OpenCode

OpenCode is an open-source AI coding agent for the terminal, desktop, and IDE. It supports custom OpenAI-compatible providers through its opencode.json config file.

Quick setup

Paste your API key below, select your models, then copy the generated config into your opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "modelbridge": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ModelBridge",
      "options": {
        "baseURL": "https://api.modelbridge.dev/v1",
        "apiKey": "sk_your_api_key_here"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6",
          "limit": {
            "context": 200000,
            "output": 16384,
            "modalities": [
              "text",
              "image"
            ]
          },
          "variants": {
            "max": {
              "reasoningEffort": "max"
            },
            "high": {
              "reasoningEffort": "high"
            },
            "medium": {
              "reasoningEffort": "medium"
            },
            "low": {
              "reasoningEffort": "low"
            },
            "none": {
              "reasoningEffort": "none"
            }
          }
        }
      }
    }
  },
  "model": "modelbridge/claude-sonnet-4-6"
}

Place the config file at ~/.config/opencode/opencode.json (global) or opencode.json in your project root (per-project).

Setup steps

  1. Install OpenCode if you haven't already
  2. Create or edit your opencode.json config file
  3. Paste the generated config above
  4. Run opencode and select your ModelBridge model with /model

Reasoning effort variants

The generated config includes variants for each model, letting you switch between reasoning effort levels without duplicating models. Use the variant_cycle keybind in OpenCode to quickly switch between them.

All models get these variants:

  • high -- High reasoning effort (best for complex tasks)
  • medium -- Balanced reasoning (good default)
  • low -- Minimal reasoning (fastest, cheapest)
  • none -- No reasoning at all

Additionally:

  • Claude models get a max variant for maximum reasoning budget
  • GPT models get an xhigh variant for extra-high reasoning effort

Image support

Models that support vision (Claude, GPT-5.x) are configured with modalities: ["text", "image"] so OpenCode can send images to them. This enables features like screenshot analysis and image-based prompts.

Configuration details

  • npm -- Uses @ai-sdk/openai-compatible for the OpenAI-compatible protocol
  • options.baseURL -- Set to https://api.modelbridge.dev/v1
  • options.apiKey -- Your ModelBridge API key
  • models -- Each model includes a display name, limit (context/output/modalities), and variants
  • model -- The default model in provider/model-id format (e.g. modelbridge/claude-sonnet-4-6)

Switching models

In OpenCode, use the /model command to switch between configured models. All ModelBridge models appear under the "ModelBridge" provider. Use the variant_cycle keybind to switch reasoning effort without changing models.

Available models

Loading models...

Was this page helpful?