Budget enforcement for LLM agents
Project description
Burnmap
Budget enforcement for LLM agents. One line of code, no proxy, hard-stop before costs spiral.
Install
pip install burnmap
# with SDK support
pip install "burnmap[anthropic]"
pip install "burnmap[openai]"
pip install "burnmap[all]"
Quickstart
import burnmap
with burnmap.run("auth-refactor", budget=2.00) as r:
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Refactor the auth module"}],
)
print(r.report.summary())
# Run 'auth-refactor' completed in 1.23s. 1 call(s), $0.0842 of $2.00 budget...
If spend hits the budget limit, BudgetExceededError is raised before the next call executes:
from burnmap import BudgetExceededError
try:
with burnmap.run("agent-loop", budget=0.50) as r:
while True:
client.messages.create(...) # raises BudgetExceededError at the limit
except BudgetExceededError as e:
print(f"Stopped at ${e.spent_so_far:.4f} after {e.call_count} calls")
Per-user budget enforcement for multi-tenant products:
with burnmap.run("summarise", budget=0.10, user_id="usr_123"):
client.messages.create(...)
CLI — wrap any agent command
burnmap wrap --budget 5.00 --job "auth-refactor" -- claude --dangerously-skip-permissions "refactor auth"
burnmap wrap --budget 10.00 -- python my_agent.py
Burnmap scans the subprocess output for API usage JSON, accumulates cost in real time, and kills the process if spend exceeds --budget. Prints a cost summary on exit.
What it does
- Hard-stop budget enforcement — raises
BudgetExceededErrorbefore the call that would push spend over the limit. - Run-level attribution — groups all LLM calls inside one
withblock, tracks cost per run rather than per API call. - Per-call breakdown —
r.report.cost_by_callshows each call's model, tokens, cost, and running total. - Loop detection — kills runaway agents that are hammering the API or accumulating context geometrically.
- Async-native — works with
async withand is safe acrossasyncio.gatherandasyncio.create_task.
What it doesn't do
- No proxy. API calls go directly from your code to Anthropic/OpenAI. No latency added, no single point of failure, API keys stay local.
- No dashboard (yet). Cost data lives in
r.report— export it however you like. - Does not intercept calls made outside a
burnmap.run()block.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file burnmap-0.2.0.tar.gz.
File metadata
- Download URL: burnmap-0.2.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13d8b6c0b7a1f75546875a1b77e3bcbd39cbce5b06a3c956418b17840b81b332
|
|
| MD5 |
13ed1e12855eb5c59a32ddf5fd953ec1
|
|
| BLAKE2b-256 |
39dbe6d69392f7cb3a80e485980b4564a6417f03df263c7196384e2633fa59df
|
File details
Details for the file burnmap-0.2.0-py3-none-any.whl.
File metadata
- Download URL: burnmap-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71f526031236d9660f4e594b23d9db8bbccf29f46f70c7b714c8a4016ad08a2c
|
|
| MD5 |
ed3275aee744c5d34e679463f65e5dbd
|
|
| BLAKE2b-256 |
4348584381bde392fd5053fef7a97a4865c353b2c16b0c792901a652dd8d0f50
|