OpenCode
OpenCode accepts custom OpenAI-compatible providers. FreeGate is one, so the setup is a config file plus an environment variable · no proxy or shim.
1. Export your key in the shell that starts OpenCode
export FREEGATE_API_KEY="fg_live_…" export FREEGATE_API_KEY="fg_live_…" $env:FREEGATE_API_KEY = "fg_live_…"
The config references {env:FREEGATE_API_KEY}, so the variable must exist in the
process that launches OpenCode · not just in another terminal.
2. Add the provider
mkdir -p ~/.config/opencode && ${EDITOR:-nano} ~/.config/opencode/opencode.jsonc mkdir -p ~/.config/opencode && ${EDITOR:-nano} ~/.config/opencode/opencode.jsonc New-Item -ItemType Directory -Force "$env:USERPROFILE\.config\opencode" | Out-Null
notepad "$env:USERPROFILE\.config\opencode\opencode.jsonc" {
"$schema": "https://opencode.ai/config.json",
"providers": {
"freegate": {
"name": "FreeGate",
"env": ["FREEGATE_API_KEY"],
"package": "@opencode/ai/providers/openai-compatible",
"settings": {
"baseURL": "https://api.firesafety.men/v1"
},
"models": {
"flint": { "name": "Flint" },
"glyph": { "name": "Glyph Cluster" },
"beam-contributor-free": { "name": "Beam 1.0 Contributor" },
"oss-120b": { "name": "GPT-OSS 120B" },
"oss-20b": { "name": "GPT-OSS 20B" },
"qwen38": { "name": "Qwen 3.8 27B" },
"allam-2-7b": { "name": "ALLaM 2 7B" },
"dd-v4-flash": { "name": "DeepSeek V4 Flash" },
"dd-v41-flash-fast": { "name": "DeepSeek V4.1 Flash Fast" },
"muse-spark-13": { "name": "Muse Spark 1.3 Contributor" },
"glm-53-flash": { "name": "GLM 5.3 Flash" },
"qwen37-flash": { "name": "Qwen 3.7 Flash" },
"hy4-flash": { "name": "Tencent Hy4 Flash" },
"kimi-k27": { "name": "Kimi K2.7 Code" }
}
}
},
"model": "freegate/oss-20b"
} env is what tells OpenCode where to read the credential · without it, requests go
out with no bearer token. The model list above is the whole catalog, including paid models your
account may not have; calling a locked one returns 403 model_not_allowed.
Older OpenCode builds use "npm": "@ai-sdk/openai-compatible" and
"options" instead of "package" and "settings". The values
are the same; only the field names changed.
3. Pick a model
Inside OpenCode, run /models and choose freegate/oss-20b.
What works
- Chat and code questions, streaming responses.
- Tool calling.
tools,tool_choiceand tool results are forwarded. - Images on vision-capable models (see models).
- Files · text-like files are inlined; binary formats are refused.
Another provider keeps overriding it
OpenCode merges several config files, and a later file wins on conflicting keys. A custom AI
router can keep winning because it sets the top-level "model" in a file with higher
precedence.
Start with the source list OpenCode itself prints:
opencode debug config On Windows, these are the files that can override the global config:
Get-Item "$env:USERPROFILE\.config\opencode\opencode.json*", "$env:ProgramData\opencode\opencode.json*", ".\opencode.json*", ".\.opencode\opencode.json*" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName Open every file that exists and fix the conflict there:
Get-Item "$env:USERPROFILE\.config\opencode\opencode.json*", "$env:ProgramData\opencode\opencode.json*", ".\opencode.json*", ".\.opencode\opencode.json*" -ErrorAction SilentlyContinue | ForEach-Object { notepad $_.FullName } -
%ProgramData%\opencode\opencode.jsonis the machine-wide system config. It overrides your user config and every project config. -
A project's
.opencode\opencode.jsonoverrides a plainopencode.jsonin the same tree. -
The fix is usually to change or remove the existing
"model": "…"line in the winning file, or set"model": "freegate/oss-20b"there. Provider entries merge, so both providers can stay installed. - Run
opencode reloadafter editing, oropencode service restartif the background server was already running.
If the provider does not appear
- Check the key resolves in the same shell: on macOS/Linux
echo $FREEGATE_API_KEY, on Windows$env:FREEGATE_API_KEY. - If the background server was already running before you exported the key, restart it:
opencode service restart.opencode reloadpicks up config edits but not new environment variables. - Confirm the endpoint:
curl https://api.firesafety.men/v1/models -H "Authorization: Bearer $FREEGATE_API_KEY"(Windows:curl.exeand$env:FREEGATE_API_KEY). - Verify the JSON parses · a trailing comma in
opencode.jsoncis the most common failure. -
provide an API key in x-api-key or as a Bearer tokenmeans OpenCode sent no credential. Runopencode debug configand confirmproviders.freegatestill has"env": ["FREEGATE_API_KEY"], then runopencode service restart. Storing the key with/connectalso works. 401means a bad or revoked key;403means the model is not available to your account.