# Run OpenCode through AnyRouter

> One CLI command injects an AnyRouter provider for the session, or add a custom provider in opencode.json — one key, the Chat Completions catalog, and request logs.

Add an AnyRouter provider to OpenCode

**Slug**: `opencode`  
**URL**: https://anyrouter.dev/use-cases/opencode  
**Markdown**: https://anyrouter.dev/use-cases/opencode.md  
**Short link**: https://anyrouter.dev/u/opencode  

## Why use this

OpenCode's built-in providers each want their own key. Switching models or sharing billing with Claude Code and Codex means editing every tool separately.

## Set it up

1. Create an AnyRouter key in the dashboard (sk-ar-…), or let the CLI sign you in.
2. Launch with anyr opencode so it injects the provider for that session, or add AnyRouter to opencode.json for a persistent config.
3. Pick an anyrouter/… model in /models and confirm the call in request logs.

## Code

### anyr launcher

```bash
anyr opencode
```

### opencode.json

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anyrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AnyRouter",
      "options": {
        "baseURL": "https://anyrouter.dev/api/v1",
        "apiKey": "{env:ANYROUTER_API_KEY}"
      },
      "models": {
        "anthropic/claude-sonnet-4-6": {
          "name": "Claude Sonnet 4.6"
        }
      }
    }
  },
  "model": "anyrouter/anthropic/claude-sonnet-4-6"
}
```

## Limits

- anthropic/* models in the example run on your own Anthropic key (BYOK). Swap in any listed model id to use credits.

## Related

- [claude-code](https://anyrouter.dev/use-cases/claude-code)
- [coding-agents](https://anyrouter.dev/use-cases/coding-agents)
- [mcp-for-agents](https://anyrouter.dev/use-cases/mcp-for-agents)
