AI is a first-class citizen with strong guardrails.
Every prompt that produces stored output must be defined with definePrompt. It records model and prompt_version. Changing the prompt template requires bumping the version and passing the golden eval set.
Use generateWithUsage. It performs kill-switch + budget preflight (with re-check), calls the provider, and records a usage_events row with cost.
The chat route is the reference implementation for rate limiting, preflight, tool use, and proper onFinish/onError handlers.