An OpenCode plugin for using AnyRouter as a Claude API provider with OpenCode.
OpenCode sends tool names in lowercase (e.g. todowrite, webfetch), which causes compatibility issues when using AnyRouter's Claude API. This plugin transparently converts tool names to PascalCase and fixes array serialization problems, making OpenCode work seamlessly with AnyRouter.
OpenCode uses lowercase tool names, but AnyRouter's Claude API requires correct casing. This plugin converts them automatically:
| OpenCode (lowercase) | Converted (PascalCase) |
|---|---|
todowrite |
TodoWrite |
webfetch |
WebFetch |
google_search |
Google_Search |
| Other names | First letter capitalized |
Transformation covers:
- Request body:
tools[].nameandmessages[].content[].name(tool_use blocks) - Response body:
content[].name(tool_use blocks) - SSE stream:
content_block_startevents withtool_usetype
Fixes an issue where arrays/objects in tool_use input fields are serialized as JSON strings. The plugin detects string values starting with [ or { and parses them back to proper JSON objects.
git clone <repo-url> opencode-anyrouter-cc
cd opencode-anyrouter-cc
bun install
bun run buildThis outputs dist/index.js. You can then reference it directly in opencode.json:
{
"plugin": ["/path/to/opencode-anyrouter-cc/dist/index.js"]
}bun install
bun run build
cp dist/index.js ~/.config/opencode/plugins/opencode-anyrouter-cc.jsAdd to your project's opencode.json:
{
"plugin": ["opencode-anyrouter-cc"]
}Or install globally in ~/.config/opencode/opencode.json:
{
"plugin": ["opencode-anyrouter-cc"]
}Use either project-level opencode.json or global ~/.config/opencode/opencode.json.
{
"plugin": [
"opencode-anyrouter-cc"
],
"anthropic": {
"options": {
"baseURL": "https://anyrouter.top/v1",
"apiKey": "sk-",
"headers": { "Authorization": "Bearer sk-" }
}
}
}{
"$schema": "https://opencode.ai/config.json",
"plugin": [
"opencode-anyrouter-cc"
],
"anthropic": {
"options": {
"baseURL": "https://anyrouter.top/v1",
"apiKey": "sk-your-anyrouter-key",
"headers": {
"Authorization": "Bearer sk-your-anyrouter-key"
}
}
}
}If you use a local plugin file, replace
"opencode-anyrouter-cc"with your relative path (for example"./opencode-anthropic-tool-name-transformer.mjs").
Note:
mise.tomlis only for the maintainer's local toolchain. Windows users and general contributors do not need mise.
bun install
bun run buildnpm install
npm run buildBoth commands output to
dist/index.js.
bun install # Install dependencies
mise run build # Build the plugin
mise run test # Run tests
mise run link # Symlink to OpenCode plugin dirThe plugin monkey-patches globalThis.fetch at initialization time. It only intercepts requests to URLs containing /v1/messages (the Anthropic Messages API endpoint). All other requests pass through unchanged.
Request flow:
OpenCode (lowercase) -> patchedFetch (PascalCase) -> AnyRouter API
|
OpenCode <- transformResponse/SSE <-----------------------+
MIT