DIM · Dagon Inference Marketplace

Receipts

A receipt is the seller's signed record of one request: how many tokens went in and out, how the request ended, how long it took, and what it costs under the published price schedule. The charge is never above the hold's cap. Your agent recomputes the charge from the token counts before paying, so a seller cannot bill more than its own prices allow.

What is in a receipt

A receipt is exactly 382 bytes, signed with one of the seller's listed receipt keys:

Field Meaning
seller_id, key_epoch Who signed, and with which listed receipt key.
route_id, model_identity_id What was served.
request_id, request_commitment Copied from the hold, so the receipt is bound to one request and one exact body.
channel, channel_epoch Which channel pays.
status 0 ok, 1 cancelled, 2 failed, 3 not_served, 4 policy_unhonored.
usage_input, usage_cached_input Input tokens, and how many of them were served from cache.
usage_output_visible, usage_output_hidden Output tokens you saw, and hidden output such as reasoning tokens.
usage_source 0 counted by the upstream model, 1 estimated.
charge_micros, cap_micros The charge, and the hold's cap.
schedule_digest Which price schedule applied.
ttft_ms, duration_ms, created_at Time to first token, total time, and when it was issued.

A receipt carries no prompt, no output text and no customer identifier.

The charge rule

charge = ceil((in·r_in + cached·r_cached + out_visible·r_out_visible + out_hidden·r_out_hidden) / 1,000,000) + per_request_fee
  • Rates are micro-USDC per million tokens, from the route's schedule.
  • cached is clamped to at most in, and in is billed as in − cached at the input rate.
  • The sum is computed in wide integers and rounded up once per request.
  • The receipt's charge is the lesser of that amount and the cap. Anything above the cap the seller absorbs.

A step-by-step example with real numbers is in verifying receipts.

Billing by outcome

Status When Charge
ok The request completed. The full charge.
cancelled The client disconnected after output started. Input tokens plus per_request_fee, no output.
failed The seller failed, including no first token within ttft_max_ms. 0
not_served The seller declined the request or never started it. 0
policy_unhonored The seller could not honor the route's policy. 0

For cancelled, the contract allows billing output only for tokens actually forwarded to your socket; the reference gateway bills input and fee only. The reference gateway does not currently issue policy_unhonored.

How a receipt reaches you

  • Non-streaming: in the response header X-IM-Receipt: base64(receipt).base64(signature).
  • Streaming: as a final server-sent event, event: im_receipt with data {"receipt": "…", "sig": "…"}, just before data: [DONE].
  • Lost? GET /im/v1/requests/{request_id_hex}/receipt on the seller returns {receipt, sig}, or 404.

When a receipt is billable

  • If the seller answered with a non-2xx status (402, 429, 5xx), or the connection failed before a status line arrived, the request is unbillable. A receipt that later shows up for it must be failed or not_served at charge 0; anything else is kept as evidence of a contradiction and never paid. The SDK exposes these through equivocations().
  • Once you received a 2xx status, the request is billable according to the seller's signed receipt, even if you cancelled or timed out while it streamed. The SDK recovers that receipt and pays it.