BudgetGuard context manager and actguard transparently counts tokens and USD spend in real time, raising BudgetExceededError the moment a limit is hit.
Installation
Quickstart
ContextVar, so it is isolated per async task and per thread.
Key features
- Token and USD limits: set one, the other, or both.
- Zero code changes to LLM calls: patch is applied once when entering the
withblock. - Streaming support: usage is captured from final stream chunks; stream contents are untouched.
- Async support:
BudgetGuardis both a sync and async context manager. - Multi-provider: OpenAI, Anthropic, Google Generative AI out of the box.
- Context-var isolation: nested or concurrent guards do not interfere.
- Tool guards:
rate_limit,circuit_breaker,max_attempts,timeout,idempotent, plusprove/enforcechain-of-custody decorators. - Gateway-ready: optionally report tool checks to the ActGuard platform.
How it works
Next steps
- Getting Started - installation options and first examples
- Core Concepts - limits, context isolation, streaming, and tool runtime context
- Tool Guards - rate limiting, circuit breaker, max attempts, timeout, idempotency, chain-of-custody, and framework integrations
- Integrations - provider-specific notes and requirements
- API Reference - full API and exception reference
