Build

How routing works.

How a request picks a route, what changes its price, and what happens when every route fails.

On this page

Dispatch, our real-time routing engine. Every provider competes, the cheapest wins. Every request is a live competition. Each provider that serves the model you ask for quotes on it, the quotes that meet your rules compete, and the best one for your mode wins. You get a receipt for every request.

A quote is what the request is expected to cost on a route at that route's current price for the model: your input tokens, plus the output estimated from max_tokens, or from the model's recent average answer when you send no max_tokens.

  • Buying direct gives you one provider at its own price. Dispatch puts every provider of the model in competition.
  • Other routers add a platform fee to the source price. Dispatch charges below the source price, with no platform or top-up fee.
  • A provider that fails hands the request to the next one, and zero retention is the default wherever the model has a route that keeps nothing.

One request: the fastest provider of the model, zero retention, and a price ceiling.

Copy and run

curl
curl https://api.usdf.fi/v1/chat/completions \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash:fastest",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 256,
    "provider": {"zdr": true, "max_price": {"prompt": 1, "completion": 4}}
  }'

A mode tells Dispatch what wins when providers compete.

ModeWhat wins
cheapestThe default. The lowest price among providers that are working now.
fastestThe highest median output speed over the last 7 days. Speeds within 1 token a second are a tie, and the cheaper quote wins. A route with fewer than 5 timed requests ranks after every route with 5 or more.
smartestThe model with the highest quality score. It needs several models in scope and a price cap.
efficientThe most tokens for each dollar and each watt. Measured on Foundry's own operators, estimated from public data elsewhere.
autoAuto picks the best model for your prompt, at the lowest price.

Efficient ranks the routes that can serve a request by tokens per dollar per watt: the tokens a dollar buys at each route's price, times the tokens each watt-hour yields there. Foundry's own operators report the power they draw while they generate, so their figure is measured; other routes use public per-model energy figures and are marked estimated. A route with no energy figure comes after those with one. In the other modes the same figure settles a tie that price and speed leave open.

Send mode in the request, or add it to the model id after a colon: deepseek-v4.1-flash:fastest. The colon counts only when the word after it is exactly a mode name.

Cost tiers, for auto and smartest: economy, balanced or premium. Doubling the price must buy 5, 2 or 0.5 more quality points.

On a model with a route that promises to keep nothing, zero retention is the default: only those routes can win. A request that allows retention lets the others compete too.

Append a suffix to any model id, or send the same ask as a provider preference in the request body:

deepseek-v4.1-flash:cheapest
deepseek-v4.1-flash:fastest
glm-5.3-flash:private
{
  "model": "glm-5.3-flash",
  "messages": [ ... ],
  "provider": { "private": true }
}

:cheapest

Or provider.sort: "price". Eligible routes go cheapest first. Every model is below its source price, and the cheapest provider wins.

:fastest

Or provider.sort: "latency". The highest median output speed over the last 7 days wins; speeds within 1 token a second are a tie, and the cheaper quote wins. A route with fewer than 5 timed requests ranks after every route with 5 or more.

:private

Or provider.private: true. Runs on attested hardware the gateway has verified, at the same price. See Private inference.

A response and its receipt always name the model without the suffix. The :batch suffix is not a routing order. It submits an asynchronous job instead; see Batch jobs.

Add rules to any request. A provider that breaks a rule does not compete.

RuleWhat it does
price_capThe most the whole request may cost, in USD. Refused with 402 price_ceiling_exceeded before any charge.
max_ttft_msThe longest wait for the first token. A slower provider goes last.
min_tpsThe slowest output you accept, in tokens a second.
regionOnly providers that process in this region, such as "us" or "eu". If none of the model's providers does, the request is refused before anything is charged (404 no_route_for_policy).
zero_retentionOnly providers that keep nothing of your request. true on a model with no such route is refused, nothing charged (409 retention_required).
no_trainingOnly providers that never train on requests. A model with none is refused, nothing charged (404 no_route_for_policy).
providers, modelsallow and deny lists, with * for any text.
cost_tierFor auto: economy, balanced or premium.

Rules in a request

{
  "model": "auto",
  "messages": [{ "role": "user", "content": "Summarise this contract." }],
  "rules": { "price_cap": 0.02, "zero_retention": true, "cost_tier": "balanced" }
}

Send a provider object in the request body. These fields shape routing:

FieldTypeEffect
zdrBooleanA model with a zero-retention route always uses it. A model marked 'provider may keep data' is served by a provider that may keep request data when you choose it.
data_collection"allow" or "deny""deny": only routes whose policy says content is not used for training.
privateBooleanRuns on attested hardware the gateway has verified, at the same price.
attested_onlyBooleanAttested enclaves only. Implies private.
regionStringOnly routes whose upstream publishes that processing region, as a lowercase code such as "us".
only, ignoreArray of route kindsRoute kinds to allow or exclude: hosted, network or private.
sort"price", "latency" or "throughput"The order routes are tried in. "throughput" is the same as "latency".
allow_fallbacksBooleanfalse: the first route only.
max_price{ prompt, completion }A price ceiling. See Price ceiling.

The full field list is in the API reference.

Models with a zero-retention route use it by default. A model marked 'provider may keep data' is served by a provider that may keep request data; choosing it is your choice. GET /v1/models shows it as may_keep_data. Picking the model is the only opt-in.

Ask for a policy

curl https://api.usdf.fi/v1/chat/completions \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 256,
    "provider": {"zdr": true, "data_collection": "deny", "sort": "price"}
  }'

A route whose policy is not verified is never used for a request that asks. GET /v1/models shows each model's policy with no key: retention, zdr, may_keep_data and may_train. Signed in, each model's policy_asks in GET /v1/pricing says whether such a request has a route for it. A route with no published region is never used for a request that names one. On a multipart endpoint, send provider as a JSON string form field.

provider.max_price sets the most a request may be charged per 1M tokens, in USD: prompt for input, completion for output.

It is compared with every rate the request can be billed at. The input, cached-input and cache-write rates count against prompt; the output rate against completion. Past a model's long-context threshold, its long-context rates count instead.

Set a price ceiling

curl
curl https://api.usdf.fi/v1/chat/completions \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4.1-flash",
    "messages": [{"role": "user", "content": "Hello"}],
    "max_tokens": 256,
    "provider": {"max_price": {"prompt": 1, "completion": 4}}
  }'

A model above the ceiling is refused with 404 no_route_for_policy, naming the rates above it. Nothing is held. The ceiling applies to token-priced endpoints only: chat, completions, embeddings and rerank. A model that is not priced per token, which covers most speech, transcription, image and video models, refuses it with 400 max_price_unsupported.

Before the first token, the request's worst case is held: that is its price cap, and you never pay more.

You pay only for the tokens actually used, and the rest of the hold goes back to your balance.

Models with a zero-retention route use it by default. A model marked 'provider may keep data' is served by a provider that may keep request data; choosing it is your choice.

What each route does with request content is in Privacy.

A provider that fails never becomes your error. A request tries its eligible routes cheapest first, with a route that is failing now after the others, until one of them serves it, and you pay only for the one that answered. Set allow_fallbacks to false and it runs on the first route only; if that one fails, the request fails instead of moving on.

{
  "model": "deepseek-v4.1-flash",
  "messages": [ ... ],
  "provider": { "allow_fallbacks": false }
}

A request with no eligible route is refused before anything is tried, with 404 no_route_for_policy. Nothing is held. When every eligible route is tried and fails, the answer is 502 upstream_unavailable, or 504 upstream_timeout when no provider answered before the deadline. The hold is released first.

A provider that refuses the request itself is different: the request is at fault, so the answer is 400 upstream_rejected and it never crosses to a fallback model.

Set any of these once for every key on the account with PATCH /v1/account/settings, under the session: zdr, data_collection, sort, provider_allow, provider_deny, allow_fallbacks and max_price. On the dashboard: Settings.

Set account defaults

curl
curl -X PATCH https://api.usdf.fi/v1/account/settings \
  -H "Authorization: Bearer $SESSION" \
  -H "Content-Type: application/json" \
  -d '{
    "zdr": true,
    "sort": "latency",
    "provider_deny": ["network"],
    "allow_fallbacks": true,
    "max_price": {"input": 1, "output": 4}
  }'

In the settings, max_price takes input and output. The gateway applies provider_allow and provider_deny as the request's own only and ignore. A request's own provider field overrides the routing ones (sort, the provider lists, allow_fallbacks, max_price), and an empty only or ignore list clears the account's. A model with a zero-retention route always uses it. A model marked 'provider may keep data' is served by a provider that may keep request data when you choose it. The account's data_collection: "deny" holds for every request. Defaults apply to requests made with a key; a request paid per request carries only its own asks.

A preset is a named request config of the account: a model (or models, the first that can serve), provider preferences, params and a system prompt. Make and change presets under the session; call one with any of the account's own keys. On the dashboard: Presets.

Make a preset

curl
curl -X POST https://api.usdf.fi/v1/presets \
  -H "Authorization: Bearer $SESSION" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "support-bot",
    "config": {
      "model": "deepseek-v4.1-flash",
      "params": {"temperature": 0.2, "max_tokens": 512},
      "system": "Answer as the support team, in two sentences."
    }
  }'

Response, 201, trimmed

{
  "object": "preset",
  "slug": "support-bot",
  "version": …,
  "versions": …,
  "config": { … },
  "use": {
    "model": "@preset/support-bot",
    "preset": "support-bot",
    "pinned": "@preset/support-bot@<version>"
  },
  …
}

Name it as the model, @preset/support-bot, or send "preset": "support-bot". The request's own model, parameters and provider fields win; the preset's system prompt is used when the request sends no system or developer message, and its tools when a chat request sends none.

A preset can carry a mode and rules too, a price cap among them. A request that names the preset and sends no mode or rules of its own runs with the preset's; anything the request sends itself wins.

Call a preset

curl
curl https://api.usdf.fi/v1/chat/completions \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "@preset/support-bot",
    "messages": [{"role": "user", "content": "Where is my invoice?"}]
  }'

Every save is a new version, and every version is kept. Requests use the newest; @preset/support-bot@<version>, or "preset": "support-bot@<version>", uses that version whatever is saved later. A version the preset does not keep is refused with 404 preset_version_not_found.

EndpointWhat it does
GET /v1/presets, POST /v1/presetsThe account's presets at their current versions; make one with slug and config. The list's limits give the most presets and versions.
GET /v1/presets/{slug}One preset at its current version.
PATCH /v1/presets/{slug}Saves a new version. PUT and POST are taken the same.
DELETE /v1/presets/{slug}The preset and every version.
GET /v1/presets/{slug}/versionsIts versions, newest first; before and limit to page.
GET /v1/presets/{slug}/versions/{n}One version's config.
POST /v1/presets/{slug}/versions/{n}Saves version n again as the newest (restored_from names it).
POST /v1/presets/{slug}/shareShares it with an org you belong to (org_id). Its id, psh_…, is the link; every member uses it read only as @preset/psh_….
GET /v1/preset-sharesThe presets shared by you and with you; org keeps one org's.
DELETE /v1/preset-shares/{id}Withdraws a share: its preset's owner, or the org's owner or an admin.

List the versions

curl
curl https://api.usdf.fi/v1/presets/support-bot/versions \
  -H "Authorization: Bearer $SESSION"

Restore a version

curl
curl -X POST https://api.usdf.fi/v1/presets/support-bot/versions/1 \
  -H "Authorization: Bearer $SESSION"

The receipt and the request's detail name the preset and version used.

Every answer carries a receipt, with receipt.router and these fields.

  • model, the model that answered, and price_cap, the most it could have cost.
  • charge, what it cost, and saving, against the source price, in USD and percent.
  • providers_competed, how many providers quoted, and provider, shown as Foundry network.

GET /v1/receipts lists the caller's receipts, newest first: a key's own, or a session's whole account. GET /v1/receipts/{request_id} reads one.

Paid with a key

A request that serves nothing is not charged. One that fails after its hold is taken is marked failed_refunded: cost zero, and the hold back in the balance. The row gives the reason: no provider produced anything, the stream ended empty, or the gateway itself failed. It stays in the usage log at zero cost, so a refund is as checkable as a charge.

One exception: some providers bill reasoning they do not stream. On such a model, a stream you leave, or a call cut at its deadline, after the provider accepted it is billed its held output budget, as the provider bills it. The receipt says partial.

Paid with x402 or MPP

A request paid per request is charged what it used, and the rest of the payment is refunded in the asset it was paid in. If the gateway or the provider fails before any output, or the provider rejects the request itself, the whole payment is refunded.

A caller who leaves a stream is charged what the provider reports for it. On a model whose provider bills reasoning it does not stream, a request cut after the provider accepted it is charged the output budget it held, as the provider bills it. See Refunds and refusals.

See also: receipts, settlement and the public log

Foundry documentation

Confirm it's you

Confirm to continue the action you started.

Checking confirmation options…