OpenCode Setup with AnonRouter
Connect OpenCode to AnonRouter as a custom OpenAI-compatible provider, configure coding models, enable tools, and protect source-code privacy.
OpenCode can use AnonRouter as a custom OpenAI-compatible provider. Add one
compatibility-enabled key, declare the models you want in opencode.json, and
switch among them from OpenCode's /models picker.

The short version
Run /connect, choose Other, use provider id anonrouter, and paste a
compatibility-enabled ar_... key. Then add the JSON configuration below,
restart OpenCode, and run /models.
Before you begin
You need:
- A current OpenCode installation.
- An AnonRouter account with available credits.
- An inference key with OpenAI-compatible access enabled.
- At least one tool-capable model id from the AnonRouter catalog.
OpenCode sends a conventional bearer key and cannot perform AnonRouter's two-step private ticket exchange. Use a dedicated compatibility key with a credit limit appropriate for an agent that can make repeated requests.
Create an API key1. Save the AnonRouter credential
Start OpenCode and run:
/connectThen:
- Scroll to Other in the provider list.
- Enter
anonrouteras the provider id. - Paste the compatibility-enabled AnonRouter inference key.
The provider id must exactly match the key used in the JSON configuration.
OpenCode stores credentials entered through /connect in
~/.local/share/opencode/auth.json.
Protect OpenCode's credential store
Restrict access to the OpenCode data directory and never commit
auth.json. A hidden or masked key is still a reusable bearer credential.
2. Add the custom provider
Create opencode.json in the project root, or add the provider to the existing
file:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anonrouter": {
"npm": "@ai-sdk/openai-compatible",
"name": "AnonRouter",
"options": {
"baseURL": "https://api.anonrouter.ai/v1"
},
"models": {
"anthropic/claude-opus-4.8": {
"name": "Claude Opus 4.8"
},
"anthropic/claude-sonnet-5": {
"name": "Claude Sonnet 5"
},
"moonshotai/kimi-k2.5": {
"name": "Kimi K2.5"
},
"qwen/qwen-3-coder-480b-turbo": {
"name": "Qwen 3 Coder 480B"
}
}
}
}
}@ai-sdk/openai-compatible tells OpenCode to use the OpenAI Chat Completions
protocol. The baseURL must end at /v1; OpenCode adds
/chat/completions itself.
The model map is explicit because OpenCode does not automatically import a custom provider's complete catalog. Replace stale examples with exact current ids from AnonRouter. Only include models you want displayed in the picker.
Global or project configuration
OpenCode merges its configuration sources. The most useful locations are:
| Scope | File |
|---|---|
| Every project for the current user | ~/.config/opencode/opencode.json |
| One repository | opencode.json in the project root |
A project configuration overrides conflicting global settings. OpenCode's
official documentation says project configuration is safe to commit, but that
assumes it contains no embedded secrets. Keep the API key in /connect storage
or an environment variable.
Environment-variable alternative
Instead of /connect, add apiKey under the provider's options:
{
"options": {
"baseURL": "https://api.anonrouter.ai/v1",
"apiKey": "{env:ANONROUTER_API_KEY}"
}
}Set the value before starting OpenCode:
export ANONROUTER_API_KEY=ar_REPLACE_WITH_YOUR_API_KEY
opencodeThis JSON is only the options fragment; merge it into the complete provider
configuration rather than replacing opencode.json with it.
3. Select a model
Restart OpenCode after changing the provider configuration, then run:
/modelsChoose a model under AnonRouter. OpenCode identifies custom models as
provider_id/model_id; for example, the first configuration entry is selected
as:
anonrouter/anthropic/claude-opus-4.8The portion sent to AnonRouter remains anthropic/claude-opus-4.8.
You can also set a default at the root of opencode.json:
{
"model": "anonrouter/anthropic/claude-opus-4.8"
}Choose models for agentic coding
OpenCode notes that coding agents need models that are strong at both code and tool calling. For each AnonRouter route, verify:
- Tools are supported.
- The context window can hold the relevant files, instructions, and tool output.
- The output limit is sufficient for the edits you expect.
- The route's privacy and moderation labels match your project.
Model capabilities and ids change over time. Treat the examples as a starting configuration and verify them against the live catalog before relying on them for unattended work.
How tools work
OpenCode describes local actions—such as reading files, editing code, searching, and running shell commands—with OpenAI tool definitions. AnonRouter forwards supported tool definitions and model tool calls. OpenCode executes the selected tools locally and sends their results back in a later request.
AnonRouter does not execute OpenCode tools. Your OpenCode permissions determine what the agent can read or change, so review them separately from the model provider configuration.
Compatibility limits
| Feature | Status |
|---|---|
| Streaming Chat Completions | Supported |
| Tool calling | Supported on tool-capable routes |
| Static bearer authentication | Requires compatibility access on the key |
| Inline image message arrays | Not supported by AnonRouter's current compatibility contract |
| Legacy text completions | Not supported |
| OpenAI Responses API | Not used by this configuration |
Keep the provider package as @ai-sdk/openai-compatible. OpenCode's official
guide reserves @ai-sdk/openai for providers using /v1/responses, which is
not the AnonRouter endpoint configured here.
Source-code privacy boundary
OpenCode requests may include source files, patches, repository instructions, terminal output, test failures, tool schemas, and earlier conversation context. Anything included in the prompt reaches AnonRouter and the selected model provider.
This setup uses AnonRouter compatibility mode. The compatibility broker temporarily receives key identity and plaintext request together. AnonRouter does not intentionally retain prompts or responses, but this static-key flow is not unlinkable like the native ticket flow.
Use OpenCode's permission controls, exclude secrets and generated artifacts from agent context, and choose an AnonRouter route whose privacy label fits the code you are sending.
Troubleshooting
AnonRouter does not appear under /models
Confirm opencode.json contains the anonrouter provider and at least one
entry under models. Saving a credential with /connect does not create the
provider configuration by itself.
Authentication returns 401 or 403
Run opencode auth list to confirm the credential is stored under the
anonrouter id. Verify the key begins with ar_ and has OpenAI-compatible
access enabled.
Requests return 404
Use https://api.anonrouter.ai/v1 for options.baseURL. Do not append
/chat/completions.
Model not found
The object key under models must be an exact current AnonRouter API id. Replace
stale values with ids from the live catalog and restart OpenCode.
File edits or shell tools do not work
Choose a route that advertises tool calling and review OpenCode's local tool permissions. A successful text response alone does not prove the model emitted a valid tool call.
Context-length errors
Reduce the files and history included in the request or select a model with a
larger advertised context window. If you add OpenCode limit fields, copy the
current model limits rather than guessing them.
OpenCode setup FAQ
Do I need an OpenCode plugin?
No. OpenCode already supports custom OpenAI-compatible providers.
Can I configure several AnonRouter models?
Yes. Add several entries to the provider's models object, then switch among
them with /models.
Should I commit opencode.json?
Project configuration can be committed when it contains only provider and model
settings. Keep the key in /connect storage or an environment variable.
Is this AnonRouter's private ticket flow?
No. OpenCode sends a static bearer key and therefore uses compatibility mode.
Sources and further reading
- OpenCode: Providers and custom providers
- OpenCode: Configuration and file locations
- OpenCode: Selecting and configuring models
- AnonRouter compatibility mode
- AnonRouter model catalog
AnonRouter is an independent service and is not affiliated with OpenCode.
Connect your apps
Use AnonRouter with the chat clients, coding tools, self-hosted interfaces, and personal agents you already use.
Janitor AI Proxy Setup with AnonRouter
Connect Janitor AI to AnonRouter with an importable JSON proxy configuration, the correct API URL, model settings, and troubleshooting steps.