Back to API Docs
Opencode
Thiết lập Opencode với provider tương thích OpenAI.
Connection
- URL cơ sở
- https://your-domain.com/v1
- Install
- npm install -g opencode-ai
Default model
Setup
- Install Opencode globally via npm.
- Create an opencode.json configuration file at your project root.
- Export your gateway API key in the shell.
- Run `opencode` in your project directory.
Cấu hình
Configuration file
opencode.json
json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"gateway": {
"npm": "@ai-sdk/openai-compatible",
"name": "API Gateway",
"options": {
"baseURL": "https://your-domain.com/v1",
"apiKey": "{env:GATEWAY_API_KEY}"
},
"models": {
"gpt-6-astra": { "name": "gpt-6-astra" }
}
}
},
"model": "gateway/gpt-6-astra"
}Shell environment
~/.zshrc
bash
export GATEWAY_API_KEY="YOUR_API_KEY"Tip: The `@ai-sdk/openai-compatible` provider lets Opencode talk to any OpenAI-shaped API. Add more models to the "models" map to expose them in the picker.
