OpenCode
Connect OpenCode, the open-source AI coding assistant, to AnyRouter: choose OpenAI Compatible, set the base URL and API key, and add custom model IDs.
Configuring a Third-Party API in OpenCode
OpenCode is an open-source AI coding assistant with highly customizable API integration. By configuring a third-party API, you are free to choose more capable or more cost-effective models (such as DeepSeek, SiliconFlow, etc.).
Step 1: Gather the API essentials
Before configuring, have the following ready:
- API Key: your authorization key. AnyRouter platform
- Base URL: the endpoint address (e.g.
https://anyrouter.win/v1). - Model ID: the exact model name (e.g.
deepseek-ai/DeepSeek-V3).
Step 2: Open the configuration UI
- Launch OpenCode.
- Click the settings gear in the bottom-left corner -> Settings.
- Type
OpenCodeorAI Providerinto the search box. - Find the Provider selector and set it to
OpenAI Compatible(orCustom).
Step 3: Fill in the parameters
1. Set the Base URL
Find the OpenAI Compatible: Base URL option and enter your third-party proxy address.
Note: make sure the address ends with
/v1and does not include/chat/completions.
2. Bind the API Key
Find the OpenAI Compatible: API Key option and paste your key.
3. Define the model list
Find the Custom Models or Model Map option:
- Click Add Item.
- Enter the name you want displayed in the UI (e.g.
DeepSeek). - Enter the model's real ID at the API provider (e.g.
deepseek-chat).
Step 4: Enable and test
- Open OpenCode's Chat window (usually the robot icon in the sidebar).
- In the model switcher at the bottom, select the Custom Model you just added.
- Send a prompt (for example:
Write a quicksort) to test connectivity.
Advanced tip: environment variables (for developers)
If you prefer managing things through the terminal or system environment:
OpenCode can also read .env files or system environment variables. You can set:
OPENAI_API_BASE: your third-party URLOPENAI_API_KEY: your key
Troubleshooting
| Error | Likely cause | Solution |
|---|---|---|
| Model Not Found | Model ID mismatch | Check the provider's model list and make sure the ID matches character for character. |
| Invalid API Key | Key expired or copied incorrectly | Regenerate the key and make sure there are no stray line breaks. |
| Network Error | Certificate or proxy issues | If you are using a relay in mainland China, check whether a specific network proxy needs to be turned off/on. |
| Stream Mode Error | Endpoint does not support streaming | Try disabling the Enable Streaming option in settings (though most modern APIs support it). |
💡 Tip: OpenCode is very friendly to open-source models. If you run LM Studio or LocalAI locally, just point the Base URL to
http://localhost:xxxx/v1for fully offline coding assistance.
OpenClaw
Set up OpenClaw, the local open-source agent platform, with AnyRouter: run openclaw onboard, pick custom providers, and enter your API key and model ID.
Qwen Code
Power Qwen Code with any model on AnyRouter in four steps: install the npm package, set OPENAI_API_KEY, OPENAI_BASE_URL and OPENAI_MODEL, verify with /about.