Skip to main content

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 BudgetExceededError before the call that would push spend over the limit.
  • Run-level attribution — groups all LLM calls inside one with block, tracks cost per run rather than per API call.
  • Per-call breakdownr.report.cost_by_call shows 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 with and is safe across asyncio.gather and asyncio.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

burnmap-0.1.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

burnmap-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file burnmap-0.1.0.tar.gz.

File metadata

  • Download URL: burnmap-0.1.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for burnmap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df459dd6f837d450834db9133160bffb1983f7b38350f61266cd8c448a5429ee
MD5 4080c866dd645c630f63f3002d47ea85
BLAKE2b-256 8ea8e7c7a044f0be637a2c238f26a506efd7f0648a39296b8733af9ed9f4b7fc

See more details on using hashes here.

File details

Details for the file burnmap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: burnmap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for burnmap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6b207a30b1bf9379647dc8e98db9db43d5dc8f972f0dac9fb6cb720cae6425c
MD5 cfb048460427e399e761ca11d165d8d1
BLAKE2b-256 ef1c1a56c520627d54ac327aa64a7143f0c7813e4fd4bbc706567e9265a514ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page