Backstop
Reference

CLI Reference

Full reference for the backstop and wedge console commands.

Backstop installs two console commands: backstop and wedge. Most commands run offline with a mock provider — no API key required.

CommandPurpose
backstop verifyReproducible proof that enforcement works
backstop demoSide-by-side runaway loop comparison
backstop doctorValidate your install and environment
backstop harnessRun a load scenario against a mock provider
backstop benchmarkRun the deterministic benchmark suite
backstop serveRun as an OpenAI-compatible gateway/sidecar
backstop metricsStart a Prometheus metrics server
backstop dashboardServe the built-in operations dashboard
backstop real-openaiReal OpenAI API smoke test
backstop real-anthropicReal Anthropic API smoke test
backstop ledger demoPriced chargeback from fixed, offline events. No key, no network, no file
backstop ledger showA JSONL ledger's integrity report, then its chargeback
backstop ledger exportWrite a chargeback CSV from a JSONL ledger

backstop verify

Proves the guardrail works end-to-end using a local mock transport. Expect 8/8 checks to pass in under 5 seconds, with zero network and zero API keys.

backstop verify

Options:

FlagDefaultDescription
--liveoffAlso probe the real provider (GET /models). Validates key existence only.
--offlineonNever touch the network (default).
--strictoffTreat warnings as failures (for CI).
--jsonoffEmit JSON instead of human-readable text.
--provideropenaiProvider to simulate: openai or anthropic.
--model—Model identifier for the simulated request.
--base-url—Override provider base URL for the live probe.
--api-key-envOPENAI_API_KEYEnv var holding the provider key.
--timeout30.0Per-check timeout for live probes, in seconds.

Output

# Backstop Verify — 30-Second Keyless Proof

Mode: offline (100% local mock transport, zero network, zero API keys)
Provider: openai (gpt-4o-mini simulation)

| Metric            | Result             | Notes                                     |
|-------------------|--------------------|-------------------------------------------|
| Allowed calls     | 2                  | Completed within budget (500 tokens)      |
| Blocked calls     | 8                  | Pre-empted before network dispatch        |
| Tokens reserved   | 500                | Enforced budget ceiling                   |
| Tokens saved      | 2,000              | 8 runaway calls prevented                 |
| Exception surfaced| BudgetExceededError| Caught cleanly (subclasses openai.OpenAIError) |
| Wall-clock overhead| 0.07 ms           | Control-path p99 mediation latency        |

## Mechanism Checks
- [PASS] config valid: BackstopConfig() constructed with sane bounds.
- [PASS] wrap pipeline: Backstop.wrap(client) served a mock request end-to-end.
- [PASS] budget block: 8/10 runaway calls blocked at 500-token budget.
- [PASS] overhead: control-path overhead p99 < 5ms.
- [PASS] cache hit: second identical request served from cache.
- [PASS] per-agent isolation: budgets are independent.
- [PASS] hierarchical budgets: parent exhaustion blocks child; sibling unaffected.
- [PASS] shadow mode: would_block recorded without actual denial.

Summary: 8 passed, 0 warn, 0 failed, 0 skipped
Status: VERIFIED (real wrap enforcement active)

The 8 mechanism checks verify: config construction, wrap pipeline, budget blocking, overhead, cache hits, per-agent isolation, hierarchical budgets, and shadow mode — all using a mock provider with no network calls.


backstop demo

Runs a side-by-side comparison of an unprotected agent loop versus a Backstop-wrapped loop:

backstop demo
| Calls completed | 10 |  3 |  -7 (-70.0%) |
| Calls blocked   |  0 |  7 |  +7 (blocked in-process) |
| Tokens consumed | 250 | 75 | -175 (-70.0%) |

Options:

FlagDefaultDescription
--calls10Number of loop iterations to simulate.
--budget75Token budget for the wrapped client.
--provideropenaiClient SDK to simulate.
--model—Model identifier.
--jsonoffEmit JSON instead of Markdown.
--strictoffExit non-zero if the guardrail fails to block.

backstop doctor

Validates your Backstop installation and environment:

backstop doctor

Checks:

  • Python version and platform
  • Backstop version
  • Optional dependencies (openai, anthropic, prometheus_client, redis, opentelemetry, yaml)
  • API key presence (does not send keys anywhere)
  • Wrap smoke test with mock transport
  • Actual SDK client wrapping (OpenAI + Anthropic)
  • Provider support status

backstop harness

Runs a deterministic load scenario against a mock provider:

backstop harness --scenario burst
FlagDefaultDescription
--scenario—One of burst, steady-state, error-storm, budget-hit.
--seeddeterministicRandom seed for reproducibility.
--jsonoffEmit JSON instead of Markdown.

Scenarios:

ScenarioWhat it exercises
burstSudden spike of concurrent requests
steady-stateSustained baseline load
error-stormProvider returns 5xx errors
budget-hitTokens exhausted mid-scenario

backstop benchmark

Runs the full benchmark suite and prints results:

backstop benchmark                  # print to stdout
backstop benchmark --publish        # also write to docs/benchmark-results-<date>.md
backstop benchmark --json           # JSON output

backstop serve

Runs Backstop as an OpenAI-compatible gateway/sidecar:

backstop serve --target https://api.openai.com/v1 --budget 100000
FlagDefaultDescription
--target—Upstream base URL.
--budget100000Token budget for the gateway.
--port8080Listen port.
--host127.0.0.1Bind address.
--api-keys—Comma-separated allowed Bearer tokens (auth disabled if omitted).
--rate-limit—Max requests per minute per API key (requires --api-keys).
--config-json—BackstopConfig overrides as a JSON object.

backstep metrics

Starts a Prometheus metrics server:

backstop metrics --port 9090

Metrics covered: request count, request duration, queue wait, queue depth, active concurrency, AIMD limit, remaining budget, circuit state, retries, cache hits, tenant budget blocks.


backstop dashboard

Serves the built-in operations dashboard:

backstop dashboard --demo           # synthetic traffic, no API keys
backstop dashboard                  # live process metrics
FlagDefaultDescription
--port8787Listen port.
--host127.0.0.1Bind address (non-loopback requires --token).
--refresh1.0 (demo) / 2.0 (live)Sample interval in seconds.
--cost-model—Model whose input rate converts tokens to USD.
--audit—Path to audit JSONL sink.
--demooffRun with deterministic mock workload.
--runners3Demo runner count.
--token—Bearer token (required for non-loopback host).
--themeautoInitial colour theme: auto, dark, light.
--no-browseroffDo not open a browser.

backstop real-openai / backstop real-anthropic

Real provider smoke tests (requires API keys):

backstop real-openai              # uses OPENAI_API_KEY
backstop real-anthropic           # uses ANTHROPIC_API_KEY

Options: --model, --base-url, --budget, --async-client, --json.


backstop ledger

Three subcommands over the opt-in spend ledger. The ledger itself is off by default and is turned on with BackstopConfig(ledger_enabled=True) — see the ledger schema reference and the chargeback recipe.

backstop ledger demo                          # keyless, offline, exit 0
backstop ledger show   --path ledger.jsonl    # integrity, then the chargeback
backstop ledger export --path ledger.jsonl --out chargeback.csv \
                       --group-by team,feature

backstop ledger demo

Prints a priced chargeback table built from fixed synthetic events. No API key, no network call, no file, and byte-identical across runs. The traffic is synthetic; the prices are real and every dollar is Decimal arithmetic against the bundled rate card. One model in the demo is deliberately absent from the rate card, so its requests are counted and its dollars are absent.

FlagDefaultDescription
--group-byteam,featureComma-separated Attribution dimensions. An unknown one is an argparse usage error listing the legal dimensions.
--jsonoffEmit JSON instead of Markdown.

Exit 0.

The demo's teardown prose is hardcoded to say requests declared no team and no feature, so a --group-by other than team,feature gets correct numbers and one wrong sentence. show and export word it generically.

backstop ledger show

Reports a JSONL ledger's integrity before its chargeback, so a reader who only looks at the total cannot miss a lost line, then prints the chargeback.

FlagDefaultDescription
--path—Path to a JSONL ledger file. Required.
--limit20Maximum rows to print; 0 for every row.
--group-byteam,featureComma-separated Attribution dimensions.
--jsonoffEmit JSON instead of Markdown.

Exit 0 on success; 1 on a corrupt non-final line or an unreadable path, with the message on stderr. A file read reports dropped_events and sink_errors as unknown with the reason, never as 0 — those counters are process-local and are not written to the file. Read state.close() from the live writer for them.

A final line that will not parse is reported as a torn write and the rest of the file is read. A final line that is unterminated but parses is reported and kept, because dropping a complete event loses a dollar.

backstop ledger export

Writes the RFC 4180 CSV: CRLF, UTF-8, money as 2-decimal strings, stable column order, and no totals row.

FlagDefaultDescription
--path—Path to a JSONL ledger file. Required.
--out—Path of the CSV to write. Required.
--group-byteam,featureComma-separated Attribution dimensions.
--jsonoffEmit JSON instead of Markdown.

Exit 0 on success; 1 as above, and in that case nothing is written, because a chargeback that silently skips rows is worse than a failed command.


wedge

wedge is a separate CLI for declarative task workflows. See examples/wedge_basic.py and the wedge documentation for details.


— Edit this page on GitHub

On this page