Skip to main content

chain-receipt — Python SDK

Verified AI output receipts. Every call through the Chain Receipt proxy gets a signed receipt: a canonical-JSON record (schema air/1) whose SHA-256 hash is signed with Ed25519 and anchored to Bitcoin in batches. This SDK calls the proxy, fetches receipts, downloads evidence bundles, and verifies receipts offline — the signature and hash checks need no network.

Install

pip install chain-receipt

Requires Python 3.11+. The only runtime dependency is cryptography (for Ed25519); HTTP uses the standard library.

Quickstart

from chain_receipt import ChainReceiptClient

client = ChainReceiptClient(api_key="crk_live_...")  # or set CHAIN_RECEIPT_API_KEY

# 1. Call any model through the OpenAI-compatible proxy.
resp = client.chat_completions(
    model="openai/gpt-6-luna",
    messages=[{"role": "user", "content": "Say the word receipt."}],
    max_tokens=20,
)
print(resp["choices"][0]["message"]["content"])
receipt_id = resp["ai_receipt"]["receipt_id"]  # keep the salts too:
salts = resp["ai_receipt"]["salts"]            # returned ONCE, never stored

# 2. Fetch the receipt envelope and verify it offline.
result = client.verify_receipt(receipt_id)
print(result.valid, result.hash_ok, result.signature_ok)  # True True True

# 3. Or verify an envelope you already hold, with no client at all.
from chain_receipt import verify_receipt, fetch_public_keys

keys = fetch_public_keys()  # /.well-known/receipt-keys.json (public)
result = verify_receipt(envelope, public_keys=keys)

Receipts

# One receipt, full envelope (receipt, receipt_hash, signature, anchor, verify_url)
envelope = client.get_receipt("rcpt_...")

# Newest first, paginated (limit 1–100, default 50)
page = client.list_receipts(limit=10, status="complete")
for row in client.iter_receipts():  # walks every page
    print(row["receipt_id"], row["anchor_status"])

# Evidence bundle: envelope JSON + .ots Bitcoin proof (when batched)
bundle = client.download_bundle("rcpt_...", path="rcpt_....zip")
print(bundle.ots is not None)  # False until the receipt is batched

# Receipt any JSON directly, no AI call — the commitment hashes the
# JSON as sent; a non-object is wrapped as {"value": data}.
result = client.create_receipt(
    {"order": "ORD-1", "total": 42.5, "currency": "CAD"},
    customer_ref="ORD-1",
)
print(result["receipt"]["receipt_id"])  # + verify_url, receipt_hash

# Permission Slips — data is {"checkout_mandate": ..., "payment_mandate": ...}.
# A paid add-on (Developer +$15/month, Team +$49/month; included on
# Business/Enterprise). A duplicate slip answers 200 with
# duplicate=True and no new receipt.
slip_result = client.create_receipt(
    {"checkout_mandate": {...}, "payment_mandate": {...}},
    record_kind="permission_slip",
)
slip = slip_result["slip"]  # {"slip_id", "status": "active", ...}

# A slip's public status — no API key is sent. Status only, never
# the mandate content.
status = client.get_slip("slip_...")
print(status["status"])  # "active" | "cancelled" | "expired"

# Revoke a slip. Owner: the org's API key (default). Delegate: the
# agent whose key the slip's cnf binds — pass its Ed25519 signature
# (base64, over the canonical JSON of {"slip_id", "slip_hash",
# "cancelled_at"}) with cancelled_at; no API key is sent.
client.cancel_slip("slip_...", cancelled_at="2026-11-26T12:00:00.000Z")

Verify content, not just the signature

The receipt stores hashes of your prompt and the response, salted so a short prompt cannot be guessed. Re-hash your own copies to prove the receipt is about your call:

from chain_receipt import build_prompt_commitment, verify_receipt_content

ok = verify_receipt_content(
    envelope["receipt"],
    salts,  # from ai_receipt, returned once at call time
    prompt_body=build_prompt_commitment(
        messages=[{"role": "user", "content": "Say the word receipt."}]
    ),
    response_json=resp,  # the full provider response object
)

Streaming

events = client.chat_completions(
    model="google/gemini-3.5-flash",
    messages=[{"role": "user", "content": "Count to three."}],
    max_tokens=30,
    stream=True,
)
for event in events:
    if event.get("object") == "ai_receipt":
        print("receipt:", event["ai_receipt"]["receipt_id"])

Bring your own provider key

Pass it per call (never stored by the SDK) or save it on the portal Keys page and omit it:

resp = client.chat_completions(
    model="anthropic/claude-haiku-4-5",
    messages=[{"role": "user", "content": "Say the word receipt."}],
    provider_key="sk-ant-...",  # sent as X-Provider-Key
)

What is verified, exactly

verify_receipt checks, each reported separately:

  • hash — receipt_hash recomputes from the receipt object (SHA-256 over RFC 8785 canonical JSON).
  • signature — Ed25519 verifies over the 32 raw hash bytes, against the published public key for signature.key_id.
  • merkle — when the envelope carries an anchor proof, the leaf + proof recompute to the batch root (otherwise None).

valid is true when every check that could run passed. A genuine receipt is valid before its batch confirms on Bitcoin — anchor status is reported separately in the envelope.

Golden vectors

The primitives in this SDK (JCS, Ed25519, SHA-256, Merkle root) pass the same golden vectors as @chain-receipt/core, the verifier, and the JS SDK: packages/core/test-vectors/golden.json (JCS from RFC 8785 §3.2.3, Ed25519 from RFC 8032 test 1, SHA-256 from FIPS 180-4). Run them with pytest in packages/sdk-py.

Metadata

Release files for chain-receipt 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chain-receipt 0.2.0
File Size Uploaded Provenance Actions
chain_receipt-0.2.0.tar.gz 26.0 kB With provenance Details for chain_receipt-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chain-receipt 0.2.0
File Interpreter ABI Platform Actions
chain_receipt-0.2.0-py3-none-any.whl Python 3 none any Details for chain_receipt-0.2.0-py3-none-any.whl

Total release size: 46.5 kB

Release files / chain_receipt-0.2.0.tar.gz

Download URL chain_receipt-0.2.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1aa2b4a04f244df6a6c860c18abaad04ef47f6871271add0643cd929e0e53dee
BLAKE2b-256 checksum
How to use checksums
af0e12ca129c02292ae5952593857a06b83d2af5d16e12bf659da50261cc65e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chain_receipt-0.2.0-py3-none-any.whl

Download URL chain_receipt-0.2.0-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee599f571614a5c31256949b72a1d30c4d6b4ceb5a4e66d244752aca506b6a0e
BLAKE2b-256 checksum
How to use checksums
65afb66faf90320ff1a484da05eb5e709d5ec1c6b98d6265c366df03a5c0c33c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for chain-receipt 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chain_receipt-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page