OpenCode
Use OpenCode with AIRouter24
AIRouter24 adaptation
reviewVerify that the target tool supports custom OpenAI-compatible base URLs before relying on every setting.
What is OpenCode?
OpenCode is an open-source AI coding agent available as a terminal interface and desktop app (beta). It features LSP integration, multi-session support, sharable session links, and compatibility with 75+ LLM providers — including AIRouter24 for unified multi-model access through a single API key.
Quick Start
Step 1: Install OpenCode
Install Script
curl -fsSL https://opencode.ai/install | bashnpm
npm install -g opencode-aiHomebrew
brew install anomalyco/tap/opencodeFor additional installation methods (Bun, pnpm, Yarn, Arch Linux, Windows), see the OpenCode installation docs.
Step 2: Get Your AIRouter24 API Key
- Sign up or log in at AIRouter24
- Navigate to your API Keys page
- Create a new API key
- Copy your key (starts with
sk-***)
Step 3: Connect OpenCode to AIRouter24
OpenCode supports AIRouter24 as a built-in provider. Use the interactive /connect command:
- Start OpenCode in your project directory:
cd /path/to/your/project
opencode- Run the
/connectcommand and select AIRouter24:
/connect-
Paste your AIRouter24 API key when prompted.
-
Run
/modelsto select a model:
/modelsYour requests will now be routed through AIRouter24.
Alternative: Config File
You can also configure AIRouter24 directly in your opencode.json config file:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"airouter24": {
"models": {
"~anthropic/claude-sonnet-latest": {},
"~google/gemini-flash-latest": {}
}
}
}
}Set your API key via the /connect command or by adding it to ~/.local/share/opencode/auth.json:
{
"airouter24": {
"type": "api",
"key": "sk-***"
}
}Provider Routing
When using AIRouter24, you can control which upstream providers handle your requests by adding options.provider to individual models in your config:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"airouter24": {
"models": {
"~anthropic/claude-sonnet-latest": {
"options": {
"provider": {
"order": ["anthropic"],
"allow_fallbacks": true
}
}
}
}
}
}
}For a full breakdown of routing options, see the Provider Routing docs.
Why Use AIRouter24 with OpenCode?
Access to Hundreds of Models
Switch between any model available on AIRouter24 — Anthropic, OpenAI, Google, xAI, Meta, DeepSeek, and many more — without managing separate API keys for each provider.
Provider Failover
If one provider is unavailable or rate-limited, AIRouter24 automatically routes to another, keeping your coding sessions uninterrupted.
Organizational Controls
For teams, AIRouter24 provides centralized budget management. Set spending limits, allocate credits, and monitor usage across developers using OpenCode from your AIRouter24 Activity Dashboard.
Model Flexibility
Switch models by updating your config or using the /models command — no need to reconfigure API keys or endpoints.
Troubleshooting
- Auth Errors: Ensure your API key is set correctly via
/connect. Check at airouter24.com/keys. - Model Not Found: Verify the model ID on airouter24.com/models. Use the exact format (e.g.,
~anthropic/claude-sonnet-latest). - Privacy: AIRouter24 does not log your source code prompts unless you opt in to prompt logging. See our Privacy Policy for details.