OpenReceipt protocol
OpenReceipt is an open specification; the canonical version is at signedreceipts.org/spec. This page describes how CloakAPI implements it. To check a receipt, see Verification methods. For v3 receipts from the portal, Self-attested portal keys explains what the embedded browser-instance key and the gateway countersignature establish.
Envelopes in production
CloakAPI issues three envelope kinds, depending on how you call it:
- v3, client-signed. On the client-side paths (browser chat, desktop app, browser extension), the device that performed the tokenization signs an OpenReceipt v3 envelope (
v: "v3",alg: "ecdsa-p256-sha256") before egress. It carries thev3-attestationclaim set: what egressed, which detector categories fired, engine hashes and the trust tier. When the request goes through the gateway, the gateway verifies the client signature and adds a countersignature that witnesses the provider, the model and the upstream byte hashes. The v3 specification defines the normative format. - v2, gateway-signed. On the bare-SDK API path (
api.cloakapi.io), the gateway seals a completed response with the v2 flat envelope described below, when a receipt is issued. It returns the envelope in theX-CloakAPI-Receipt-v2header, or as thereceipt-v2event at the end of a stream; a stream cut off before it completes has no trailer. Authenticated calls that fail with a4xxor5xxget a separate signed failed-call receipt; a request without a valid API key gets none. - v1, gateway-signed and stored. A successfully persisted v1 envelope is linked into the tenant receipt chain. Chain membership confirms that receipt’s signed position; it does not establish that every Gateway interaction produced one. The authenticated detail lookup returns the stored envelope.
Identifiers
The gateway generates the v2 envelope’s jti from 16 random bytes and writes them as 32 lowercase hexadecimal characters. X-CloakAPI-Receipt-v2-Jti carries that same value when the gateway returns the receipt in a header. When the gateway issues a v2 receipt and persists a v1 envelope for the same call, the signed v1 envelope reuses the v2 jti. A stored v1 envelope created without a v2 identifier gets its own UUID.
The gateway detail response’s outer jti comes from the PostgreSQL UUID column. PostgreSQL renders the same 128 bits in hyphenated 8-4-4-4-12 form. The random v2 bits have no prescribed UUID version or variant. Most such IDs fail a version-1–8 and RFC variant check. Keep the identifier inside a signed envelope exactly as issued.
| Lookup | Credentials | Result |
|---|---|---|
GET /api/v1/receipts/{jti} | Portal session or API key, with receipts.verify | Accepts PostgreSQL UUID input forms, including the 32-hex and hyphenated forms. For a gateway receipt, envelope holds the stored v1 envelope. API-key reads are scoped to the caller and the key that created the receipt. A session can also read the caller’s extension entries and desktop-local metadata. Desktop-local entries have envelope: null. |
| Portal receipt verifier, Receipt ID tab (JTI lookup) | Sign in to the portal for account receipts | Loads the envelope from the authenticated detail route. |
GET /api/v1/receipts/by-jti/{jti} | Public | Returns an unsigned landing-page campaign demo fixture when the fixture ID matches. A customer ID in the gateway’s 32-lowercase-hex or hyphenated form receives 401 auth_required with directions to the signed-in portal verifier and authenticated detail route. |
v2 envelope shape
The v2 envelope is a flat JSON object, signed with ES256 (ECDSA P-256 over SHA-256), canonicalized per RFC 8785 (JCS), and chain-linked per tenant.
{ "v": 2, "alg": "ES256", "kid": "gw-prod-2026-q2", "iss": "https://api.cloakapi.io", "jti": "1de5882f66e6e376c7b26ce2c34bafc7", "iat": 1759420800, "timestamp": "2026-04-18T12:00:00.000Z", "request_id": "req_01HWRK9GTBF3MXQJ4VZPND", "provider": "openai", "model": "gpt-5.4-mini", "input_tokens": 184, "output_tokens": 312, "hash_upstream_request": "b3a…", "hash_upstream_response": "c91…", "chain": { "chain_id": "receipt-v2-org-42", "seq": 47, "prev_hash": "sha256:a3f8c2…" }, "signature": "BASE64URL_RAW_R_S_ECDSA_SIGNATURE", "sig": "BASE64URL_RAW_R_S_ECDSA_SIGNATURE"}| Field | Meaning |
|---|---|
v | Protocol version. Integer 2 for the gateway-signed flat envelope (client-signed receipts use the string "v3"). |
alg | Signing algorithm: "ES256" (ECDSA P-256 over SHA-256). |
kid | Key ID. Look up the matching key in the public JWKS to get the verifying key. |
iss | Issuer URL (https://api.cloakapi.io). |
jti | Unique receipt ID: 32 lowercase hex characters (128 random bits). The transparency feed shows the same value as receipt_id. |
iat | Unix timestamp, in seconds, when the gateway sealed the response. |
timestamp | RFC 3339 timestamp with millisecond precision, in UTC (Z). |
provider / model | Upstream provider slug and the model the call was routed to. |
routing_decision | Present when the router ran: from, to (provider slugs), chosen_model, classifier, savings_pct, strategy. There is no provider_id field. |
input_tokens / output_tokens | Token counts billed for the call. |
hash_upstream_request / hash_upstream_response | SHA-256 as bare lowercase hex, not the bytes themselves. hash_upstream_request covers the JCS-canonical (RFC 8785) form of the client’s JSON request snapshot before gateway-side provider preparation. When present, hash_provider_request separately covers the provider-prepared JSON payload, which can differ from the client snapshot. See Reproducing hash_upstream_request. |
chain.chain_id | Per-tenant chain identifier (receipt-v2-org-<org_id>). |
chain.seq | Sequence number, advanced from the tenant’s stored chain head when the chain cursor is available. If the cursor is unavailable, the gateway can emit an unlinked fallback with seq: 0 and prev_hash: null; that fallback does not establish continuity. |
chain.prev_hash | When linked, the hash of the previous receipt’s canonical bytes in the same chain, so a missing or out-of-order link can be detected. A fallback with prev_hash: null has no prior link. |
signature / sig | Both carry the same value: a URL-safe base64 (unpadded) raw r‖s (64-byte) ECDSA signature over the JCS-canonical bytes of the envelope with both signature and sig removed. sig is the OpenReceipt name the SDKs read. |
v1 envelope shape
The stored receipt nests the call data under claims. Abridged from a live receipt:
{ "v": "v1", "alg": "ecdsa-p256-sha256", "kid": "gw-prod-2026-q2", "iss": "https://api.cloakapi.io", "sub": "api_key:1055", "jti": "1de5882f66e6e376c7b26ce2c34bafc7", "iat": 1789978391, "chain": { "chain_id": "tenant-51", "seq": 1078, "prev_hash": "7a08…" }, "claims": { "capability": "chat", "provider": "anthropic", "model": "claude-haiku-5-5", "tokens_in": 287, "tokens_out": 42, "hash_upstream_request": "7ee1…", "hash_upstream_response": "3dc2…", "routing_decision": { "from": "anthropic", "to": "anthropic", "chosen_model": "claude-haiku-5-5", "strategy": "client-side", "classifier": "client-side-arbitrage" }, "tokenisation_mode": "client_pretokenised", "engine_version": "1.6.0" }, "sig": "BASE64URL_RAW_R_S_ECDSA_SIGNATURE"}- The gateway signs the v1 envelope, not your device, so it has no trust
tier. Itskidresolves in the same JWKS as v2. - Token counts are
claims.tokens_inandclaims.tokens_out. Hashes are bare hex without asha256:prefix, andchain.chain_idistenant-<account id>. - Signature:
sigover the JCS-canonical bytes of the envelope withsigremoved, verified with the JWKS key that matcheskid.
Where to find the public key
- JWKS:
https://api.cloakapi.io/api/.well-known/cloakapi-receipt-pubkeys.jwks - PEM:
https://api.cloakapi.io/api/.well-known/cloakapi-receipt-pubkey.pem
Keys are rotated manually, with a quarterly target. Old keys stay in the JWKS, so earlier receipts keep verifying indefinitely. See Public JWKS for rotation and caching.