Skip to content

OpenCode ​

OpenCode is an open-source terminal coding agent built on the Vercel AI SDK. Because it supports custom provider definitions out of the box, you can connect RKAPI through either the OpenAI-compatible protocol (@ai-sdk/openai-compatible) or the Anthropic Messages protocol (@ai-sdk/anthropic), or configure both side by side.

1. Install OpenCode ​

Install OpenCode using your preferred package manager:

bash
curl -fsSL https://opencode.ai/install | bash
bash
npm install -g opencode-ai
bash
brew install anomalyco/tap/opencode

Confirm the installation:

bash
opencode --version

2. Store Your API Key in an Environment Variable ​

Avoid hardcoding secrets directly in JSON configuration files. Create an API key in the RKAPI Console and export it as GATEWAY_API_KEY:

bash
echo 'export GATEWAY_API_KEY="<YOUR_API_KEY>"' >> ~/.zshrc
source ~/.zshrc
powershell
[Environment]::SetEnvironmentVariable("GATEWAY_API_KEY", "<YOUR_API_KEY>", "User")

Open a new terminal window after setting a persistent Windows environment variable.

3. Configure ~/.config/opencode/opencode.json ​

Create or edit ~/.config/opencode/opencode.json (on Windows, %USERPROFILE%\.config\opencode\opencode.json). OpenCode expands {env:GATEWAY_API_KEY} at runtime.

Both Providers Use https://api.zwwbai.com/v1 in OpenCode

Unlike Anthropic's official Python/TypeScript SDKs, Vercel's @ai-sdk/anthropic package appends /messages directly onto baseURL. Therefore, both @ai-sdk/openai-compatible and @ai-sdk/anthropic in OpenCode should use https://api.zwwbai.com/v1.

Option A: OpenAI-Compatible Provider (@ai-sdk/openai-compatible) ​

Best for GPT, DeepSeek, Gemini, and multi-model groups exposed over OpenAI Chat Completions:

json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "gateway": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "RKAPI",
      "options": {
        "baseURL": "https://api.zwwbai.com/v1",
        "apiKey": "{env:GATEWAY_API_KEY}"
      },
      "models": {
        "gpt-5.4": {
          "name": "GPT-5.4",
          "limit": {
            "context": 272000,
            "output": 32768
          }
        },
        "deepseek-chat": {
          "name": "DeepSeek Chat",
          "limit": {
            "context": 128000,
            "output": 8192
          }
        }
      }
    }
  },
  "model": "gateway/gpt-5.4"
}

Option B: Anthropic Provider (@ai-sdk/anthropic) ​

Best for Claude models when you want native Anthropic Messages features (such as prompt caching and extended thinking):

json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "gateway-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "name": "RKAPI (Anthropic)",
      "options": {
        "baseURL": "https://api.zwwbai.com/v1",
        "apiKey": "{env:GATEWAY_API_KEY}"
      },
      "models": {
        "claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6",
          "limit": {
            "context": 200000,
            "output": 16384
          }
        },
        "claude-opus-4-6": {
          "name": "Claude Opus 4.6",
          "limit": {
            "context": 200000,
            "output": 16384
          }
        }
      }
    }
  },
  "model": "gateway-anthropic/claude-sonnet-4-6"
}

Combining Both Providers in One File ​

You can define both gateway and gateway-anthropic under "provider" in the same opencode.json file (even pointing each to a separate key variable such as {env:GATEWAY_OPENAI_KEY} and {env:GATEWAY_CLAUDE_KEY} if your keys target different channel groups). Always verify exact model IDs on RKAPI Pricing.

4. Verify with opencode ​

  1. Navigate to a project directory and start OpenCode:

    bash
    opencode
  2. Run /models inside the TUI and select your gateway/<model-id> or gateway-anthropic/<model-id> entry.

  3. Alternatively, run a quick one-shot connectivity check from your shell:

    bash
    opencode run "Reply with a single line confirming your connection."

Troubleshooting ​

  • 404 Not Found on Anthropic provider: Verify baseURL is https://api.zwwbai.com/v1 (with /v1), not https://api.zwwbai.com.
  • 401 Unauthorized or empty key: Check that echo $GATEWAY_API_KEY (or $env:GATEWAY_API_KEY in PowerShell) outputs your full sk-... key in the same shell where you launch opencode.
  • model_not_found: Confirm the model key in models matches an exact ID enabled for your API key's group on https://s2pbxm0xv5y.adtyai-fz.top/pricing.
  • Need more help? Check Channel Availability or the General FAQ.