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

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.1.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.1.0
File Size Uploaded Provenance Actions
chain_receipt-0.1.0.tar.gz 23.4 kB With provenance Details for chain_receipt-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 42.3 kB

Release files / chain_receipt-0.1.0.tar.gz

Download URL chain_receipt-0.1.0.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6a23fb86e2932324c271dce49ac7c288155821e2f1f5101a7e930e34cff32de1
BLAKE2b-256 checksum
How to use checksums
c5d2d6ae85f1bd6b338ecafb394162bbfe482b91b096f6fdbcd30b1fa31de792
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 23, 2026.

Transparency log

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

Download URL chain_receipt-0.1.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5133d9b32e429061c2fe2d4f0116d9ac310b0df5ae05862825ba2cbe4c794e3
BLAKE2b-256 checksum
How to use checksums
b4bf46baac15e89d84d7301c187eafcb2dddd6e2b18c5170e247d24ece0f2ef3
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 23, 2026.

Transparency log

Security for chain-receipt 0.1.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.1.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 23, 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.1.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