AnRouter

Configure OpenCode with AnRouter

Configure AnRouter in the OpenCode desktop app, the TUI, or opencode.json, then verify the connection.

OpenCode can connect to Chat Completions through @ai-sdk/openai-compatible. Its TUI, desktop app, and IDE interfaces can reuse the same provider configuration.

1. Get an AnRouter API key

  • Register at anrouter.com and sign in.
  • Open the dashboard and go to API Keys.
  • Create a key and copy it. Treat it like a password — never commit it to a repository.

2. Desktop app: add a custom provider

  1. Open the provider settings in OpenCode Desktop and add a custom provider.
  2. Set Provider ID to anrouter and the display name to AnRouter.
  3. Set Base URL to https://api.anrouter.com/v1 and enter your AnRouter API key.
  1. Add a model under Models. Its ID must exactly match the AnRouter models page or GET /v1/models, for example glm-5.3.
  2. Leave request Headers empty unless a documented integration requires them, submit, then choose anrouter/glm-5.3 from the model picker.
OpenCode Desktop custom provider and model configuration in English

3. TUI / CLI: store credentials

  1. Start OpenCode and enter /connect in the TUI.
  2. Choose Other and enter anrouter as the provider ID.
  3. Enter your AnRouter API key. This stores credentials only; the provider configuration below is still required.

4. Configure the provider manually

Image attachments in OpenCode: custom-provider models are treated as text-only unless image capability is declared. Keep both "attachment": true and "modalities": { "input": ["text", "image"], "output": ["text"] } on every AnRouter model you want to use with images. If these fields are omitted, OpenCode may display and resize an image but remove it before the API request, causing the model to say it cannot view images.
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anrouter/glm-5.3",
  "provider": {
    "anrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "AnRouter",
      "options": {
        "baseURL": "https://api.anrouter.com/v1"
      },
      "models": {
        "deepseek-v4.1-flash-1017": {
          "name": "DeepSeek V4.1 Flash",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.2": {
          "name": "GLM 5.2",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3": {
          "name": "GLM 5.3",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "glm-5.3-flash": {
          "name": "GLM 5.3 Flash",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "minimax-m3.1-flash": {
          "name": "MiniMax M3.1 Flash",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "qwen3.8-27b": {
          "name": "Qwen 3.8 27B",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "qwen3.8-flash-next": {
          "name": "Qwen 3.8 Flash Next",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "mimo-v2.6-pro": {
          "name": "MiMo V2.6 Pro",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        },
        "mimo-v2.6-flash": {
          "name": "MiMo V2.6 Flash",
          "attachment": true,
          "modalities": {
            "input": [
              "text",
              "image"
            ],
            "output": [
              "text"
            ]
          }
        }
      }
    }
  }
}

Put project configuration in opencode.json at the repository root, or personal global configuration in ~/.config/opencode/opencode.json. The example intentionally omits hard-coded context and output limits so client metadata cannot drift from the service's actual capabilities.

Restart required: after changing model capabilities, quit OpenCode completely and reopen it. Starting a new session or refreshing the page is not enough because OpenCode caches model capabilities at startup.

5. Verify

opencode auth list
opencode

# In the TUI
/models
Protocol choice: @ai-sdk/openai-compatible maps to /v1/chat/completions. Use @ai-sdk/openai only for a model/provider that is explicitly intended to use Responses.

Reference: OpenCode custom providers