Editor & Tool Configuration

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:

  1. API Key: your authorization key. AnyRouter platform
  2. Base URL: the endpoint address (e.g. https://anyrouter.win/v1).
  3. Model ID: the exact model name (e.g. deepseek-ai/DeepSeek-V3).

Step 2: Open the configuration UI

  1. Launch OpenCode.
  2. Click the settings gear in the bottom-left corner -> Settings.
  3. Type OpenCode or AI Provider into the search box.
  4. Find the Provider selector and set it to OpenAI Compatible (or Custom).

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 /v1 and 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

  1. Open OpenCode's Chat window (usually the robot icon in the sidebar).
  2. In the model switcher at the bottom, select the Custom Model you just added.
  3. 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 URL
  • OPENAI_API_KEY: your key

Troubleshooting

ErrorLikely causeSolution
Model Not FoundModel ID mismatchCheck the provider's model list and make sure the ID matches character for character.
Invalid API KeyKey expired or copied incorrectlyRegenerate the key and make sure there are no stray line breaks.
Network ErrorCertificate or proxy issuesIf you are using a relay in mainland China, check whether a specific network proxy needs to be turned off/on.
Stream Mode ErrorEndpoint does not support streamingTry 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/v1 for fully offline coding assistance.

On this page