OpenCode API key setup

OpenCode API Key Setup: Base URL, Provider & Models

OpenCode with a third-party API needs three things: an API key, a base_url, and a provider config. What is the OpenCode base URL? For Claude, GPT, DeepSeek and GLM models it is https://api.aicodewith.ai/v1 (options.baseURL), and your AI Code With API key goes in options.apiKey in ~/.config/opencode/opencode.json.

Pay as you go for Claude, Kimi, GLM, and more: get an API key, set base_url and provider in opencode.json, then confirm with a test message.

Example opencode.jsonJSON
opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "aicodewith-anthropic/claude-opus-5-5",
  "provider": {
    "aicodewith-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "AI Code With Anthropic",
      "options": {
        "baseURL": "https://api.aicodewith.ai/v1",
        "apiKey": "your-aicodewith-api-key"
      },
      "models": {
        "claude-opus-5-5": {
          "name": "Claude Opus 5.5"
        }
      }
    }
  }
}

OpenCode not installed?

This page configures the OpenCode terminal CLI. If opencode --version already prints a version, skip ahead to the quick setup.

Basic install command

curl -fsSL https://opencode.ai/install | bash

Or install globally with npm (this exact command is commonly searched)

npm install -g opencode-ai@latest

Installation succeeds when opencode --version prints a version number.

Secure quick setup

Pick a model, copy the config, save the file, and verify the connection in about 3 minutes.

  • Claude Opus 5.5 (claude-opus-5-5)
  • Claude Sonnet 5.5 (claude-sonnet-5-5)
  • DeepSeek V4.1 Flash (deepseek-flash)
  • GLM-5.3 (glm-5.3)
  • Kimi K2.7 Code (kimi-k2.7-code)
  • GPT-6 Astra (gpt-6-astra)
  • Claude Fable 5.1 (claude-fable-5-1)
  • Fable 5 (claude-fable-5)
  • Haiku 4.5 (claude-haiku-4-5-20251001)
  • Opus 4.6 (claude-opus-4-6)
  • Opus 4.7 (claude-opus-4-7)
  • Opus 4.8 (claude-opus-4-8)
  • Opus 5 (claude-opus-5)
  • Sonnet 4.6 (claude-sonnet-4-6)
  • Sonnet 4.6 (claude-4.6-sonnet-medium)
  • Sonnet 5 (claude-sonnet-5)
  • DeepSeek V4 Flash (deepseek-v4-flash)
  • DeepSeek V4 Pro (deepseek-v4-pro)
  • 2.5 Pro (gemini-2.5-pro)
  • 3 Pro Preview (gemini-3-pro-preview)
  • 3.1 Pro Preview (gemini-3.1-pro-preview)
  • Gemini 3 Flash Preview (gemini-3.5-flash)
  • Gemini 3.6 Flash (gemini-3.6-flash)
  • Gemini 3.7 Flash (gemini-3.7-flash)
  • Gemini 3.8 Flash (gemini-3.8-flash)
  • GLM 5.1 (glm-5.1)
  • GLM 5.2 (glm-5.2)
  • Grok 4.5 (grok-4.5)
  • Grok 4.6 (grok-4.6)
  • Grok 4.7 (grok-4.7)
  • Grok 4.7 Build Fast (grok-4.7-build-fast)
  • Kimi K2.6 (kimi-k2.6)
  • Kimi K3 (kimi-k3)
  • GPT-5.5 (gpt-5.5)
  • GPT-5.6 Sol (gpt-5.6-sol)
  • GPT-5.6 Terra (gpt-5.6-terra)
  • GPT-6 Sol (gpt-6-sol)
  • Claude Haiku 5.5 (claude-haiku-5-5)
  • Gemini 3 Flash Preview (gemini-3-flash-preview)
  • Gemini 4 Argon (gemini-4-argon)
  • Kimi K3.1 Pro (kimi-k3.1-pro)
  • MiniMax M3.1 Flash (minimax-m3.1-flash)
  • GPT-6.1 Sol (gpt-6.1-sol)
  • GPT-6.1 Terra (gpt-6.1-terra)
  • Jev 1.13 (jev-1.13.0)
  • Jev Latest (jev-latest)
  • Grok 4.5 (grok-4.5)
  • Grok 4.6 (grok-4.6)
  • Grok 4.7 (grok-4.7)
  • Grok 4.7 Build Fast (grok-4.7-build-fast)

1. Choose a model

The current catalog contains 50 models.

2. Copy the config

Provider
aicodewith-anthropic
npm adapter
@ai-sdk/anthropic
Base URL
https://api.aicodewith.ai/v1
Model ID
claude-opus-5-5
{
  "$schema": "https://opencode.ai/config.json",
  "model": "aicodewith-anthropic/claude-opus-5-5",
  "provider": {
    "aicodewith-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "AI Code With Anthropic",
      "options": {
        "baseURL": "https://api.aicodewith.ai/v1",
        "apiKey": "your-aicodewith-api-key"
      },
      "models": {
        "claude-opus-5-5": {
          "name": "Claude Opus 5.5"
        }
      }
    }
  }
}
Next: save the config

3. Save opencode.json

Back up an existing opencode.json, then merge both model and provider from the generated content. Keep other Providers, and make sure options.apiKey holds your real key.

Open the API key page

Save the config file

  1. 1. Open your system terminal

    2. Run the command below to open the config file (created automatically if missing):

    notepad "$env:USERPROFILE\.config\opencode\opencode.json"
  2. 3. Paste the config copied in step 2 and save it

    Press Ctrl+S on Windows/Linux, Cmd+S on macOS.

Check the API key

Signed in: your key is already filled in. Not signed in: replace your-aicodewith-api-key in options.apiKey with your real key. Save, then restart OpenCode.

4. Restart and verify

  1. Run in your system terminalopencode
  2. Type inside OpenCode/models confirm the Provider and Model ID match the page selection
  3. Send in the chatReply with exactly: connection successful
  4. confirm OpenCode displays a reply and match its time and model in AI Code With usage records

Usage records confirm that a request reached AI Code With. Determine success from the status, response content, and the reply actually shown in OpenCode.

How does OpenCode connect to a third-party API?

OpenCode uses a custom Provider to send requests to the API service you choose: the Provider is the namespace that tells OpenCode which service to call, the API key handles authentication, the Base URL is the third-party API endpoint, and the Model ID selects the actual model.

Once saved, requests flow along OpenCode → Provider → Base URL → model API. After a /models check and a short test message, you can match the request against your usage records by time and model.

If setup fails, check these 4 things first

Each item links to a dedicated troubleshooting article with detailed steps.

  • Usually the API key is invalid, mistyped, or not read correctly. Check that options.apiKey in ~/.config/opencode/opencode.json holds the full key with no extra spaces, and that the Base URL ends with /v1.

  • The Model ID does not match the Provider config, or the channel does not support the model. Compare the generated Model ID and Provider pair character by character.

  • Usually the Base URL is wrong. Copy the value generated on this page and do not append /v1, /v1beta, or invent an endpoint path.

  • Config not applied / Provider missing

    View detailed troubleshooting →

    Check the config file path, that the JSON is valid, and that OpenCode reloaded the file. Reopen OpenCode after saving, then run /models.

Frequently asked questions

What should the Base URL be?

Copy the Base URL generated by the quick setup above. Do not append /v1 or /v1beta manually.

Where is the OpenCode config file?

This page generates ~/.config/opencode/opencode.json. Paths can vary by install method and version, so compare it with the current OpenCode docs.

How do I confirm the setup works?

Run /models to select the model, send a short message, then match the request by time and model in AI Code With usage records.

Which models are supported?

Claude, GPT, Gemini, DeepSeek, GLM, Kimi, and Grok, among others. Click "View all models" to browse the full catalog.

Need full installation or troubleshooting docs?

See the OpenCode setup docs for full installation guides, every config parameter, the complete model list, and troubleshooting.

Open the OpenCode setup docs

Common problems: Rate limit or 429 · Usage is recorded but OpenCode shows no reply · reasoning part/text part not found or summaryParts parsing error · 403 Forbidden · BunInstallFailedError or models.dev download failure