Skip to main content

Burnwatch SDK: mirror your AI agent's payments to Burnwatch for spend monitoring.

Project description

Burnwatch SDK

Observe-only spend monitoring for autonomous AI agents.

Your agents pay for APIs, tools, and services on their own, over x402 or stablecoins. A bug, a runaway loop, or a prompt injection can drain funds fast. Burnwatch learns each agent's normal spend and alerts you the moment something looks wrong. It never holds your keys and never sits in the payment path.

PyPI Python License: MIT

Burnwatch catching a hijacked agent in real time

Why this SDK is open

Burnwatch is monitoring you bolt onto an agent that spends real money, so you should be able to read exactly what it does. This SDK is the only part of Burnwatch that runs inside your process, and it is deliberately tiny:

  • Stdlib-only. Zero dependencies. A monitor must never add weight or a new supply-chain surface to your agent.
  • Observe-only. It mirrors payment metadata outbound. It never holds keys or funds and never sits in the payment path.
  • Fail-open. Recording is async and batched, and a transient outage re-queues events rather than dropping them (bounded buffer). If Burnwatch is unreachable, your agent keeps paying as normal. Monitoring can never break the thing it monitors.

The cloud backend that learns baselines and runs detection is a separate, source-available product. The detection logic itself is documented in full in DETECTION.md, so nothing about how alerts fire is a black box.

Install

pip install burnwatch

Quick start

Call record() after each payment your agent makes:

from burnwatch import BurnwatchClient

with BurnwatchClient(endpoint="https://app.burnwatch.dev", token="bw_your_token") as bw:
    bw.record(
        agent_ref="agent_7f3c",          # stable id for this agent
        agent_name="research-bot",       # optional; used when auto-provisioning
        amount=0.002,
        recipient="api.weather.dev",     # payee, endpoint, or address
        resource="GET /forecast",        # optional, for richer alerts
        rail="x402",
        currency="USDC",
        context={"tx_hash": "0xabc...", "chain_id": "eip155:8453"},  # optional, public only
    )

Get an ingest token at app.burnwatch.dev under Settings -> Collector setup.

x402 wrapper

If you pay over x402, wrap your existing client and let Burnwatch mirror metadata automatically:

from burnwatch import BurnwatchClient, X402Monitor

with BurnwatchClient(endpoint="https://app.burnwatch.dev", token="bw_...") as bw:
    mon = X402Monitor(bw, agent_ref="agent_7f3c", agent_name="research-bot")
    resp = mon.paid_get(x402_client.get, "https://api.weather.dev/forecast", max_amount=0.01)

Or mirror manually after your own client returns:

resp = x402_client.get(url, max_amount=price)
mon.after_payment(resp, recipient=url, resource="GET /forecast")

See examples/ for runnable demos.

What gets sent (and what never does)

Each record() call queues one JSON object like this:

{
  "agent_ref": "agent_7f3c",
  "agent_name": "research-bot",
  "amount": 0.002,
  "recipient": "api.weather.dev",
  "resource": "GET /forecast",
  "currency": "USDC",
  "rail": "x402",
  "status": "paid",
  "ts": "2026-06-23T15:55:01+00:00",
  "context": { "tx_hash": "0xabc...", "chain_id": "eip155:8453" }
}

Never sent: private keys, mnemonics, seeds, raw signatures, request or response bodies, or anything else from inside your agent. context is for public identifiers only (tx hashes, chain ids, facilitator names). The backend rejects payloads containing known secret-shaped keys.

You can read the entire transmit path in burnwatch/client.py. It is about 130 lines.

What Burnwatch detects

After a short warm-up per agent (roughly 20 payments to learn "normal"), 13 transparent rules watch every payment:

Rule Catches
Spend velocity Burn rate spiking far above the agent's baseline
Drain burst Many payments or a large total in a short window
Unknown counterparty A payee never seen during baseline
Off-pattern destination A new kind of payee (e.g. a wallet where it only paid APIs)
Amount spike A single payment far above the agent's usual size
Off-hours spend Activity in hours the agent is normally quiet
New rail A payment rail not seen before
Recipient concentration One payee suddenly dominating spend
Counterparty velocity Rapid repeated payments to the same payee
Asset anomaly A token or asset not seen during baseline
Daily budget exceeded Cumulative daily spend over a configured cap
Blocklist match A payment to a blocked recipient
Allowlist violation A payment outside a strict allowlist

Every alert ships with explainable evidence (the exact numbers and thresholds that tripped). The full logic and evidence schema for each rule is in DETECTION.md.

Every alert ships with the evidence

Turn alerts into action (optional)

Burnwatch is observe-only on purpose: it never sits in your payment path and never holds your keys, so it can't slow or break your agent. To make a detection do something automatically, point a webhook (dashboard -> Settings -> Alert delivery) at a small receiver that pauses or de-funds the agent. examples/killswitch.py is a complete, stdlib-only one you can copy.

Client reference

BurnwatchClient(endpoint, token, *, flush_interval=2.0, max_batch=100, timeout=3.0, enabled=True)

Method Purpose
record(...) Queue one payment. Non-blocking, never raises.
flush() Send buffered events now.
close() Stop the flusher and send anything buffered.

Use it as a context manager (with BurnwatchClient(...) as bw:) and close() is handled for you. Set enabled=False to make every call a no-op (handy for tests or local runs).

Links

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

burnwatch-0.1.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

burnwatch-0.1.2-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file burnwatch-0.1.2.tar.gz.

File metadata

  • Download URL: burnwatch-0.1.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for burnwatch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1534d9d216ffe79bc16c151dac917ecd29e0e6c71d67e916942854aae0be688c
MD5 2b1bd9a8f8d3510d646d8e8ef2342ae7
BLAKE2b-256 c5b07888bfe3390ad3184c335ff6887f882a43b21fe5d41b3d6301ae15c755b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for burnwatch-0.1.2.tar.gz:

Publisher: publish.yml on tsouth89/burnwatch-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file burnwatch-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: burnwatch-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for burnwatch-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 accaa460e860735b7082a207542fd3e475c92bc3bc7bc38579ba33f33dd2b3dd
MD5 ae777faa08e17e5902e34d9bc5a8e1a2
BLAKE2b-256 6c9c8b62a3de3b794e98ad41e64faff52f8824fb3250422b90f1ff913a9d78e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for burnwatch-0.1.2-py3-none-any.whl:

Publisher: publish.yml on tsouth89/burnwatch-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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