git404hub

what is llm-budget-cap fr?

rentheria/llm-budget-cap — explained in plain English

Analysis updated 2026-07-25

1TypeScriptAudience · developerComplexity · 2/5Setup · moderate

tl;dr

A TypeScript package that enforces hard spending limits on AI API calls using Redis, preventing unexpected bills from bugs or abuse. It tracks usage with an atomic counter that stops requests once a daily or custom budget is exceeded.

vibe map

mindmap
  root((repo))
    What it does
      Hard spending caps
      Blocks AI calls over limit
      Per-user or per-tenant limits
    How it works
      Redis counter
      Lua script for safety
      Configurable time windows
    Use cases
      Stop runaway AI bills
      Multi-tenant budget control
      Protect against API abuse
    Tech stack
      TypeScript
      Redis
      Express Fastify NestJS
    Audience
      Backend developers
      Teams using AI APIs
      Cost-conscious startups

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

what do people make with this?

VIBE 1

Cap daily AI API spending to a fixed dollar amount to prevent runaway bills.

VIBE 2

Set per-user or per-tenant limits so one customer cannot exhaust your entire AI budget.

VIBE 3

Protect your application from billing spikes caused by bugs, loops, or distributed abuse.

what's the stack?

TypeScriptRedisExpressFastifyNestJS

how it stacks up fr

rentheria/llm-budget-cap0xkinno/neuralvault0xmayurrr/ai-contractauditor
Stars111
LanguageTypeScriptTypeScriptTypeScript
Setup difficultymoderatehardeasy
Complexity2/54/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

how do i run it?

Difficulty · moderate time til it works · 30min

Requires a running Redis instance and an existing Redis client connection to function.

No license information was provided in the explanation, so usage terms are unclear.

in plain english

{"i": 0, "repo": "Rentheria/llm-budget-cap", "stars": 1, "lang": "TypeScript", "ok": true, "char_count": 2847, "text": "llm-budget-cap is a small TypeScript package that puts a hard spending limit on calls to AI services like OpenAI, Gemini, and Anthropic. The core problem it addresses is real and practical: a bug, a loop, or abuse from many IP addresses can spike an AI bill to thousands of dollars overnight. Existing rate limiters that throttle per IP do not help when an attacker is spread across many addresses. This package provides a single hard counter that cuts off spending once a limit is reached.\n\nThe way it works is simple from the user's side. You create a BudgetCap object with a Redis connection, a key name, and a limit (say, 500 calls per day). Before you make a paid AI API call, you run checkAndIncrement. If the limit is exceeded, the method tells you to block the request. You can also set per-user or per-tenant limits by passing a subKey, and you can configure the time window to any length in milliseconds.\n\nThe technical detail that sets this package apart is how the counter works inside Redis. A naive approach reads the count, checks it, and writes the new count in separate steps. Under high traffic, two requests can both read the same count at the same time, both pass the check, and both proceed, letting one extra call through. To prevent this, the package runs the increment and the expiration timer inside a single Lua script. Redis executes that script start to finish without interruption, so no two requests can slip through at the boundary.\n\nBy default, if Redis goes down, the package lets requests through in a degraded mode rather than blocking your entire feature. You can change this to fail closed if you prefer. The package has zero third-party dependencies beyond the Redis client you already use, and works with Express, Fastify, NestJS, or any other framework. The full README is longer than what was shown.", "error": null}

prompts (copy fr)

prompt 1
Help me integrate llm-budget-cap into my Express app so that OpenAI API calls are blocked after 500 requests per day. Show me how to set up the BudgetCap with Redis and call checkAndIncrement before each AI request.
prompt 2
I want to use llm-budget-cap to enforce a separate daily limit for each tenant in my multi-tenant SaaS app. Write a middleware that creates a BudgetCap with a subKey for each tenant ID and blocks requests when their limit is hit.
prompt 3
Explain how llm-budget-cap uses a Lua script in Redis to prevent race conditions where two requests pass the budget check at the same time. Show me a code example of the checkAndIncrement pattern.
prompt 4
Configure llm-budget-cap to fail closed instead of letting requests through when Redis is unavailable, so that no AI calls bypass the budget during a Redis outage.

Frequently asked questions

what is llm-budget-cap fr?

A TypeScript package that enforces hard spending limits on AI API calls using Redis, preventing unexpected bills from bugs or abuse. It tracks usage with an atomic counter that stops requests once a daily or custom budget is exceeded.

What language is llm-budget-cap written in?

Mainly TypeScript. The stack also includes TypeScript, Redis, Express.

What license does llm-budget-cap use?

No license information was provided in the explanation, so usage terms are unclear.

How hard is llm-budget-cap to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is llm-budget-cap for?

Mainly developer.

peek the repo → explain another one

This repo across BitVibe Labs

double-check against the repo, no cap.