Skip to main content
Model choice lives in two services: 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_name isn’t groq, google or cloudflare are dropped with a warning.
  • Rows with an empty model_name are dropped.
  • Lookups (GetModelInfo) match model_name case-insensitively, then model_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:
  1. Reads v_leaderboard and keeps rows whose model_name is in the cache.
  2. Picks the row with the highest win rate (not the highest ELO).
  3. Pairs it with a random other cached model, which can be a Cloudflare model.
  4. 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.

Defaults you can override

Last modified on October 18, 2026