// PART 10
Model routing and fallbacks
Model routing is a boot-time decision with a documented degradation path. This page covers the fallback rules, the knobs, and how to diagnose a routing problem from the database.
One provider per process, chosen at boot
The LLM provider object is built at boot. A Vault change is invisible until the process restarts — plan provider switches as a config change plus a restart, and verify with a real completion afterwards.
Fallback behavior
Model routing supports a fallback chain. The documented degradation rules from the LLM outage runbook:
- Switch provider or model — point the bot (or the global fallback in
secret/gbo/llm) at a healthy model, then restart so the provider is rebuilt. - Stop the burn while the provider is down — a degraded answer beats a
hung request: reduce the per-request timeout (
LLM_READ_TIMEOUT_SECS, default 120 s) and let the fallback message run. The user-facing text must name the outage and offer a retry — never a blank answer. - Protect the budget — if one bot or tenant is consuming quota, drain it (disable its bots) before rotating providers, so fallback capacity serves everyone else.
- Never mock in production — a mock provider is for staging drills;
in production, degrade with an explicit message and keep the real error in
llm_metricsfor the postmortem.
Tool calls that do not need the model keep working during an outage, and channels using scripted replies keep flowing — the product degrades instead of stopping.
Profiles and models
| Knob | Purpose |
|---|---|
GB_LLM_PROFILES / GB_LLM_PROFILES_FILE |
inline JSON or file holding LLM profile definitions used by routing |
GB_LLM_PRICING |
inline JSON with token pricing data for cost accounting |
FREE_MODEL (desktop) |
the free model, chosen by measured time to first token; replaced automatically when the gateway says it no longer exists (guarded against loops) |
On the desktop editions the wizard’s FREE_MODEL_ID must match the
platform’s FREE_MODEL; a mismatch is a setup error, not a runtime fallback.
Diagnosing a routing problem
# What is failing, and with which error?
psql -h localhost -U postgres -d botserver -c "SELECT model, COUNT(*) AS failures, MAX(error) AS last_error
FROM llm_metrics
WHERE NOT success AND timestamp > NOW() - INTERVAL '30 minutes'
GROUP BY model ORDER BY failures DESC;"
# Latency or errors? p95 of both signals in the last hour.
psql -h localhost -U postgres -d botserver -c "SELECT percentile_cont(0.95) WITHIN GROUP (ORDER BY ttft_ms) AS ttft_p95,
percentile_cont(0.95) WITHIN GROUP (ORDER BY latency_ms) AS answer_p95,
COUNT(*) FILTER (WHERE NOT success) AS failures,
COUNT(*) AS calls
FROM llm_metrics WHERE timestamp > NOW() - INTERVAL '1 hour';"
# Is the local engine alive?
sudo incus exec llm -- pgrep -a llama-server || sudo incus exec llm -- systemctl status llm
Rollback of a provider change
Vault keeps versioned secrets — read the previous version instead of inventing a value:
vault kv get -version=<previous> secret/gbo/llm
vault kv put secret/gbo/llm url=<old-url> model=<old-model> openai_key=<old-key>
sudo incus exec bot -- systemctl restart botserver
If the fallback itself is failing, remove it so traffic returns to the
primary. Escalation owner for a provider outage: ai-oncall (see SLOs and
on-call).