Configure OpenCode with XAI Router
Posted January 10, 2026 by The XAI Tech Teamย โย 2ย min read
OpenCode (opencode) is a developer-friendly coding assistant for the terminal and beyond. This guide shows you how to route opencode through XAI Router (xairouter).
Prerequisites
- An XAI Router account: Sign up at m.xairouter.com and create an API Key.
- opencode installed locally.
Step 1: Create an API Key in XAI Router
- Log in to m.xairouter.com.
- Go to API Keys and create a new key (use a label like
opencode). - Copy the key. Youโll use it as
XAI_API_KEY.
Step 2: Set the environment variable
We recommend XAI_API_KEY.
macOS / Linux:
export XAI_API_KEY="sk-xxx"
Windows PowerShell:
$env:XAI_API_KEY="sk-xxx"
Step 3: Configure opencode
Create or overwrite ~/.config/opencode/opencode.json:
cat > ~/.config/opencode/opencode.json << 'EOF'
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"XAI": {
"options": {
"baseURL": "https://api.xairouter.com/v1",
"apiKey": "{env:XAI_API_KEY}"
},
"models": {
"glm-4.7": {},
"ark-code-latest": {},
"MiniMax-M2.1": {},
"gemini-3-pro-preview": {}
}
}
},
"plugin": ["oh-my-opencode"]
}
EOF
Note: We use the
XAIprovider and configure models likeglm-4.7,MiniMax-M2.1, andgemini-3-pro-preview.
Step 4: Validate
opencode debug config
Verify that the configured models appear in the output.
With the setup above, your opencode runs through XAI Router with centralized key management, observability, and cost control.