Show HN: Tokencap – Token budget enforcement across your AI agents

Token budget enforcement for AI agents. Hard limits, configurable policy, zero infrastructure required. - pykul/tokencap
7 points by pykul 201 days ago github.com 0 comments
Summary not yet generated for this article.

Original Text

I built this after hitting the same wall repeatedly — no good way to enforce token budgets in application code. Provider caps are account-level and tell you what happened, not what is happening.

Two ways to add it:

  # Direct client wrapper
  client = tokencap.wrap(anthropic.Anthropic(), limit=50_000)

  # LangChain, CrewAI, AutoGen, etc.
  tokencap.patch(limit=50_000)  
Four actions at configurable thresholds: WARN, DEGRADE (transparent model swap), BLOCK, and WEBHOOK. SQLite out of the box, Redis for multi-agent setups.

One design decision worth mentioning: tokencap tracks tokens, not dollars. Token counts come directly from the provider response and never drift with pricing changes.

Happy to answer any questions.

Comments (0 of ) ⌛

Loading more comments... ⌛
Scroll down to load more comments
No comments available.
Type to search HN and engineering blog articles
Press Escape to close  |  ↑↓ to navigate  |  Enter to open