OpenCode
1.1 API Configuration
Method 1: Interactive Configuration (Recommended)
-
Enter project directory
-
Start OpenCode
-
Run
/connectcommand -
Select provider type
-
Choose "Other" or "Custom Provider"
-
Or search for provider name
-
-
Enter URL and API Key
-
Select model
Method 2: Config File
Step 1: Create Config
Create or edit ~/.config/opencode/config.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"hpc-ai": {
"npm": "@ai-sdk/openai-compatible",
"name": "HPC-AI Tech",
"options": {
"baseURL": "https://api.hpc-ai.com/inference/v1",
"apiKey": "{env:HPC_AI_API_KEY}"
},
"models": {
"minimax/minimax-m2.5": {
"name": "HPC-AI Tech"
}
}
}
},
"model": "minimax/minimax-m2.5"
}
Step 2: Add API Key
Create or edit ~/.local/share/opencode/auth.json:
{
"hpc-ai": {
"type": "api",
"key": "sk-your-hpc-ai-api-key"
}
}
Config Priority
| Priority | Config Path | Description |
|---|---|---|
| 1 | OPENCODE_CONFIG env var | Custom config file path |
| 2 | OPENCODE_CONFIG_DIR env var | Custom config directory |
| 3 | <project>/opencode.json | Project-level config |
| 4 | ~/.config/opencode/opencode.json | Global config |
Method 3: Environment Variables
export HPC_AI_API_KEY="sk-your-hpc-ai-api-key"
export OPENAI_API_BASE="https://api.hpc-ai.com/inference/v1"