OpenCode
Last updated: 2026-08-03; third-party tools can change at any time. If configuration fails, follow the latest official documentation.
OpenCode is a terminal agent with custom model-provider support. Review the OpenCode installation documentation and custom provider documentation before installing it.
Install
curl -fsSL https://opencode.ai/install | bash
# 或
npm i -g opencode-ai
Configure Provider
In ~/.config/opencode/opencode.json or opencode.json in the project directory add:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"token-market": {
"npm": "@ai-sdk/openai-compatible",
"name": "Token Market",
"options": {
"baseURL": "https://api.tokensmarket.ai/v1",
"apiKey": "{env:TOKEN_MARKET_API_KEY}"
},
"models": {
"<MODEL_ID>": { "name": "<MODEL_ID>" }
}
}
}
}
| Configuration Location | Scope |
|---|---|
~/.config/opencode/opencode.json | Shared by multiple projects for the current user; inject the real key through an environment variable. |
Project-level opencode.json | Applies only to the current project and works well as a team template; never store a real Key in it. |
Startup and model selection
cd /path/to/your/project
opencode
Use /models in the input box to select a configured model. This guide uses @ai-sdk/openai-compatible with /v1/chat/completions; for a model that supports only the Responses API, switch to @ai-sdk/openai as described in the official documentation. If the provider schema or fields change, follow the official custom provider documentation.
