OpenCode
OpenCode loads custom providers from opencode.json. Register Foglare with
the openai-compatible runtime package and its models appear in /models.
Prerequisites
- OpenCode installed (
opencodeon your PATH). - Optional: a Foglare API key (
sk-fog-…) from the dashboard for per-key usage stats. OpenCode wants some credential either way; without a key, any placeholder works and calls run anonymously. - Model ids from
GET /v1/models, or start with the tiers in the config.
Configuration
Put this in ~/.config/opencode/opencode.json for every project, or in
opencode.json at a project root for that project only. The baseURL
includes /v1; the runtime appends
/chat/completions.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"model": "foglare/auto:fast",
"providers": {
"foglare": {
"name": "Foglare",
"env": ["FOGLARE_API_KEY"],
"package": "@opencode/ai/providers/openai-compatible",
"settings": {
"baseURL": "https://api.foglare.com/v1"
},
"models": {
"auto:fast": { "name": "Foglare Fast" },
"auto:M": { "name": "Foglare Medium" },
"auto:L": { "name": "Foglare Large" },
"auto:XL": { "name": "Foglare XL" },
"qwen4-max": { "name": "Qwen4 Max" }
}
}
}
} | Field | Value | Why |
|---|---|---|
providers.foglare | provider id | Keys model references: foglare/auto:fast. |
package | @opencode/ai/providers/openai-compatible | Runtime for OpenAI chat-completions APIs. |
settings.baseURL | https://api.foglare.com/v1 | Versioned root. |
env | ["FOGLARE_API_KEY"] | Env var holding your sk-fog key from the dashboard. Required for inference. |
models | map of ids | Each key is sent as the model id verbatim. Add any catalog id here. |
model | foglare/auto:fast | Default model, provider/id format. |
Set the credential to your sk-fog key from the dashboard and launch. Inside OpenCode, /models picks
among the Foglare entries.
Shell
export FOGLARE_API_KEY="sk-fog-YOUR_KEY"
opencode
Config format verified against the OpenCode providers and config documentation. JSONC
(opencode.jsonc) works too if you want comments.
Verify
Check the endpoint from your shell first: the output should stream
chat.completion.chunk lines and end with
data: [DONE]. Then start OpenCode and send a message on
foglare/auto:fast.
curl the chat endpoint
curl -N https://api.foglare.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-fog-YOUR_KEY" \
-d '{"model":"auto:fast","stream":true,"messages":[{"role":"user","content":"Hello"}]}' Expected stream (trimmed)
data: {"id":"fglr_...","object":"chat.completion.chunk","created":1795312786,"model":"auto:fast","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"fglr_...","object":"chat.completion.chunk","created":1795312786,"model":"auto:fast","choices":[{"index":0,"delta":{"content":"! How can I help?"},"finish_reason":null}]}
data: {"id":"fglr_...","object":"chat.completion.chunk","created":1795312786,"model":"auto:fast","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}]}
data: [DONE] List accepted model ids (trimmed response)
curl https://api.foglare.com/v1/models
{
"object": "list",
"data": [
{ "id": "deepseek-v4.1-flash", "object": "model", "created": 1763769600, "owned_by": "foglare" },
{ "id": "qwen4-max", "object": "model", "created": 1763769600, "owned_by": "foglare" },
{ "id": "auto:fast", "object": "model", "created": 1763769600, "owned_by": "foglare" }
]
} Troubleshooting
| Symptom | Fix |
|---|---|
| 404, model not found | The model id is not in the catalog. List accepted ids with GET /v1/models. Tier ids are auto:fast, auto:S, auto:M, auto:L, auto:XL; direct ids carry no suffix. |
| 404 on the endpoint path | The base URL is wrong for this tool. Check whether it expects the root (https://api.foglare.com) or the versioned root (https://api.foglare.com/v1); the configuration table above says which. |
| 503, capacity exhausted | All upstream routes are busy or rate-limited. The error message says when to retry. Retry after that window, or switch to a routing tier so the gateway picks healthy capacity. |
| Output arrives all at once, or the stream hangs | Something between you and the gateway is buffering SSE. Use curl -N, disable proxy buffering (nginx: proxy_buffering off), and read the response as a stream instead of waiting for the full body. |
| Foglare models missing from /models | OpenCode only lists providers with a usable credential. Export FOGLARE_API_KEY (your sk-fog key, or any value) in the shell that starts OpenCode, or run /connect and paste it. |
| Config ignored | Check the file location: ~/.config/opencode/opencode.json for global, opencode.json in the project root for local. Project config overrides global. Validate the JSON against https://opencode.ai/config.json. |
| 404 on the endpoint path | settings.baseURL must end in /v1 and must not include /chat/completions; the package appends it. |