Show HN: AgentGuard – Auto-kill AI agents before they burn through your budget
42 dipampaul17 26 7/31/2025, 5:54:04 AM github.com ↗
Your AI agent hits an infinite loop and racks up $2000 in API charges overnight. This happens weekly to AI developers.
AgentGuard monitors API calls in real-time and automatically kills your process when it hits your budget limit.
How it works:
Add 2 lines to any AI project:
const agentGuard = require('agent-guard');
await agentGuard.init({ limit: 50 }); // $50 budget
// Your existing code runs unchanged
const response = await openai.chat.completions.create({...});
// AgentGuard tracks costs automatically
When your code hits $50 in API costs, AgentGuard stops execution and shows you exactly what happened.Why I built this:
I got tired of seeing "I accidentally spent $500 on OpenAI" posts. Existing tools like tokencost help you measure costs after the fact, but nothing prevents runaway spending in real-time.
AgentGuard is essentially a circuit breaker for AI API costs. It's saved me from several costly bugs during development.
Limitations: Only works with OpenAI and Anthropic APIs currently. Cost calculations are estimates based on documented pricing.
Source: https://github.com/dipampaul17/AgentGuard
Install: npm i agent-guard
It's an... intrusive solution. Glad to hear it works for you though.
See https://docs.litellm.ai/docs/proxy/users
When I want to try a new editor, vs code plugin or software, I only have to point it at my litellm proxy and immediately have access to all of my providers and models I’ve configured, no extra setup. It’s like a locally hosted openrouter that doesn’t charge you for routing. I can just select a different provider as easy as choosing the model in the software; switching from “openai/gpt-4o” to “groq/moonshotai/kimi-k2-instruct”, for example.
You can use litellm or OpenAI protocols which makes it compatible with most software. Add on ollama proxy and you can proxy ollama requests from software that doesn’t support specifying OpenAI’s base address but that does support ollama (a not uncommon situation). That combo covers most software.
So yes, to me it is absolutely worth running locally and as easy as editing a config file and starting a docker (or a shell script to open a venv and start litellm, if you prefer).
The only drawbacks I’ve found so far is that not all providers accurately respond with their model information so you sometimes have to configure models/pricing/limits manually in the config (about 5 lines of text that be copy/pasted and edited). All the SOTA models are pre-configured and kept relatively up to date, but one can expect updates to lag behind real pricing changes.
The UI is necessary if you want to set up api key/billing restrictions which requires a db, but that is rather trivial with docker as well.
And if this is really a problem, why not funnel your AI agents through a proxy server which they all support instead of this hacky approach? It would be super easy to build a proxy server that keeps track of costs per day/session and just returns errors once you hit a limit.
[1] LiteLLM: https://www.litellm.ai/
The README now matches what developers actually experience: two lines of code, automatic tracking, no code changes needed."
Hey OP - next time perhaps at least write the commit messages yourself?
[1] https://github.com/dipampaul17/AgentGuard/blob/51395c36809aa...
[2] https://github.com/dipampaul17/AgentGuard/commit/d49b361d7f3...
[3] https://github.com/dipampaul17/AgentGuard/blob/083ae9896459b...
It's kind of crazy that people use these multi-billion parameter machine learning models to do search/replace of words in text files, rather than the search/replace in their code editor. I wonder what the efficiency difference is, must be 1000x or even 10000x difference?
Don't get me wrong, I use LLMs too, but mostly for things I wouldn't be able to do myself (like isolated math-heavy functions I can't bother to understand the internals of), not for trivial things like changing "test" to "step" across five files.
I love that the commit ends with
> Codebase is now enterprise-ready with professional language throughout
Like "enterprise-ready" is about error messages and using "Examples" instead of "Demo".
> Polish README: Remove downloads badge and clean up styling
> - Removed downloads badge ___as requested___
> The foundation is bulletproof. Time to execute the 24-hour revenue sprint.
Comedy gold. This is one of those times where i cant figure out if the author is in on the joke, or if they're actually so deluded that they think this doesn't make them look idiotic. If it's the latter, we need to bring bullying back.
Either way it's hilarious.
It seems like he's still stuck in the "If I just say to my AI that I want a production-ready package that people will pay me $99/month for, I'll get it eventually, right?" phase of discovering LLMs.
The end-result is many commits saying "fixed all issues, enterprise-ready now as requested!" adding 500 lines of code causing more issues.
The funniest part, to me, is that this only damages his image, instead of solidifying it. We've had so many applicants at my company recently where we go to their github, and they have 10 repositories all obviously vibe-coded together, acting like they made some amazing stuff. Instant deletion of application, no coming back from that - this person would NOT get a job here.
If I was using something like this I think I'd rather have it wrap the AI API clients. Then it can throw an error if it doesn't recongise the client library I'm using. This way it'll just silently fail to monitor if what I'm using isn't in its supported list (whatever that is!)
I do think the idea is good though, just needs to be obvious how it will work when used and how/when it will fail.
While you are at it, use the term "guardrails" as that is quite fashionable.