Choosing a route
To choose a route, first filter: the exact model identity you want, the policy you require (zero data retention, region), a fresh capacity report with headroom, and a minimum cap you can afford. Then rank what is left by price, latency and throughput, and weigh every probed number by its sample size and time window. DIM deliberately has no single universal score; the SDK's planner ranks for you by default, and you can rank differently.
The code on this page assumes the sdk, routes and one route from the buyer quickstart.
Step 1: filter
A route is eligible for a request only if all of these are true. The SDK's planner applies exactly this list:
- its
model_identity_idis the one you asked for, or in your explicit allowlist; - it matches
routeIdif you pinned one; - it declares
zdr: trueif you require zero data retention; - its
policy.regionlist includes your region, if you set one; - its price schedule is already effective;
- it has a capacity report that is not from the future, still fresh, and shows
headroom > 0; - your request's cap is at least the route's
w_req_micros.
Step 2: compare prices properly
Compare the charge for a request shaped like yours, not a single rate. A route with cheap output but a high per-request fee loses on short answers. The SDK's planner prices every route at a reference request of 1,024 input and 256 output tokens with the real charge rule. You can do the same:
import { computeCharge, Status } from "@im/protocol";
const typical = { input: 3_000n, cachedInput: 1_000n, outputVisible: 600n, outputHidden: 0n };
const byPrice = [...routes].sort((a, b) => {
const pa = computeCharge(a.schedule, typical, Status.Ok);
const pb = computeCharge(b.schedule, typical, Status.Ok);
return pa < pb ? -1 : pa > pb ? 1 : 0;
});
for (const r of byPrice) console.log(r.id.slice(0, 8), computeCharge(r.schedule, typical, Status.Ok), "micro-USDC");
Step 3: read the evidence, with its sample size
Each SDK Route carries the best current probe observation from your pinned operators in route.observation, or null:
ttft_ms_p50andttft_ms_p95: time to first token;tps_p50: output tokens per second;availability: successes in basis points (9,950 means 99.5%);throughput_curve: tokens per second and error rate at each tested concurrency;samples,window_start,window_end: how much evidence and from when.
Rules of thumb:
- Small samples are weak evidence. A p95 from a dozen requests can swing widely. Prefer a route with fewer milliseconds only when its sample count is comparable.
- Old windows are stale. By default the SDK stops using an observation 600 seconds after its window ends; the index serves windows for 900 seconds.
- No observation is not a bad observation. It means no pinned operator measured the route recently. You can still use it; you are simply relying on the seller's claims.
- Capacity changes by the second. The SDK treats a capacity report as fresh for 30 seconds by default. Call
sdk.refresh(discovery, { modelIdentityId })regularly.
The index's REST list can also return up to 24 hours of retained windows per route with GET /v1/routes?family=…&observation_history=1, if you want to judge stability over time.
Step 4: let the planner rank, or rank yourself
AdaptivePlanner, the SDK default, scores every eligible route and takes the lowest score; ties go to the lower route ID. The score adds:
- price: the charge for the 1,024-in / 256-out reference request, in micro-USDC, times
priceWeight(default 1); - latency: the route's time to first token, from your own receipts once you have them, else the probe's p95, else 100 ms, scaled up by current load;
- decode time: the time to generate 256 tokens at the measured throughput, scaled by load;
- queue: the seller's reported queue depth times latency.
It then adapts while you run: it starts each route at its signed headroom or the throughput knee of its probe curve, grows the window as requests succeed, cuts it on 429, 5xx or sustained latency inflation, and honors Retry-After on the route that sent it. Make price matter more or less with new AdaptivePlanner({ priceWeight }), or supply your own RoutePlanner; a custom planner still cannot bypass the policy, headroom, wallet or signature checks.
To pin one route by hand, pass routeId on the call:
const reply = await sdk.chat.completions.create(
{ model: "my-model", messages: [{ role: "user", content: "One sentence on channels." }] },
{ routeId: route.id, capMicros: 10_000n },
);
console.log(reply.choices[0]?.message.content);
Ranking profiles
The architecture calls for several documented ranking profiles (by price, speed, reliability, verification or policy) and for rankings that include settled usage. What ships today is narrower: the SDK planner's one score with a tunable price weight, your own planner, and the Markets board on this site, where you sort routes by price, tokens per second, time to first token, success rate or room. The index itself returns evidence (score_inputs: advertised headroom and the latest measurement), not a rank.