r/foojay • u/FrankCodeWriter • 1d ago
Token budgets for Spring AI: the problems I didn't expect
On Foojay, Ujjwal Tiwari explains why counting requests is the wrong unit for LLM apps. One HTTP request can trigger forty paid model calls in a tool loop, and a rate limiter only sees one request.
The article covers Token Allowance, a Spring Boot starter that puts token and dollar budgets on Spring AI ChatClient calls, per user, tenant or session, with a cap on model calls per request. It also explains the harder parts: where the advisor check has to sit relative to ToolCallingAdvisor, a race in check-then-call budgeting and how reservations fix it, why costs are stored as micro-dollars in a long, and how OpenAI and Anthropic report input tokens differently.
https://foojay.io/today/building-token-budgets-for-spring-ai-the-problems-i-didnt-expect/
No hashtags are needed, but this fits #SpringAI #Java