Show HN: AgentBudget – Real-time dollar budgets for AI agents
Show HN (score: 5)Description
I built AgentBudget after an AI agent loop cost me $187 in 10 minutes — GPT-4o retrying a failed analysis over and over. Existing tools (LangSmith, Langfuse) track costs after execution but don't prevent overspend.
AgentBudget is a Python SDK that gives each agent session a hard dollar budget with real-time enforcement. Integration is two lines:
import agentbudget
agentbudget.init("$5.00")
It monkey-patches the OpenAI and Anthropic SDKs (same pattern as Sentry/Datadog), so existing code works without changes. When the budget is hit, it raises BudgetExhausted before the next API call goes out.How it works:
- Two-phase enforcement: estimates cost pre-call (input tokens + average completion), reconciles post-call with actual usage. Worst-case overshoot is bounded to one call. - Loop detection: sliding window over (tool_name, argument_hash, timestamp) tuples. Catches infinite retries even if budget remains. - Cost engine: pricing table for 50+ models across OpenAI, Anthropic, Google, Mistral, Cohere. Fuzzy matching for dated model variants. - Unified ledger: tracks both LLM calls and external tool costs (via track() or @track_tool decorator) in a single session.
Benchmarks: 3.5μs median overhead per enforcement check. Zero budget overshoot across all tested scenarios. Loop detection: 0 false positives on diverse workloads, catches pathological loops at exactly N+1 calls.
No infrastructure needed — it's a library, not a platform. No Redis, no cloud services, no accounts.
I also wrote a whitepaper covering the architecture and integration with Coinbase's x402 payment protocol (where agents make autonomous stablecoin payments): https://doi.org/10.5281/zenodo.18720464
1,300+ PyPI installs in the first 4 days, all organic. Apache 2.0.
Happy to answer questions about the design.
More from Show
Show HN: Gemini Plugin for Claude Code
Show HN: Gemini Plugin for Claude Code I built a plugin that lets Claude Code delegate work to Gemini CLI.<p>I started this after finding myself reaching for Gemini more often on long context repo work. I have been especially liking Gemini’s codebaseinvestigator for long context.<p>This is inspired by openai/codex-plugin-cc.<p>Code Review, adversarial review. Under the hood its Gemini CLI over ACP<p>Would love feedback from people using Claude Code, Gemini CLI, or ACP. I am especially curious whether this feels useful outside my own workflow.<p>Its a great combo with Opus 4.7 + Gemini 3.1 workflows
Show HN: gcx – The Official Grafana Cloud CLI
Show HN: gcx – The Official Grafana Cloud CLI Hi HN,<p>We’re excited to share gcx, a new CLI we’ve been building for Grafana Cloud.<p>With the rise of agentic coding tools like Claude Code and Codex we're building faster than ever, but these agents are often blind to what’s actually happening in production.<p>gcx brings the full power of Grafana Cloud observability to your terminal. Query production. Investigate alerts. Let the Assistant root-cause issues. Ship fixes with observability built in. Without leaving your editor. gcx also comes packaged with a skills bundle that allow agents to see and act on your production telemetry. You can ask an agent to root-cause a latency spike, and it can actually fetch the telemetry, analyze the spans, and suggest a fix—all while having the full context of your codebase.<p>Do check it out and give us feedback!<p>Github link: <a href="https://github.com/grafana/gcx" rel="nofollow">https://github.com/grafana/gcx</a>
No other tools from this source yet.