frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

An LLM API gateway with budget-limited tokens for your LLM API keys

https://github.com/er91/budget_aware_llm_api_gateway
1•endlessroad1991•17h ago

Comments

endlessroad1991•17h ago
[Originally intended as a Show HN post, but my account is not eligible for posting Show HN post yet, so posting as normal content instead.]

Motivation: I have read quite a few stories about people's LLM API keys get uploaded verbatim in git repos, get stolen, or go unexpectedly over-budget. Being a panic-y person myself, I was thinking what we can do for those problems.

Before you read any further: only after I finished this whole thing, I found out that LiteLLM has this "virtual key" concept, and virtual key already comes with budget control. That actually implements the same thing as I did (with way more API endpoint support and other functionalities). So if you are already using LiteLLM or want to use LiteLLM, you can stop reading now and just use LiteLLM. However, LiteLLM has grown quite complicated: production deployment involves compute + database + secret manager, whereas my implementation is a serverless Cloudflare workers project, which can be hosted completely free (the free quota is more than enough at least for my personal use). If you are still interested, read on.

Solution: put real API key in an LLM API gateway, so your git repos/coding agents cannot even see the real API key. Instead, we create temporary, budget-scoped "tokens" in the LLM API gateway, and use coding agents with those tokens. The gateway will only let requests through and supply the real API key if the token has not expired, and has not exceeded its budget limit. This way, if our development machine is compromised, or coding agent gets into an infinite loop, our loss is limited (the token's budget limit) [1]. I mostly use DeepSeek/Claude for my side projects. Now everyday I create a new DeepSeek token with $1 budget and keep coding with the peace of mind knowing that I will only use (a bit more than) $1 for the day. Or before I hand off a complicated task to Claude, I will create a token with a fixed budget, and then sleep peacefully without worrying my API cost exploding.

Technical detail: the gateway splits response stream into two: one is forwarded to client directly, so clients still get streaming output like before; the other one is used to extract usage information from the response, calculate the cost, and update token budget.

Supported API endpoints: it works with official DeepSeek/OpenAI/Anthropic API endpoints. For coding agents (e.g. Codex, Claude Code, OpenCode), you will need to: point them to the gateway, create a new token in the gateway, and use your token as API key.

Compare with existing products: - LiteLLM: 1. This is a much smaller subset of what LiteLLM provides; this simplicity can let you easily audit the full source code. 2. Zero infra to operate: no VM to patch, no database server to maintain, no secret manager to set up; just upload worker code to Cloudflare. 3. Cloudflare provides sufficient free quota for personal use. - Cloudflare AI Gateway: Cloudflare AI gateway's budget control is static policies applied to a fixed time window (e.g. $1 every day). My implementation is more flexible: you can create a new budget limited token at any time, with any budget limit. My hope is that Cloudflare AI gateway just implements this, so I don't need to maintain my implementation :-)

Since this project uses your API keys, please audit/review the code before using it. Github: https://github.com/er91/budget_aware_llm_api_gateway

Reddit: https://www.reddit.com/r/opencodeCLI/comments/1uwwb2n/wrote_...

[1]: Note that the budget limit is NOT 100% reliable, because 1. we only check remaining budget at the beginning of an incoming request, so one large request or concurrent requests can both go over budget; 2. budget calculation and update might fail silently.

Show HN: Vidmoat – a video editing pipeline any AI agent can operate

https://www.vidmoat.com/
1•fredabila•21s ago•0 comments

Jacobian conjecture was proven for 3D, Math seems to be distraction however

https://abhishek-shankar.com/posts/the-zero-discount-claim
1•catstyler•2m ago•0 comments

Show HN: PounceDomains – Domain discovery and sniping for Namecheap Marketplace

https://pouncedomains.com
1•DotSauce•2m ago•0 comments

Linux Now Runs on the Atari Jaguar, a 1993 Console with Just 2 MB of RAM

https://linuxiac.com/linux-now-runs-on-the-atari-jaguar-a-1993-console-with-just-2-mb-of-ram/
1•cable2600•4m ago•0 comments

The road to epsilon-zero: ordinals as Nim-heaps

https://blog.plover.com/math/ordinals/01-nim.html
1•pavel_lishin•6m ago•0 comments

Why Andrew Tate Is a MAGA Superstar

https://www.thenation.com/article/society/andrew-tate-arrest-maga-connection/
1•petethomas•9m ago•0 comments

AI just disproved a major math problem. A mathematician explains

https://mashable.com/tech/anthropic-fable-5-disproves-jacobian-conjecture
1•01-_-•12m ago•1 comments

Secrets Don't Belong in Config

https://secretspec.dev/blog/secrets-dont-belong-in-config/
1•domenkozar•12m ago•0 comments

AI's most important protocol is getting a little bit easier to use

https://techcrunch.com/2026/07/20/ais-most-important-protocol-is-getting-a-little-bit-easier-to-use/
1•haritha1313•13m ago•0 comments

Bdinfo-rs – Rust cross-platform Blu-ray analyzer (GUI and CLI and WASM)

https://github.com/agentjp/bdinfo-rs
1•hyperslop•14m ago•1 comments

The $100M Mistake Making Modern Movies Look So Cheap

https://comuniq.xyz/post?t=1415
1•01-_-•16m ago•0 comments

Wp2shell: First Critical Unauthenticated WordPress Core RCE in Nearly a Decade

https://www.wordfence.com/blog/2026/07/wp2shell-aftermath-the-first-critical-unauthenticated-word...
1•computer23•18m ago•0 comments

How Google's A.I. Search Is Imperiling the Open Web

https://www.nytimes.com/2026/07/20/technology/google-ai-open-web.html
1•mikhael•20m ago•0 comments

Wax On, Weights Off: Knowledge Distillation Explained

https://jdsemrau.substack.com/p/knowledge-distillation-attacks
2•ph4rsikal•22m ago•0 comments

Ask HN: How are you interviewing engineers in this agentic era?

3•jcgr•23m ago•1 comments

Google plans new chip to run Gemini models more efficiently

https://www.reuters.com/business/google-plans-new-chip-run-gemini-models-more-efficiently-informa...
1•alach11•23m ago•1 comments

GitHub Code Quality is now generally available

https://github.blog/changelog/2026-07-20-github-code-quality-is-now-generally-available/
1•andsoitis•23m ago•0 comments

Twitch, but for Running

https://kailo.fit/products/live-stream
2•steadyelk•27m ago•0 comments

Trump admin launches its first major H-1B visa fraud investigation

https://www.foxbusiness.com/politics/trump-admin-launches-its-first-major-h-1b-visa-fraud-investi...
1•rawgabbit•28m ago•0 comments

Show HN: A chess game you play with Claude as your wing-bot in the CLI

https://github.com/goawaygeek/ground-control
1•goawaygeek•28m ago•0 comments

How Does an LLM Request and Response Cycle Work? A Full Walkthrough

https://qainsights.com/how-does-an-llm-request-and-response-cycle-work-a-full-walkthrough/
2•qainsights•31m ago•1 comments

Probabilistic computing is here; here is how it works

https://www.eetimes.com/probabilistic-computing-is-already-here-here-is-how-it-works/
1•teleforce•31m ago•1 comments

Sealed secret execution for AI agents

https://ironrun.dev/
1•skeehn•36m ago•0 comments

The Yarn Spinner Public License

https://yarnspinner.dev/yspl
1•mintplant•37m ago•0 comments

The Telegarden (1995-2004)

https://goldberg.berkeley.edu/garden/
1•zetamax•39m ago•0 comments

Delayed Boeing jets only fit for baked bean tins, Emirates boss says

https://finance.yahoo.com/technology/articles/delayed-boeing-jets-only-fit-162341761.html
8•devonnull•40m ago•1 comments

Claude Pro subscribers get $100 promotional credit for Fable 5

https://old.reddit.com/r/ClaudeAI/comments/1uzjhhn/fable_so_100_credit_for_pro_user/
1•JumpCrisscross•47m ago•2 comments

Now on the American Road: Bulletproof Cars

https://www.nytimes.com/2026/07/20/style/armored-cars-bulletproof-american-drivers.html
3•cdrnsf•51m ago•0 comments

Show HN: Relay – a self-hosted LLM gateway with eval-gated routing

https://github.com/llmrelay/relay
1•olopadef•51m ago•0 comments

The Fedora project grapples with change

https://lwn.net/SubscriberLink/1081557/cde56e450fe4bf10/
2•chmaynard•52m ago•0 comments