AI Usage, Prompts & Monitoring

How AI is wired

AI features call Google Gemini directly using our own API key. We deliberately do not route model traffic through third-party gateways, so behaviour and cost stay predictable and the platform remains portable.

Prompt catalogue and versioning

Prompts are content, not code. They live in ai_prompt_templates with history in ai_prompt_versions, and exactly one version of a template is active at a time. Editing a prompt creates a new version rather than overwriting the old one, so a regression can be traced to a specific change and rolled back.

When a gym reports that AI output "changed", check the template's version history before anything else.

Usage monitoring

Every call is recorded in ai_usage_log — which feature, which gym, token counts and outcome. Use it to spot a single gym or a single feature driving cost, and to confirm whether a failure was a model error or a call that never happened.

Where AI is used

Quality feedback

Manual coach edits to enriched content are captured so prompt changes can be judged against real corrections rather than opinion. Treat a rise in edits on one component as a prompt problem, not a coach problem.