Back to API Docs
Opencode
Opencode via the @ai-sdk/openai-compatible provider.
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-4o-mini": { "name": "gpt-4o-mini" },
"claude-3-5-sonnet-latest": { "name": "Claude 3.5 Sonnet" },
"gpt-4o": { "name": "GPT-4o" }
}
}
},
"model": "gateway/gpt-4o-mini"
}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.
