DIM · Dagon Inference Marketplace

Gateway configuration reference

bun services/gateway/src/cli.ts --config <file> reads one JSON file. Path fields are resolved relative to the config file. Integers must be non-negative safe integers; anything else fails startup. Unknown top-level fields are ignored, so check spelling against this table.

Command line

Flag Meaning
--config <file> Required. The JSON file below.
--backend <url> Replaces backend.url for every route. Route IDs and prices do not change.
--takeover Start as a replacement generation that takes over the ledger of a live gateway (rolling deploy, Linux).
--control status|maintenance|resume Talk to the live generation over its management socket and print {state, in_flight}. Cannot be combined with --takeover.

On Linux the CLI always runs the managed (rolling-deploy capable) gateway. On other platforms it runs a plain listener unless --takeover is given.

Identity, keys and chain

Field Type Default Notes
listingKeyFile path required JSON byte array: 32-byte Ed25519 seed or 64-byte Solana keypair. Its public key is the seller ID.
receiptKeyFile path required Same format. Signs receipts.
settlerKeyFile path required Same format. Fee payer for redemptions and the seller_settler channels must name. Fund it with SOL.
keyEpoch integer 0 Epoch of the active receipt key, at most 4,294,967,295.
payoutToken base58 required SPL token account for the program's mint. Every route pays here.
rpcUrl URL required Solana JSON-RPC. The CLI reads the genesis hash from it at startup to build the signing domain. Use a history-enabled RPC for settlement.
wsEndpoint URL derived from rpcUrl Set it when the WebSocket URL differs.
programId base58 2grG8aUKE1HRjE8FqG4h5C2tmfAUG7PLsS8yL4nKrjdW The im-channels program to settle against.
idlPath path tracked programs/idl/im_channels.json If set, the file must exist and its Anchor address must equal programId.
rpcTimeoutMs integer 8000 Per RPC call; 1 to 2,147,483,647.
channelCacheTtlMs integer 15000 How long a channel snapshot stays valid without a refresh. The view refreshes at half the TTL and fails closed on stale or missing state; it never calls RPC on the request path.

Rotation

Field Type Notes
nextReceiptKeyFile, nextReceiptKeyEpoch path, integer Publishes a future receipt key in receipt_keys without signing with it. The epoch must be greater than keyEpoch. Both or neither.
retiredReceiptKeys [{ "key": base58, "keyEpoch": integer }] Old receipt keys that stay in receipt_keys so their receipts still verify. At most 255 extra keys in total.
retainedSettlers [base58] Old settler public addresses. Channels that name them are still served and redeemed; the new settler pays the fees.

See operations for the rotation procedures.

Ledger and durability

Field Type Default Notes
ledgerPath path required SQLite file. Must be file-backed: the Solana redeemer refuses :memory:. On Linux the gateway also writes <ledgerPath>.claims (claim journal) and <ledgerPath>.deploy.sock (management socket).
ledgerMode "legacy" | "shared" "legacy" (exclusive) shared is an opt-in, Linux-only authority for overlapping generations. The two formats refuse each other. Shared mode is not latency-qualified.
claimJournalWorker boolean true on Linux file ledgers false restores the in-loop group commit. Exclusive ledger only.

Keep the database, its WAL and the .claims file together on private local storage (not NFS).

Limits and timing

Field Type Default Notes
hostname string 0.0.0.0 Listen address. Use 127.0.0.1 behind a local TLS proxy.
port integer 8000 Listen port.
timeoutMs integer 120000 Whole-request deadline after admission. Expiry ends the request as failed (504 backend_timeout, charge 0).
uploadTimeoutMs integer min(5000, timeoutMs) Deadline for receiving the request body. A stalled upload holds no inference slot.
requestLimit integer 2097152 (2 MiB) Maximum chat body bytes actually read. Larger bodies get 413.
settlementIntervalMs integer 2000 How often the settler relays pending vouchers.
settlementBatchSize integer 16 Pending vouchers taken per settler pass; up to four channels are relayed concurrently.
cryptoWorkers integer 0 1–16 moves Hold verification and receipt signing into worker isolates; 0 uses prepared inline keys (the measured default).
idlePollCpus integer[] unset Linux only. Must equal the process CPU affinity exactly or startup fails. Runs one lowest-priority spinner per listed CPU; those CPUs show 100% busy. List only CPUs reserved for the gateway.

Routes

routes is a non-empty array. Each entry:

Field Rule
nonce 64 lowercase hex characters (32 bytes).
endpoint Public http(s) URL with path exactly /v1/chat/completions, no credentials, query or fragment.
modelIdentity {family, revision, quantization, serving: {engine, engine_version, gpu, gpu_count, max_concurrency}}. Strings non-empty, gpu_count ≥ 0, max_concurrency ≥ 1. See model identity.
schedule The price schedule; see pricing.
policy { "zdr": boolean, "region": [non-empty strings] }. See policies.
backend.kind "openai" (default) or "anthropic".
backend.url Base URL of the upstream. No credentials, query or fragment. /v1/chat/completions (OpenAI) or /v1/messages (Anthropic) is appended unless already present.
backend.model Model name sent upstream. It replaces whatever model the buyer sent.
backend.apiKeyFile Optional path to a text file holding the provider key. Leading and trailing whitespace is trimmed; inner whitespace is rejected. Sent as Authorization: Bearer (OpenAI) or x-api-key (Anthropic).

Two routes with the same route ID are rejected. The buyer's own authorization headers and the X-IM-* headers are never forwarded upstream.

A configuration that will not start

These all fail with the single startup error line:

  • a key file that is not a JSON array of 32 or 64 bytes, or a 64-byte keypair whose public half does not match;
  • the listing, receipt and settler keys not all distinct;
  • nextReceiptKeyEpoch without nextReceiptKeyFile, or not greater than keyEpoch;
  • ledgerMode other than shared or legacy;
  • idlePollCpus that differs from the process affinity;
  • an RPC that does not answer getGenesisHash within rpcTimeoutMs.