OpenCode setup
OpenCode (a terminal coding agent) supports custom OpenAI-compatible providers
via opencode.json.
Configuration
Save as opencode.json in your project root (or
~/.config/opencode/opencode.json for all projects):
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"mafdet": {
"npm": "@ai-sdk/openai-compatible",
"name": "Mafdet AI",
"options": {
"baseURL": "https://api.mafdet.ai/v1",
"apiKey": "{env:MAFDET_API_KEY}"
},
"models": {
"deepseek-v4-pro": { "name": "Mafdet AI DeepSeek V4 Pro" }
}
}
}
}
Then export your key and pick the model inside OpenCode as
mafdet/deepseek-v4-pro:
export MAFDET_API_KEY="sk-mafdet-xxxxxxxxxxxxxxxx"
{env:MAFDET_API_KEY}is resolved by OpenCode at runtime — no secret lives in the file- Add one entry under
modelsper Mafdet AI model ID you want to use (see Models overview)
You can also generate this file pre-filled with your model from Console → API Keys → Developer Tools.
Common errors
| Symptom | Meaning | Fix |
|---|---|---|
| 401 | MAFDET_API_KEY not set | Export it before starting OpenCode |
| 429 | Rate limited (RPM/TPM) | Coding agents need a key with a high TPM limit |
| model not listed | Missing models entry | Add the model ID under models |