0.6.0 is published, and main now ships an opt-in priced spend ledger
Read the ledger ↗Backpressure, hard budget enforcement, circuit breaking, and a priced, attributed spend ledger for multi-agent workflows. Intercepts transport calls directly inside your runtime without routing prompts through third-party servers.
A terminal capture of one command. backstop ledger demo prices 1,967 fixed requests per team and per feature from the bundled rate card, with no API key, no network call and no file — run it yourself and you get the same bytes back. 69 of those requests declared no team and no feature, so $1.54 of the $34.56 — 4.45% of priced spend — belongs to nobody, and it is printed as a row instead of dropped. Another 34 sit on a model the rate card does not carry, so their cost is absent rather than zero. A CFO trusts a number that names its own gaps.
The traffic is synthetic and fixed, so the request counts are a scenario and the dollars are exact only for that volume under a rate card dated 2026-09-26. It is a rendered capture, not a screen recording: every figure on it is either a real fact from the repository or a labelled scenario number. The capture above stops at Backstop's own arithmetic — it is a ledger, not a statement, so it cannot tell you whether you were actually billed that. For that there is backstop reconcile, which reads a provider statement file and reports the variance per model, with a model it has no rate for shown as unpriced rather than guessed. It has been checked against synthetic statements only: no real provider statement has been run through it yet.
Priority-aware admission. Protects interactive user chats by queueing and admitting requests in priority order — critical, then default, then background. Nothing is dropped; a starved ticket is released by a timer.
Hard deterministic spend caps per agent loop, worker thread, or customer tenant. Trips locally in microseconds to stop runaway $4,000 billing loops.
Automated 429 outage defense. Prevents catastrophic retry storms by tripping locally, executing instant zero-latency fallbacks, and canary probing.
Prompts and secrets never leave your runtime memory. Direct in-process connection with zero intermediate 3rd-party servers, logging proxies, or DNS overhead.
Adjust incoming traffic QPS and simulate sudden multi-agent traffic spikes.
Hosted reverse proxies (Cloudflare AI Gateway, Portkey, LiteLLM) force every LLM call to make an extra cloud roundtrip (adding 30–60ms of overhead). Backstop runs in-process with a microsecond-level CPU check before making a direct TLS connection.
Passing user prompts, chat histories, and master provider API keys through a third-party gateway creates unnecessary compliance liability and outage risk. Backstop requires zero external credentials and transmits zero telemetry off-box.
The admission gate queues requests once the concurrency limit is reached and admits them in priority order — critical, then default, then background — with a starvation valve so an old low-priority ticket is never left waiting forever. It does not drop or cancel background work. What actually stops a request before it reaches the network is the hard token budget ceiling, which raises BudgetExceededError, and the circuit breaker, which fails fast with CircuitBreakerOpenError while the provider is unhealthy.
from openai import OpenAI
from backstop import Backstop, BackstopConfig
from backstop.exceptions import BudgetExceededError
# Wrap a standard client in-process — zero proxy hop, zero egress
client = Backstop.wrap(
OpenAI(),
budget=50_000, # hard token ceiling for this session
config=BackstopConfig(initial_concurrency=4),
)
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)
except BudgetExceededError:
print("Budget hit — no runaway loop possible.")
Left figure: 0.07 ms control-path overhead, identical at p50, p95 and p99 in the one snapshot the repo commits — 1,000 requests through a local httpx.MockTransport, no network, seed 0x00C0FFEE, recorded 2026-07-20. That snapshot records no CPU, OS, Python or SDK version, so read it as one recorded run, not a guarantee; re-measure with backstop benchmark. Right figure: a modelled breakdown of one remote hop, not a measurement of any named gateway.
{
"layer": "in_process",
"budget_check": "PASS ($0.042 / $5.00 limit)",
"backpressure": "ADMITTED (tier 1)",
"circuit_breaker": "CLOSED (healthy)",
"proxy_hop_latency_ms": 0.00
}When AI providers return 429s or 503s, raw SDKs trigger retry storms that amplify the outage. Backstop trips in-process and fails fast with CircuitBreakerOpenError before dispatch, instead of sending more work to a provider that is already failing.
Every agentic session and background loop is bounded by a hard local token and cost ceiling. Backstop fails closed in-process, preventing unexpected five-figure API invoices.
Enforcement stops a runaway loop. It does not tell anyone which team spent the money. Opt in with one config field and every completed provider request appends a priced, attributed record to a file you own. A CFO trusts a number that names its own gaps, so the gaps are columns beside the money, not a footnote.
# Backstop Ledger — Chargeback
- **1967 requests** on 2026-09-26 (day 2026-09-26), priced from the bundled rate card effective **2026-09-26** (`price_source=bundled`).
- **Window:** 2026-09-26T00:00:00.000000Z → 2026-09-26T23:59:28.002464Z
- **Grouped by:** team, feature
- **Models:** claude-haiku-4-5, claude-sonnet-4-20250514, gpt-4.1, gpt-4o, vendor-preview-2027
- **Mode:** 100% offline. No API key, no network call, no live provider data, no file. The traffic is synthetic and fixed; every price and every dollar is computed from the bundled rate card with `Decimal` arithmetic.
| team | feature | request_count | input_tokens | output_tokens | total_usd | unpriced_requests | unpriced_components |
| --- | --- | ---: | ---: | ---: | ---: | ---: | --- |
| payments | checkout-v2 | 388 | 8532297 | 278259 | 26.21 | 0 | cache_write |
| payments | refunds | 96 | 520529 | 101931 | 3.40 | 0 | (none) |
| support | triage | 240 | 516754 | 87934 | 1.76 | 0 | (none) |
| search | query-rewrite | 1140 | 741077 | 165354 | 1.65 | 0 | (none) |
| (unattributed) | (unattributed) | 69 | 396310 | 39882 | 1.54 | 0 | (none) |
| search | vendor-preview | 34 | 82143 | 11300 | 0.00 | 34 | (none) |
| **Total** | all | 1967 | 10789110 | 684660 | **34.56** | 34 | cache_write |
## What a CFO reads first
- **1.54 of 34.56 (4.45%) of priced spend is unattributed** — 69 of 1967 requests declared no `team` and no `feature`, so nobody can be charged for that money. It is one row in the table, labelled `(unattributed)`, and it is the row a pivot table drops. The share is computed on the exact totals — 1.539061 of 34.547570 to six decimal places — so dividing the rounded dollars above will not reproduce it exactly.
- **34 requests (1.73%) have no price at all** — `vendor-preview-2027` is not in the rate card. Their cost is *absent, not zero*, so every total above understates real spend by an unknown amount. A guess would make the number wrong in a way nobody could detect; this one is wrong in a way everybody can.
- 1 token component carries no published rate in this window (`cache_write`), so the requests that used it are charged zero for it and every affected row names the gap. Those lines are a floor, not a measurement. 9 of 1967 requests carry tokens Backstop estimated locally because the provider reported no usage, so their cost is a floor too. That count and the unpriced one are not disjoint: a request that is both estimated and unpriced is in each, and its cost is absent rather than a floor, which is the weakest figure in this report.
## Delivery (this process)
- submitted: 1967
- written: 1967
- landed (written less the sink's own losses): 1967
- dropped_events (writer buffer full): 0
- writer sink_errors (escaped the sink): 0
- sink sink_errors (counted by the sink): 0
- sink degraded: no
- **lost (dropped + writer errors + sink errors): 0**
This run lost **0** of 1967 events, counted from the live writer. Both counters matter and neither is written to a ledger file: a file read reports them as unknown rather than as zero.
## Joined against your revenue
Backstop does not become a revenue system. You key your own revenue on the same group tuple and the join shows the margin — with a visible `(none)` for any group missing on either side, never a silent zero. Here two groups are missing on purpose: `research/long-context` has revenue and no spend in this window, and `search/vendor-preview` has spend and no revenue here.
```csv
team,feature,request_count,total_usd,revenue_usd,margin_usd,match,currency
payments,checkout-v2,388,26.21,148230.00,148203.79,both,USD
payments,refunds,96,3.40,41200.00,41196.60,both,USD
support,triage,240,1.76,96450.00,96448.24,both,USD
search,query-rewrite,1140,1.65,78500.00,78498.35,both,USD
(unattributed),(unattributed),69,1.54,(none),(none),cost_only,USD
research,long-context,(none),(none),12000.00,(none),revenue_only,USD
search,vendor-preview,34,0.00,(none),(none),cost_only,USD
```
## Get this out of your own ledger
```bash
backstop ledger demo # this table, offline
backstop ledger show --path ledger.jsonl # integrity + chargeback
backstop ledger export --path ledger.jsonl --out chargeback.csv \
--group-by team,feature
```
### What is not shown here
- The requests are synthetic, so the *volume* is a scenario. The *dollars* are exact for that volume under the bundled rate card.
- The rate card is a snapshot dated 2026-09-26. A negotiated price belongs in a catalog file or a per-call override, and outranks it.
- One day of one shape is not a trend. Read `unpriced_requests` and `unpriced_components` before you read the total, and group by `customer` or `cost_center` if those are how you bill.One frozen, validated record per completed provider request: provider, model, normalised endpoint, priority, outcome, four token counts, latency, retries, your attribution and a priced cost breakdown. An unknown key and a missing key are both errors naming the offender, so a truncated line cannot reload as plausible data.
team, agent, session, task, feature, surface, customer, tenant, environment, repo, cost_center, gl_code, currency. You declare who is spending once, at the top of the function that spends it. Scopes merge, the outer value is restored on exit, and a process that declares nothing records an all-None attribution rather than a guess.
with attribution(team="payments",
feature="checkout-v2"):
client.chat.completions.create(...)Every amount crosses the wire as a string, never a JSON number, because a JSON number comes back as a binary float and a finance export that loses cents is worse than one that is awkward to parse. The CSV renders money to two decimals in a stable column order.
A model missing from the rate card yields cost=None and a counted unpriced_requests. There is no default rate and no neighbouring-model fallback, because a chargeback that is quietly wrong is worse than one that is absent. The 34 requests in the vendor-preview row above are counted; their dollars are absent.
Each signal is a record. It cannot block a request, cancel work, kill an agent, or raise — that is structural, not a promise, and a test walks the public API for a verb that could. Auto-kill is absent on purpose: a legitimate agent run can be six hours of work, and a kill switch that cannot resume destroys it. Shadow mode means the same signals are also filed and counted, so a threshold can be tuned against evidence before it can interrupt anybody.
Enforcement, with the ledger off — the default — is the 0.07 ms control path above. The ledger is not free, and the number is measured rather than promised: with the ledger on a request roughly doubles in cost, around +130 to +147 microseconds p50 on a ~150 microsecond request, over 7 alternating runs on Python 3.12.3 and Linux, with the ledger off at +3 to +5 microseconds. An agent LLM call takes seconds, so this is invisible in practice. It is still larger than the library's entire advertised overhead budget, and the honest claim is that we publish it.
Why external API gateways break the latency contract for multi-agent loops. Detailed breakdown of local token buckets, socket pool exhaustion, and in-process 429 backoff with circuit breaking.
“How a recursive code refactor agent hit an unhandled git merge exception, retried in a tight parallel loop across 32 threads, and spent thousands before human alerting fired.”
“Exponential backoff without distributed circuit breaking produces synchronized waves of retry requests that prolong upstream model provider incidents.”
Everything you need to know about in-process AI backpressure, budgets, and circuit breaking.