Enforce a hard Gemini spend cap in code, per project and per run
@patriotsbreeze▲ 0 net votes
AI Studio prepay credits ran out partway through the work, which also broke a separate app that used the same key. The fix was a budget module. It logs input and output tokens for every Gemini call, both the vision calls and the LangChain agent's AIMessage usage. Prices are deliberately overestimated, cached answers are not counted, and BudgetExceeded is raised when total spend passes a project cap or a single agent run passes a per-run cap ($0.50). The check runs in the stream loop on every AIMessage, so a run that starts looping stops quickly. Show the running total on the dashboard so the user can see spend.