Skip to main content

Flight recorder SDK for AI agents — zero-dependency BLACKBOX client

Project description

BLACKBOX SDK

Zero-dependency Python SDK for recording AI agent runs into BLACKBOX — the flight recorder for AI agents.

Install

pip install blackbox-sdk

Or from source:

cd sdk && pip install -e .

Two-line integration

import blackbox_sdk as bb

bb.configure(api_url="https://your-blackbox.railway.app", api_key="<agent-key>")

with bb.run("invoice_review_4821", model="claude-sonnet-4-6", system_prompt="You are…") as run:
    run.reasoning("Analyzing the invoice for anomalies…")
    result = call_tool("ocr_extract", path="/tmp/invoice.pdf")
    run.tool_call("ocr_extract", {"path": "/tmp/invoice.pdf"}, result=result)
    run.output("Total: $4,200. No anomalies detected.", tokens_in=512, tokens_out=38, cost_usd=0.0024)
    run.seal()

Every event is hashed and chained. Replay, diff, and audit any run in the BLACKBOX UI.

Configuration

Method Priority
bb.configure(api_url=..., api_key=...) 1 (highest)
BLACKBOX_API_URL / BLACKBOX_AGENT_KEY env vars 2
Defaults (http://localhost:8000, no key) 3

API reference

bb.run(run_id?, *, model, system_prompt, tools, sampling, policy_pack)

Returns a RunRecorder context manager. The genesis event is recorded on __enter__. Unhandled exceptions automatically record a fault event before re-raising.

RunRecorder methods

Method Description
run.genesis() Called automatically on enter
run.reasoning(text) Chain-of-thought step
run.tool_call(tool, inputs, result?, latency_ms?) Tool invocation
run.retrieval(query, results, source?) RAG retrieval
run.decision(text) Policy/routing decision
run.output(text, tokens_in?, tokens_out?, cost_usd?, latency_ms?) Final output
run.fault(claim, fault_class?, severity?, description?) Detected hallucination
run.seal(summary?) Close the run chain
run.timed_tool_call(tool, inputs, fn, *args, **kwargs) Auto-timed tool call

Fault classes

Class Meaning
C1 Fabricated value
C2 Fabricated source / citation
C3 Out-of-scope claim
C4 Contradiction with prior context

Environment variables

BLACKBOX_API_URL=https://your-blackbox.railway.app
BLACKBOX_AGENT_KEY=bb_agent_...

Auto-instrumentation

Patch openai and anthropic globally — every LLM call is recorded automatically, zero agent code changes:

import blackbox_sdk as bb

bb.configure(api_url="https://your-blackbox.railway.app")
bb.instrument()  # patches openai + anthropic clients at startup

# Every client.messages.create() / client.chat.completions.create()
# is now automatically recorded as a BLACKBOX run.

# Selective patching:
bb.instrument(record_openai=False)   # Anthropic only
bb.instrument(record_anthropic=False) # OpenAI only

OpenTelemetry

BLACKBOX also accepts standard OTLP traces at /v1/otel/traces. See the OTel setup guide.

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

blackbox_sdk-0.3.1.tar.gz (12.1 MB view details)

Uploaded Source

Built Distribution

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

blackbox_sdk-0.3.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file blackbox_sdk-0.3.1.tar.gz.

File metadata

  • Download URL: blackbox_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 12.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for blackbox_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ec58884c5e57b6dc5185581920bcb48be48353108e3b15420303b4ecf647fd01
MD5 718d921499a0baca2ccd4c74cbdd8dcf
BLAKE2b-256 a8641ab60aa1bdd33e1ff1629376269c2c240c63891e4fbea79899f1a8baf17c

See more details on using hashes here.

File details

Details for the file blackbox_sdk-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: blackbox_sdk-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for blackbox_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e8877af2d7d0441795a4410d7148cbbe286dc66485bda86022ff56bca608bf3
MD5 4590acde76fa5d88e79fefe6aa7c73e9
BLAKE2b-256 16b88cde5d66d0fb5abfc70ddda70473f2dc3902ffbb1088907f63d8d4d845e4

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