DIM · Dagon Inference Marketplace

Admission rules

Every POST /v1/chat/completions must carry a payment Hold. The gateway checks it against its local view of the Solana channel, without an RPC call on the request path, before it reads the body into an inference slot or calls your model. A refused request costs the buyer nothing and you nothing.

Request headers

Header Content
X-IM-Hold base64 of the 275-byte IM/HOLD/1 message
X-IM-Hold-Sig base64 of the 64-byte Ed25519 signature by the channel's session key
X-IM-Session base58 of the session public key
X-IM-Salt base64 of the 32-byte salt

The Hold names the channel and its epoch, a lane and strictly increasing lane counter, a random request_id, request_commitment = SHA256(salt ‖ exact body bytes), the route_id, the schedule_digest, a cap_micros and a dispatch_until deadline. The body is hashed exactly as received, never re-serialized (A19).

The checks, in order

# Check Refusal
1 All four headers present with the right lengths; the Hold's domain (genesis hash and program ID) equals the gateway's. 402 malformed_hold
2 The channel is in the gateway's channel view (channels naming this gateway's settler or a retained settler). 402 unknown_channel
3 X-IM-Session is the channel's session key and the signature verifies over the exact Hold bytes. 402 bad_signature
4 route_id is a route in this listing. 402 route_mismatch
5 channel_epoch equals the channel's epoch. 402 malformed_hold
6 The channel is open, before its service end, and no close has begun. 402 channel_closed
7 The channel's settler is this gateway's (current or retained) and its payout account is this gateway's payoutToken. 402 wrong_seller
8 schedule_digest is the route's digest and the schedule is in effect (effective_from ≤ now). 402 schedule_mismatch
9 dispatch_until has not passed. 402 hold_expired
10 cap_micros ≥ the schedule's w_req_micros. 402 cap_too_low
11 request_id has never been admitted by this seller, and no upload under it was abandoned. 402 duplicate_request
12 lane_counter is greater than every counter already seen on this channel and lane. 402 lane_replay
13 cap_micros ≤ the Mandate's per_request_cap, or ≤ budget − redeemed for a channel without a Mandate. 402 cap_exceeds_limit
14 cap_micros fits in budget − max(redeemed, acknowledged) − unvouchered − active, the funds not already promised to earlier receipts and running requests. 402 insufficient_channel_funds
15 The route has a free inference slot (in_flight < max_concurrency). 429 no_headroom, Retry-After: 1

After these pass, the gateway reads the body (up to requestLimit, within uploadTimeoutMs), checks request_commitment against the salt and the bytes (402 malformed_hold if it differs, without consuming the Hold), re-runs the checks, and durably claims the Hold. Only then is the request dispatched. With "ledgerMode": "shared", checks 11, 12 and 14 run inside the shared claim transaction instead.

Response shape

Every refusal is JSON:

{ "error": { "code": "insufficient_channel_funds", "message": "channel has insufficient funds for this exposure" } }

Other pre-admission answers

Status Code Meaning
503 gateway_draining, Retry-After: 1 Rolling deploy or maintenance. The Hold was not consumed; the buyer resends the same Hold, to this or another process serving the route (A35).
503 ingress_busy, Retry-After: 1 Too many bodies uploading on this route or session.
413 invalid_request Body larger than requestLimit.
408 invalid_request The body did not arrive within uploadTimeoutMs. This burns the Hold (a resend is duplicate_request until its dispatch_until) and limits the session to one upload at a time for 60 s, doubling on repeat offences up to an hour.
503 gateway_unavailable The gateway is stopping or its ledger failed.

What is retryable

Per A16, only insufficient_channel_funds is retryable with the same channel, and only after a voucher acknowledgment or a top-up frees funds. Every other 402 means the Hold or channel is wrong. A 429 means "try again in a second or use another route"; the SDK does that automatically. The protocol treats any non-2xx answer as unbillable for the buyer (A22), so you will never be paid for a refused request and never need to be.

Seller-side protection

The buyer decides which receipts to voucher (A25′). Your protection is check 14: the gateway counts every unvouchered receipt and every running request against the channel and refuses new Holds once they would exceed what the channel can still pay. If a buyer stops vouchering, your unpaid work on that channel is therefore bounded by the part of its budget not yet covered by acknowledged vouchers. You still hold signed receipts for that work, but only a buyer-signed voucher moves money on-chain.

The unpaid probe

A request with no Hold fails check 1:

curl -si -X POST https://gpu.example.com/v1/chat/completions -d '{"messages":[{"role":"user","content":"ping"}]}'

Expect status 402 (HTTP/1.1 402 or HTTP/2 402, depending on your edge) and "code":"malformed_hold". The self-check runs exactly this test; a 2xx means your public URL reaches a model server without passing through the gateway.