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:
curl -fsSL https://opencode.ai/install | bashnpm install -g opencode-aibrew install anomalyco/tap/opencodeConfirm the installation:
opencode --version2. 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:
echo 'export GATEWAY_API_KEY="<YOUR_API_KEY>"' >> ~/.zshrc
source ~/.zshrc[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:
{
"$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):
{
"$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
Navigate to a project directory and start OpenCode:
bashopencodeRun
/modelsinside the TUI and select yourgateway/<model-id>orgateway-anthropic/<model-id>entry.Alternatively, run a quick one-shot connectivity check from your shell:
bashopencode run "Reply with a single line confirming your connection."
Troubleshooting
404 Not Foundon Anthropic provider: VerifybaseURLishttps://api.zwwbai.com/v1(with/v1), nothttps://api.zwwbai.com.401 Unauthorizedor empty key: Check thatecho $GATEWAY_API_KEY(or$env:GATEWAY_API_KEYin PowerShell) outputs your fullsk-...key in the same shell where you launchopencode.model_not_found: Confirm the model key inmodelsmatches 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.