Context
The admin AI page offered a provider picker (Gemini, OpenAI, Fake), a fallback provider, a chat model and a Thinking Budget. None of it matched what runs: the project only has Gemini keys, the worker ignored the admin config entirely (its model and thinking come from env), the Thinking Budget field reached no request, and the kill switch stopped the api but not the worker. The probe and the "key ready" badge only looked at GEMINI_API_KEY, not the GEMINI_API_KEYS pool. Toggling the switch re-saved every unsaved field of the form.
Decision
- Gemini only, the model fixed by env.
GEMINI_MODEL(api calls),AI_QUESTION_GENERATION_MODEL(quiz worker, elseGEMINI_MODEL),EMBEDDING_MODELand the thinking settings are read from env;resolveAiModels(env)inpackages/aiis the one resolution bothcreateAiClientand the admin page use, so the page shows what is called. Changing a model is an env change and a restart. ai.configkeeps three fields:aiEnabled,temperature,maxTokens. Older rows are read field by field (resolveAiConfig): provider/model/fallback/thinking fields are ignored, and one invalid field never resets the others, so a storedaiEnabled: falsestays off.- The kill switch is an
AiClientgate.AiClientOptions.gateruns before every call (before the cache and the budget, no event). The api and the worker each pass one that readsai.config; refusal isAiError('disabled')(never retried). The api maps it to a Vietnamese 503AI_DISABLED; worker processors treat it as non-transient (grading falls back to its deterministic feedback). The worker re-reads the switch at most every 5 s, the api every 2 s (and at once after an admin change in the same process). - Separate endpoints:
PUT /admin/ai/configsaves the sampling defaults only,PUT /admin/ai/enabledthe switch only; each writes the whole row and audits the changed fields with their old and new values. The probe pings the env model with the api's key pool, without retries, and works while AI is off. - The OpenAI and Fake adapters stay in
packages/ai: tests and laptops without a key useLLM_PROVIDER=fake. Nothing in the admin UI or API selects a provider.
Consequences
- The admin page shows the real model, key status and the daily budget (limit and today's global bucket), and can no longer point production at a model nobody priced or tested.
- Switching models needs a deploy; acceptable for a capstone with one provider.