Documentation
DIM documentation: core concepts, building agents that buy inference, selling and verifying inference, and the protocol reference.
Concepts
What DIM is, the words it uses, and what is always true.
- Start here: DIM lists and ranks verifiable AI inference routes; you call the seller directly, pay per request from your vault and check a signed receipt.
- What is DIM?: DIM is a marketplace where AI agents find an exact model, pay its seller per token from their own Solana vault, and check a signed receipt for every request.
- Model identity: A model identity names one exact deployment (family, revision, quantization, serving); its SHA-256 is the ID you route on, so no other build stands in.
- Routes: A route is one seller's signed offer to serve one exact model identity at one endpoint, under one price schedule, retention policy and set of receipt keys.
- Vaults: A vault is your USDC account in the DIM program: you deposit into it, channels draw budgets from it, and only you can withdraw its free balance.
- Mandates: A Mandate is an on-chain spending rule an owner gives an agent: a budget per period, a per-request cap, allowed sellers and an expiry, revocable at any time.
- Channels: A channel is a prepaid budget locked on-chain for one seller, with a fresh session key that signs requests and payments, a service end and a grace period.
- Holds: A hold is a 275-byte message your agent signs and sends with each request, promising to pay up to a cap; the seller checks it first. It is never payable.
- Receipts: A receipt is the seller's signed 382-byte record of one request: token counts, outcome, timing and the charge under the published schedule, never above the cap.
- Vouchers: A voucher is the only payable message: a 168-byte note, signed by the channel session key, that raises the running total the seller may collect from a channel.
- Settlement and redemption: Sellers get paid when anyone submits the newest voucher to the program, which pays the signed total minus what it already paid, never past the budget.
- Evidence levels: DIM labels facts by who stands behind them: claimed (the seller signed it), probed (a pinned probe measured it) or attested (hardware proof, not shipped yet).
- The privacy model: Prompts and outputs travel only between your agent and the seller you chose; DIM's index and Solana see hashes, token counts and amounts, never content.
- Keys and signatures: Every DIM message is signed: owners and agents sign funding, session keys sign holds and vouchers, sellers sign receipts, probes and the index sign evidence.
- Glossary: Plain definitions of every DIM term, from agent and availability to vault, voucher and zero data retention, each with a link to the page that explains it.
- FAQ: Direct answers to common questions about DIM: what it is, how agents pay per token, what sellers can and cannot charge, privacy, Mandates, receipts and errors.
- Docs house style: Write every DIM docs page answer-first, about one idea, with a worked example, glossary links and a Related list, using only facts the repository backs.
Build an agent
Find a route, fund it from your own vault, call the seller, check every receipt.
- Buyer quickstart: Go from nothing to a first paid token: pin an index, find a route for an exact model, open a channel from your vault, stream a reply and pay its receipt.
- The SDK: The @im/sdk package is DIM's TypeScript buyer client; it verifies discovery, manages channels, signs holds, checks receipts and pays by voucher.
- MCP tools: The discovery index serves two read-only MCP tools, list_routes and get_route, over stdio or HTTP; each result is signed and bound to your exact call.
- Choosing a route: Filter routes by exact model, policy and fresh capacity, then rank by price, latency and throughput, weighing each probed number by its sample size.
- Funding a vault, a Mandate and a channel: Money flows vault to channel; an owner deposits USDC, optionally writes a Mandate for an agent, and each channel locks a budget for one seller.
- Calling a seller: Send an OpenAI-compatible chat request straight to the seller with hold headers and a salt; the receipt returns as a header or a final im_receipt event.
- Verifying receipts and recomputing charges: Check the seller's signature and the receipt's binding to your hold, then recompute the charge from token counts and signed rates, with a worked example.
- Paying with vouchers: The SDK pays sellers by signing vouchers for verified receipts, batched automatically; call flushVouchers to wait for acknowledgment before closing.
- Closing channels and getting leftovers back: Flush vouchers, call beginClose to start the grace period, then finalize once the deadline passes; the unspent budget returns to your vault's free balance.
- Errors from sellers, the SDK and the program: A 402 means the seller refused your hold, a 429 means the route is full, and policy errors mean no route or Mandate allows the request; none of them is billed.
- Budgets for agent swarms: Run many agents on one client with a lane each, size channels for concurrency times cap, and give sub-agents narrower child Mandates that one revocation stops.
- Recovery after a restart: The SDK journals every hold, outcome and voucher before acting, so after a crash you reattach, recover pending receipts and keep paying without paying twice.
Sell inference
List an exact model, admit funded requests, sign receipts, redeem vouchers.
- Sell inference on DIM: Sellers run a gateway in front of their own inference server and are paid per token in USDC from buyer channels, with no signup and no custodian.
- Set up the gateway: Install Bun, create three keys and a payout account, write gateway.json, start the gateway in front of your model server and expose it over HTTPS.
- Gateway configuration reference: Every field the gateway CLI reads from gateway.json, with its type, default and the rule the gateway enforces at startup.
- Backend adapters: The gateway ships OpenAI-compatible and Anthropic Messages adapters, plus a small BackendAdapter interface with fixed rules for usage and stream endings.
- The Bifrost reference adapter: Bifrost is DIM's chosen reference gateway adapter; the native plugin is not shipped yet, so today Bifrost runs as an upstream behind the DIM gateway.
- The listing document: Your listing is a JSON document signed by your listing key at /.well-known/inference-marketplace.json that binds each route to an identity, prices and keys.
- Model identity and route_id: A model identity is the exact weights, quantization and serving stack you run; its hash, your endpoint, seller key and nonce together fix the route_id.
- Price schedules and the charge formula: A schedule sets four per-million-token rates and a per-request fee in micro-USDC; the charge is computed in integers and rounded up once per request.
- Capacity reports: The gateway signs a capacity report per route at /im/v1/capacity; buyers route to you only while it is under 120 seconds old and shows headroom.
- Admission rules: The gateway admits a request only if its signed Hold matches a funded open channel, route and prices; otherwise it answers 402, 429 or 503 first.
- Signing receipts and billing by outcome: Every admitted request ends in exactly one 382-byte receipt signed by your receipt key, whose status decides the charge: full, input plus fee, or zero.
- Accepting vouchers and redemption: Buyers post cumulative vouchers over your receipts; the gateway checks the chain and exact delta, acknowledges durably, then redeems the latest on Solana.
- Payouts: Redemptions transfer USDC from the buyer's program vault straight into your payout token account; there is no marketplace balance, fee or withdrawal step.
- Policies: ZDR and region: Each route declares zero data retention and serving regions in its signed listing; buyers filter on them exactly, but the MVP does not verify them.
- The onboarding self-check: The Sell page at /providers/onboard builds your gateway.json and runs five checks that move a route from Preview to Published, Verified and Discoverable.
- Operating and monitoring: Monitor the gateway through its control socket, its signed public documents, your Solana balances and the indexer's view; it logs no requests.
- Rolling deploys and key rotation: On Linux a new gateway generation takes over the same port and ledger while the old one drains, so restarts, upgrades and key rotations fail no paid request.
- Seller troubleshooting: What each gateway error code means for a seller, the usual cause, and the fix, from startup failures to 402 refusals, voucher errors and missing payouts.
Verify and rank
Probe routes, sign observations, rank from evidence and settled usage.
- Verify and rank: Probe operators buy ordinary inference from sellers and sign what they measured; indexers attest to what they serve; clients rank from that evidence themselves.
- Run a prober: Create an operator key, restrict the host's egress, write probe.json and run a no-pay loopback smoke test before probing paid sellers on devnet.
- Fund paid probes: Paid probes pay sellers like any buyer, from a dedicated devnet vault, through a local SDK payment module with a durable wallet and a conservative budget.
- Probe measurements: Each probe window runs streaming waves at concurrency 1, 4, 16 and 64 and reports nearest-rank TTFT, tokens per second, a throughput curve and availability.
- Observation documents: An observation is one probe window signed by the operator key as an IM/JSON/1 envelope, posted to /v1/observations and accepted only from allowlisted operators.
- Evidence levels: DIM separates seller claims, independent probe observations, settled economic evidence and attestation, and labels which of them back each route fact.
- Ranking methodology: DIM publishes no single score; the indexer serves signed inputs and every client ranks by its own criterion, with sample sizes and time windows kept visible.
- Index attestation: Every discovery response, errors included, is signed by the indexer's pinned attestation key and bound to the exact query and a timestamp within 300 seconds.
- Run an indexer: The discovery service crawls the sellers you pin, accepts observations from operators you allowlist, and signs every REST and MCP answer it gives.
- Disputes and what the chain can decide: The settlement program enforces signatures, budgets and deadlines; it never sees receipts or output quality, and the MVP has no on-chain dispute process.
- Prober operations: Run the prober under a supervisor in watch mode, reload keys and pins with SIGHUP, and roll releases over the same journal so no window is lost or paid twice.
Protocol reference
Messages, accounts, instructions, HTTP and Discovery APIs, byte for byte.
- Conventions: Integers are little-endian, keys and hashes 32 bytes; signed messages open with a 16-byte type tag and a 64-byte domain; JSON is signed as RFC 8785 bytes.
- Price schedule: A seller's signed price schedule sets per-million-token rates and a per-request fee; the charge is rounded up once and can never exceed the buyer's cap.
- IM/HOLD/1: IM/HOLD/1 is the 275-byte message a buyer's session key signs to admit one request; it caps the charge and is never payable on-chain.
- IM/VOUCHER/1: IM/VOUCHER/1 is the 168-byte cumulative payment message a buyer's session key signs; it is the only message the settlement program pays out on.
- IM/RECEIPT/1: 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.
- Receipts commitment chain: A voucher commits to the receipts it pays with a SHA-256 hash chain from C0 = SHA256("IM/EMPTY/1"), appended in (created_at, request_id) order.
- On-chain accounts: The im-channels program keeps three account types, Vault, Mandate and Channel, each a PDA with an 8-byte Anchor discriminator and a version byte.
- Instructions: Every im-channels instruction with its discriminator, data layout, accounts, signer, checks, effects and the program errors it can return.
- Channel lifecycle: A channel is Open until begin_close sets its deadline D, stays redeemable until D, and is then closed by a permissionless finalize that refunds the rest.
- Seller HTTP API: A seller gateway publishes a signed listing and capacity, admits chat requests that carry a signed Hold, returns a signed receipt and accepts vouchers.
- Discovery API and MCP tools: The discovery indexer serves verified routes over REST and MCP; every response, errors included, is a signed envelope bound to its request.
- Error codes: Every error code in one place: settlement program errors, gateway admission, chat and voucher codes, discovery codes and protocol library codes.
- Test vectors: The shared fixture crates/im-protocol/vectors/v1.json pins every protocol byte; the TypeScript, Rust and Python implementations all reproduce it.
- Versioning: Messages are versioned by their type tag, accounts by a version byte, and a new settlement program is a new address that buyers choose to fund.
- Decision records: The architecture decision records behind the protocol, with what each decided, its status, and a link to the full record.