How llm-cost-shield works
An app with an AI feature has no brakes by default. One user stuck in a loop or one bot hammering your chat widget can spend a month’s budget overnight. And most apps pay full price to answer the same questions again and again.
llm-cost-shield wraps your model calls with budgets per day, per user and per feature, stops retry and agent loops, caches identical requests, and can route simple prompts to a cheaper model. It reads the real token usage that OpenAI, Anthropic, Gemini, Bedrock, OpenRouter and the Vercel AI SDK return, including cache reads and writes, thinking tokens and long-context rates.
The analyzer reads your usage logs and shows cost by model, feature and user, how much repeated requests cost you, what moving small requests to a cheaper model would save, how much goes to thinking tokens, whether prompt caching actually saves money, and which users or loops look abnormal. Fewer tokens also means less compute and energy.
Try it
npx llm-cost-shield analyze usage.jsonl --prices prices.json
Free and open source under the MIT license. Want this done for your store, or need help with the findings? Book a call.