Connect a third-party API in OpenCode
OpenCode is an open-source coding assistant with flexible API wiring. Point it at a relay or direct provider for better models or pricing (DeepSeek, SiliconFlow, etc.).Step 1: Gather credentials
- API key: Tokensmind console
- Base URL: e.g.
https://tokensmind.ai/v1 - Model id: e.g.
deepseek-ai/DeepSeek-V3
Step 2: Open settings
- Launch OpenCode.
- Settings gear (lower left) → Settings.
- Search for
OpenCodeorAI Provider. - Set Provider to
OpenAI Compatible(orCustom).
Step 3: Fill in fields
1. Base URL
Set OpenAI Compatible: Base URL to your proxy.End with/v1, without/chat/completions.
2. API key
Paste into OpenAI Compatible: API Key.3. Models
Under Custom Models / Model Map:- Add Item
- Display name (e.g.
DeepSeek) - Real model id from the provider (e.g.
deepseek-chat)
Step 4: Test
- Open Chat (robot icon in the sidebar).
- Pick your custom model in the switcher.
- Send a prompt (e.g. “implement quicksort”) to verify connectivity.
Advanced: environment variables
OpenCode can read.env or system env:
OPENAI_API_BASE— third-party base URLOPENAI_API_KEY— key
Troubleshooting
| Error | Likely cause | Fix |
|---|---|---|
| Model Not Found | Wrong model id | Match the provider list exactly. |
| Invalid API Key | Bad or expired key | Regenerate; strip newlines. |
| Network Error | TLS / proxy | Adjust proxy for CN relays. |
| Stream Mode Error | Streaming unsupported | Try disabling Enable Streaming. |
Tip: OpenCode works well with local stacks. For LM Studio or LocalAI, set Base URL to http://localhost:xxxx/v1 for offline use.

