ModelSelector (random picks, lookups and the cache) and LeaderboardModelSelector (topper pairing). Both read ai_models; neither writes to it.
The model cache
ModelSelector loads every ai_models row with status = active, newest first, and keeps it in memory for five minutes. The cache is warmed in the background when the API starts.
- Rows whose
provider_nameisn’tgroq,googleorcloudflareare dropped with a warning. - Rows with an empty
model_nameare dropped. - Lookups (
GetModelInfo) matchmodel_namecase-insensitively, thenmodel_id.
Admin changes to models are not pushed to the cache. A new, edited or deactivated model takes effect within five minutes, or at the next container start.
Auto-selectable vs manual-only
Topper pairing
LeaderboardModelSelector.GetTopperAndRandomModelAsync:
- Reads
v_leaderboardand keeps rows whosemodel_nameis in the cache. - Picks the row with the highest win rate (not the highest ELO).
- Pairs it with a random other cached model, which can be a Cloudflare model.
- Falls back to a random pair if there are fewer than two models, no stats, or any error.
Fallback
When a provider call throws or takes longer than 60 seconds, the API calls the Groq fallback model (BASIC_FALLBACK_MODEL, default llama-3.1-8b-instant). The answer is prefixed with a [System Note] naming the original model, and the response keeps the original model name. See Provider integration.