---
title: "IM/RECEIPT/1 · Protocol reference · DIM docs"
description: "IM/RECEIPT/1 is the 382-byte record a seller signs for every admitted request, binding route, model, usage, outcome, charge and timing to the Hold."
url: https://marketplace.dagon.so/docs/protocol/receipt
---

# IM/RECEIPT/1

Every request a gateway admits ends in exactly one receipt, whatever the outcome. It is signed by the seller's receipt key, copies the binding fields of the Hold, and states the usage and the charge. Buyers pay receipts by vouchering them; nothing else is billable.

## Layout

**`IM/RECEIPT/1`**: 382 bytes, little-endian, no padding between fields.

| Offset | Size | Field | Type | Meaning |
|---:|---:|---|---|---|
| 0 | 16 | `tag` | `bytes[16]` | `IM/RECEIPT/1` right-padded with `0x00` to 16 bytes. |
| 16 | 64 | `domain` | `bytes[64]` | `genesis_hash ‖ program_id`, as in the Hold. |
| 80 | 32 | `seller_id` | `bytes[32]` | Seller listing public key. |
| 112 | 4 | `key_epoch` | `u32` | Epoch of the receipt key that signed; must be listed in the seller's current `receipt_keys` (A14). |
| 116 | 32 | `route_id` | `bytes[32]` | Route that served the request. |
| 148 | 32 | `model_identity_id` | `bytes[32]` | `SHA256(jcs(model_identity))` of that route. |
| 180 | 32 | `request_id` | `bytes[32]` | Copied from the Hold. |
| 212 | 32 | `request_commitment` | `bytes[32]` | Copied from the Hold. |
| 244 | 32 | `channel` | `bytes[32]` | Copied from the Hold. |
| 276 | 8 | `channel_epoch` | `u64` | Copied from the Hold. |
| 284 | 1 | `status` | `u8` | Outcome; see the status table. Decoders reject values above 4. |
| 285 | 8 | `usage_input` | `u64` | Input tokens. |
| 293 | 8 | `usage_cached_input` | `u64` | Cached input tokens. Charged as at most `usage_input`. |
| 301 | 8 | `usage_output_visible` | `u64` | Visible output tokens. |
| 309 | 8 | `usage_output_hidden` | `u64` | Hidden (reasoning) output tokens. |
| 317 | 1 | `usage_source` | `u8` | Where usage came from; see the usage-source table. Decoders reject values above 2. |
| 318 | 8 | `charge_micros` | `u64` | Charge in micro-USDC. Decoders reject `charge_micros > cap_micros`. |
| 326 | 8 | `cap_micros` | `u64` | Copied from the Hold. |
| 334 | 32 | `schedule_digest` | `bytes[32]` | Copied from the Hold. |
| 366 | 4 | `ttft_ms` | `u32` | Milliseconds to the first upstream token (non-streaming: first response byte, A26). |
| 370 | 4 | `duration_ms` | `u32` | Milliseconds from admission to the outcome. |
| 374 | 8 | `created_at` | `i64` | Unix seconds. Orders receipts in the commitment chain (A3). |

16 + 64 + 32 + 4 + 32 + 32 + 32 + 32 + 32 + 8 + 1 + 8 + 8 + 8 + 8 + 1 + 8 + 8 + 32 + 4 + 4 + 8 = **382 bytes**. A message of any other length is rejected.

<sub>Generated from [`packages/protocol/src/wire.ts`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/packages/protocol/src/wire.ts), [`crates/im-protocol/src/wire.rs`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/crates/im-protocol/src/wire.rs), [`crates/im-protocol/vectors/generate.py`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/crates/im-protocol/vectors/generate.py).</sub>

## Status

| Value | Name | Meaning |
|---:|---|---|
| 0 | `ok` | Full charge. |
| 1 | `cancelled` | Client disconnected after output began: input plus `per_request_fee` (ADR 0003). |
| 2 | `failed` | Zero. |
| 3 | `not_served` | Zero. |
| 4 | `policy_unhonored` | Zero. |

<sub>Generated from [`packages/protocol/src/wire.ts`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/packages/protocol/src/wire.ts), [`packages/protocol/src/charge.ts`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/packages/protocol/src/charge.ts).</sub>

How the reference gateway picks the status:

- `ok`: the upstream completed with usage and a first token inside `ttft_max_ms`.
- `cancelled`: the client disconnected after the gateway had forwarded output to it. If no output had been forwarded, the status is `not_served`.
- `failed`: the upstream timed out, failed with a 5xx, broke the stream, sent no first token within `ttft_max_ms`, or the charge overflowed. Requests interrupted by a gateway restart are finalized as `failed` during recovery.
- `not_served`: the request body was not a valid chat request, or the upstream declined it with a 4xx.
- `policy_unhonored`: defined by the protocol; the reference gateway does not issue it.

## Usage source

| Value | Name | Meaning |
|---:|---|---|
| 0 | `upstream` | Usage reported by the upstream model server. |
| 1 | `estimated` | Estimated by the gateway (the reference gateway does this only for `cancelled` input). |
| 2 | `reserved` | No usage measured; the reference gateway uses it with all-zero usage. |

<sub>Generated from [`packages/protocol/src/wire.ts`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/packages/protocol/src/wire.ts), [`packages/protocol/src/charge.ts`](https://github.com/cool-kids-do-ai/inference-marketplace/blob/main/packages/protocol/src/charge.ts).</sub>

## Signing key

`seller_id` is the seller's listing key; the receipt is signed by a separate receipt key. A listing publishes `receipt_keys: [{key, key_epoch}]`, and a receipt is valid only under a key and epoch listed in the currently signed listing (A14). Rotation overlaps: a new key is listed before first use, and the old one stays listed until its receipts are settled (A34).

## Delivery

| Response | Where the receipt is |
|---|---|
| Non-streaming success | header `X-IM-Receipt: base64(receipt).base64(sig)` |
| Streaming | a final SSE event before the gateway's own `data: [DONE]`: `event: im_receipt` with data `{"receipt": "<base64>", "sig": "<base64>"}` |
| Error after the request was claimed (the [chat outcomes](https://marketplace.dagon.so/docs/protocol/errors) codes) | header `X-IM-Receipt` on the error response |
| Lost response | `GET /im/v1/requests/{request_id_hex}/receipt` returns `{"receipt", "sig"}`, or 404 |

## What a buyer checks

1. The signature verifies under a listed receipt key for `key_epoch`, in the expected domain.
2. `request_id`, `request_commitment`, `channel`, `channel_epoch`, `cap_micros`, `route_id` and `schedule_digest` equal the Hold's.
3. `charge_micros ≤ cap_micros` (decoders enforce this) and the charge matches the [schedule](https://marketplace.dagon.so/docs/protocol/price-schedule) for the stated usage and status.
4. A request that received a non-2xx status before any response bytes is unbillable: its receipt must be `failed` or `not_served` with charge 0. Any other receipt for it is never vouchered and is kept as evidence of equivocation (A22). Once a 2xx status line arrived, the request is billable by its receipt even if the buyer cancelled (A29).

Receipts are then paid by covering them in a [voucher](https://marketplace.dagon.so/docs/protocol/voucher), in the order of the [commitment chain](https://marketplace.dagon.so/docs/protocol/receipts-commitment).
