The router
The router is the product edge. It runs on every POST /v1/chat/completions and turns a buyer's request into a cleared trade.
One completion maps to one offer, one upstream forward, and one clear.
What it does, in order
- Resolve the Bearer key to a wallet and its max price.
- Acquire the per-wallet lock: one in-flight completion per wallet (
429if busy). - Pre-check the confirmed USDC balance against the estimated gross.
- Select supply: the cheapest eligible offer whose posted price is at or below the buyer's max and whose routable capacity is sufficient.
- Acquire the per-key lock; fall through to the next eligible key or wait FIFO if busy.
- Forward once to the supplier's upstream key.
- Meter the real capacity burn from the response.
- Settle in a single transaction and write audit rows.
Selection rules
- Cheapest eligible wins. Among offers at or below the buyer's max, the lowest posted price clears first.
- The clearing price is the posted ask. The buyer's max only filters; it never sets the price.
- No browsing. Buyers never see or choose individual sellers.
Serialization and limits
- One in-flight completion per wallet across all its API keys (
429 buyer_concurrency_limit). - One in-flight forward per supplier key; the router falls through or waits.
- Streaming is not supported in v1.
When nothing clears
If no eligible supply exists, the router returns 503 with one of no_eligible_supply, insufficient_routable_at_price, or pool_empty, plus headers indicating the cheapest posted price and routable capacity above your max. See Errors & limits.