Build
API reference.
The OpenAI-compatible endpoints, their parameters, and what each response carries.
On this page
The base URL is https:/. Requests and responses follow the OpenAI chat completions format. Messages and stateless Responses are also served.
Two ways to pay for a request:
- No account: send the same body with no key to the same path under
https:/and pay per request in USDF./ api. usdf. fi/ x402 - An API key, paid from your Foundry wallet or your Foundry balance: send
Authorization: Bearer sk_…to the path below.
The model endpoints and the reads around them, with what each needs:
| Endpoint | What it does | Auth |
|---|---|---|
POST / | Chat, streaming, tools and vision. Also submits batch jobs. | Key, or pay per request under /x402 |
POST / | Messages format. Any available chat model id; x-api-key or Bearer key. Base URL https://api.usdf.fi. Claude Code and the Claude desktop app: their setup. | Key |
POST / | Count input tokens for a Messages request. | Key |
POST / | Stateless Responses. Send conversation history in input. | Key |
POST / | Legacy text completions. | Key, or pay per request under /x402 |
POST /, /, /, /, /, /, /, / | The other modalities. See Modalities. | Key, or pay per request under /x402 |
GET / | The models that serve right now. In GET /v1/stats, models is the catalog every page counts; models_available is what serves right now. | None |
GET / | The full price sheet, every listed model. | None: the public prices need no key |
GET /, / | Every price sheet ever served. | Key or session |
GET /, /, / | The signed model catalog. | Key or session (the signer: none) |
GET /, / | A batch job, and its result. | Key |
GET / | Tools, their prices and input schemas. | None |
POST / | Runs one tool on the balance. | Key |
GET / | Your latest receipts. | Key or session |
GET / | One receipt, with its place in the usage log. | The key that made the request |
GET / | The public receipt of any request. | None |
GET / | Every rate limit, live. | Key or session |
GET / | The gateway's own health. | None |
Public data, with no key. Each one backs a page of the site:
| Endpoint | Returns | On the site |
|---|---|---|
GET / | The figures the site quotes, each with the endpoint it is read from. | Docs |
GET / | The attestation report behind private inference. | Private inference |
Every limit these reads share is in Rate limits. Account, agent, platform and receipt endpoints are on their own pages: Accounts and keys, Agents, Platforms and providers and Receipts. Every endpoint, token and receipt reads included, is in the API reference.
POST /v1/chat/completions takes the standard body. Samples use deepseek-v4..
Chat completion
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 }'
Response, trimmed
x-request-id: <request_id> x-cost-units: <units> { "id": "<request_id>", "object": "chat.completion", "model": "deepseek-v4.1-flash", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "…" }, "finish_reason": "stop" }], "usage": { "prompt_tokens": …, "completion_tokens": …, "total_tokens": … }, "receipt": { "request_id": "<request_id>", "status": "ok", "cost": { … }, … } }
The TypeScript samples use top-level await, so Node runs them only as a module: save one as a . file, or set "type": "module" in package..
The parameters the gateway reads:
| Parameter | Type | Required | Notes |
|---|---|---|---|
model | String | No | A model id. Suffixes such as :cheapest are in Routing. Left out, the request runs on Auto (auto), which picks the model and names it in the receipt's router. Sent as an empty string, it is refused with 400 missing_ and nothing is charged. |
messages | Array | Yes | Non-empty. Images go in message content. |
max_, max_ | Integer | No | Positive. Sets the hold. Above the model's max_, the request runs at the model's limit, and the receipt's output_ gives the max_ asked and the budget it ran at. A prompt that leaves the budget no room in the context window: 400 context_. |
stream | Boolean | No | Server-sent events. |
stream_ | Boolean | No | A final usage chunk. |
temperature | Number | No | 0 to 2. |
n | Integer | No | Must be 1. |
tools, tool_, parallel_ | Array, string or object | No | Function calling. |
response_ | Object | No | JSON mode or a JSON schema. |
reasoning_ | String | No | For reasoning models. |
top_, top_, min_, stop, seed, frequency_, presence_, repetition_, logit_, logprobs, top_, user | As OpenAI | No | Passed through to the provider. |
provider | Object | No | Routing and privacy. See Provider preferences. |
batch, webhook_ | Boolean, string | No | Submit as a job. See Batch jobs. |
- The deprecated
functionsandfunction_are refused withcall 400 unsupported_parameter. Usetools. - Fields that would change what the provider bills are dropped.
- Up to 16 images per request. More gets
400 too_many_images. - The response
idis the request id, also in thex-request-idheader. A response that is not streamed carries the cost inx-cost-units; a stream carries it in its receipt line.
How the hold is sized
The prompt is held at two bytes per token, plus eight tokens per message and 16 per request, plus max_. A model with long-context rates is held at one byte per token, so the hold never lands in a cheaper tier.
Without max_, the model's default output budget is held, shrinking to what the balance covers. The charge is the provider's reported usage; the rest of the hold is released.
Set "stream": true for server-sent events in the standard chunk format.
The order of events:
Server-sent events
data: {"id":"<request_id>","object":"chat.completion.chunk",…} data: {"id":"<request_id>","choices":[],"usage":{…}} : receipt {"request_id":"<request_id>","cost":{"units":"…","usd":"…","usdf":"…"},…} data: [DONE]
The receipt arrives as a comment line just before [DONE]. Standard clients drop comment lines, so read the receipt by id afterwards with GET /. Every chunk's id is the request id.
Stream, then read the receipt
curl -N https://api.usdf.fi/v1/chat/completions \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "deepseek-v4.1-flash", "stream": true, "stream_options": {"include_usage": true}, "messages": [{"role": "user", "content": "Hello"}] }'
POST /v1/completions serves only models whose endpoints include completions. prompt is a string, or an array of one string.
Text completion
curl https://api.usdf.fi/v1/completions \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "<model>", "prompt": "The capital of France is", "max_tokens": 16 }'
GET /v1/models lists what serves now. GET /, with no key needed, is the full sheet, every listed model with its prices and routes. The catalog's count is model_ on GET /v1/pricing/summary: every model the network's suppliers publish, each counted once whichever providers serve it, with its status. models_ counts the ones a request can be served by now. GET /v1/models and GET /v1/stats carry the same two figures. A model's own read adds model_: its context window and our price against its source price.
The fields of GET /v1/pricing:
| Field | Meaning |
|---|---|
version, unit | The sheet's version and its default unit. |
rate_ | days and valid_: how long the sheet's rates are promised. |
models[]., name, owned_ | The model id to send, its name and its maker. |
modality, unit | What the model does, and what its price is per. |
endpoints | Where it serves: chat, completions, embeddings and others. |
context, max_ | The context window and the largest output. |
price | input, output, cached_, cache_, cache_, the batch rates batch_, batch_, batch_, batch_, batch_, and long_ with its threshold. |
price_ | The private-tier rate. |
available, rate_ | Whether it serves now, and how long its price is promised. |
routes[] | Each provider route, with enabled and its data_. |
The rates in force are not locked: a later price sheet may change them, and each request is charged the lowest price for its usage among the sheet in force and every earlier sheet whose 30-day promise still holds. Every sheet ever served is at GET /v1/pricing/sheets, and the signed catalog at GET /v1/catalog. Browse them on Models.
Once a series opens, to fix a model's price for a whole month, you buy a compute lock.
A compute lock fixes today's price of one model for a month, so what you pay for it cannot rise. Each series is an onchain token: one whole token is a million tokens of its model at the series' locked price. A prompt token uses one unit of it and an output token uses the series' output weight. You use it, sell it or withdraw it to your wallet; what is left when the month ends lapses.
The status and every series' terms are read from GET /, which needs no key.
| Series | Model | Locked price (USDF per lock token) | Output weight | Expires (UTC) | Bond (USDF) | Status |
|---|---|---|---|---|---|---|
Each series' terms never change once it is listed; a new month is a new series. The bond is what the series' provider posts to answer for delivery (Serve a compute lock). Signed in, the same read adds each series' order book.
Series terms, no key
curl https://api.usdf.fi/v1/locks
Buy a lock
Buying takes one of your account's own API keys or your signed-in session, and your balance pays (Accounts and keys). Amounts are lock tokens with up to six decimals.
First the quote: what buying that many tokens would take from the book now, cheapest first, with its total and the order that buys it. It writes nothing.
Quote
curl https://api.usdf.fi/v1/locks/quote \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{"series": "<series id>", "tokens": "10"}'
Then the buy, with max_ set to the quote's total. It is filled whole at no more than that, or refused with 409 price_moved and nothing charged. The tokens are in your holding at once.
Buy at market
curl https://api.usdf.fi/v1/locks/orders \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{"series": "<series id>", "side": "buy", "tokens": "10", "max_total": "<quote total>"}'
A limit buy sends price instead of max_: the offers at or under that price fill at once, and the rest waits on the book with its price held from your balance until it fills or you cancel it.
Use a lock
Nothing changes in your requests. A request for the series' model from one of your account's keys is paid by the lock first: the series' provider serves it, the tokens it used come off your holding at the locked price, and your balance is not charged. Its receipt carries a lock part (the series, the tokens used, their locked value and what is left) and the response names the series in x-lock-series.
- With more than one series of a model, the one that expires first is used first, then the cheapest.
- If the series' provider cannot serve a request, another route serves it on the lock at no extra cost to you, while the provider's bond covers it; past that, the request goes to your balance.
- These stay on the balance: free-tier requests, priority and flex tiers, the private tier, batch jobs, an organization's keys and a platform's sub-keys, and a request whose provider preferences leave the series' provider out (Provider preferences).
- A request the lock cannot cover, or one sent after the series expired, is charged to the balance as usual.
Holdings, selling and withdrawing
Your holdings (free, in use by requests, offered, on their way to your wallet, lapsed), your orders, trades and uses:
Your locks
curl https://api.usdf.fi/v1/locks/mine \
-H "Authorization: Bearer $USDF_API_KEY"A sell offers tokens you hold at your price. It fills the bids at or above it first, each at the bid's own price, and the rest is offered on the book. An open order is cancelled by its id: a buy's hold goes back to your balance, a sell's tokens back to your holding.
Sell
curl https://api.usdf.fi/v1/locks/orders \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{"series": "<series id>", "side": "sell", "tokens": "1", "price": "<USDF per lock token>"}'
Cancel an order
curl -X DELETE https://api.usdf.fi/v1/locks/orders/<order id> \
-H "Authorization: Bearer $USDF_API_KEY"Tokens go to your account's linked wallet, sent by the next onchain run; GET /v1/locks/mine shows the transaction. Tokens sent back from that wallet to the custody wallet are credited with POST /v1/locks/deposits and the transaction's tx_, while the series is open.
Withdraw to your wallet
curl https://api.usdf.fi/v1/locks/holdings/<series id>/withdraw \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{"tokens": "1"}'
Expiry
A series expires at the first second of the month after its month (UTC), the time in its terms. Its book closes: open bids' holds go back to the balance and offers back to the holding. Requests already running finish, and every token left then lapses, in custody or in a wallet, with nothing refunded. Only if the series' provider is in default do its holders get the locked value of their lapsed tokens back on their balances.
Errors
| Code | Status | Meaning | What to do |
|---|---|---|---|
price_ | 409 | The book moved since the quote: the buy would cost more than max_total. Nothing was charged. | Ask for a new quote and buy with its total. |
not_ | 409 | The book does not hold that many tokens at or under the price now. | Buy fewer, or place a limit buy at your price. |
insufficient_ | 402 | The balance does not cover the order. | Fund the balance, then order again. |
insufficient_ | 409 | The holding does not have that many free tokens to sell or withdraw. | Read GET /v1/locks/mine: tokens offered or in use are not free. |
deposit_ | 409 | A deposit to the account is not final on the chain, so buys and withdrawals wait. Nothing was changed. | Retry in a few minutes. |
no_ | 409 | No wallet is linked: withdrawals go to the linked wallet and deposits come from it. | Link a wallet to the account. |
not_ | 409 | The series is not trading: not open, or expired. | Read its status in GET /v1/locks. |
defaulted | 409 | The series is in default and is not sold. | Choose another series. |
below_ | 400 | The order is under the smallest order. | Order at least the min_order in the rules. |
key_ | 403 | An organization's key, a platform's key or sub-key, or an agent's key. | Use one of the account's own keys or its signed-in session. |
locks_ | 503 | Compute locks are not available on the gateway right now. | Retry after Retry-After. |
Each series has one provider. Its endpoint serves every holder's requests for the series' model at the locked price for the whole month, and it posts a bond in USDF that answers for failed delivery.
What you need
- An account and an endpoint of yours registered as a provider that serves the model (Serve your own endpoint). Network nodes can serve a series once the network takes machines.
- A wallet address of yours: the bond comes from it, and your payments and the bond's release go back to it.
- The bond in USDF, set for each series and published with its terms (
bond.inrequired GET /).v1/ locks
The bond and the probes
Once your series is approved and listed, you send exactly its bond from your address to the treasury address you are given. A series is open once its token reads back onchain as listed and the bond is held.
Your endpoint is probed while the series runs, on the schedule in rules. of GET /; each failed probe moves a share of the bond to insurance.
Fallbacks and claims
When your endpoint fails or cannot serve a holder's request, the Foundry network serves it on the lock. That request's locked value is not yours, and what it cost above that value is a claim on your bond, settled at expiry. The Foundry network is tried only while the bond can still repay its worst case. Claims that use the bond up put the series in default: its holders' requests go to their balances, and at expiry they get the locked value of their lapsed tokens back.
Payments and the bond's release
- Every lock token your endpoint serves is owed to you at its locked value, paid in USDF to your address while the series runs.
- At expiry you are owed the rest of what holders paid for the series, used or not, less the locked value of what the Foundry network served and any refunds of a default.
- The bond is then released to the address it came from, less the probes' slashes and the fallbacks' claims.
Apply
Email protocol@usdf.fi with the model, the month, your endpoint's id, the locked price per lock token, the output weight, the supply and your address. A series is listed once it is approved, and its terms never change after.
A batch job runs at the upstream's batch rate. Submit it with a :batch model suffix or "batch": true, without stream. Add webhook_ to be told when it ends.
A job runs on a model whose price carries batch_ in GET /v1/pricing and one of whose routes serving now carries its upstream's batch rates.
Submit a job
curl https://api.usdf.fi/v1/chat/completions \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-haiku-4-5:batch", "messages": [{"role": "user", "content": "Hello"}], "max_tokens": 256 }'
Response, 202
{
"object": "batch.job",
"id": "batch_…",
"status": "submitted",
"rate": "batch",
"hold": { "units": "<units>", "usd": "<usd>", "usdf": "<usdf>" },
"price": { … },
"poll": "https://api.usdf.fi/v1/batches/batch_…",
"result": "https://api.usdf.fi/v1/batches/batch_…/result"
}Poll the job, then fetch its result: the completion and its receipt, which settles like every other request. Results return within 24 hours. The result is kept 7 days, then answers 410.
Poll and fetch
curl https://api.usdf.fi/v1/batches/<batch id> \ -H "Authorization: Bearer $USDF_API_KEY" curl https://api.usdf.fi/v1/batches/<batch id>/result \ -H "Authorization: Bearer $USDF_API_KEY"
How a job ends:
| Status | Meaning | Charged |
|---|---|---|
done | The result is ready. | Yes, at the batch rates |
failed | The upstream failed it. Its result answers 409 batch_. | No |
expired | The upstream did not finish in time. 409 batch_. | No |
The hold is taken at the standard rate and the charge is made at the batch_ rates when the result arrives.
A job is refused, and nothing is charged, in these cases:
| Case | Error |
|---|---|
| The model has no batch rates | 400 batch_ |
The body asks for stream | 400 batch_ |
| The key is in no-logs mode: a job's result is stored until fetched | 400 batch_ |
| The request asks for the private tier, or the key is private tier | 400 private_ |
| The request is paid per request | 400 batch_ |
| The gateway is not taking jobs right now | 503 batch_, with Retry-After |
GET /v1/tools is public. Each tool lists its price (flat per call, or a base plus a price per result), its enabled flag, and its input_.
POST / with a key runs one. The body is the tool's input. A call takes a hold, charges what it cost plus 5% at most, with no minimum, and writes a receipt. A call the tool's upstream refused or never answered costs nothing; one that failed after the upstream answered is charged what the upstream billed for it. A call to a tool whose enabled is false is refused with 409 tool_unavailable before any hold.
web. and web. send the query or the page to a search service that keeps its own records. They are marked "provider may keep data" and run as is when you call them.
The tools, read live:
| Tool | What it does |
|---|---|
The sample sends an input the tool's input_ takes (fx.).
Call a tool
curl https://api.usdf.fi/v1/tools/fx.rates \ -H "Authorization: Bearer $USDF_API_KEY" \ -H "Content-Type: application/json" \ -d '{"base":"USD","symbols":["EUR","GBP"]}'
The headers the gateway reads and sends:
| Header | Direction | Meaning |
|---|---|---|
Authorization | Request | A key, a session, a read token, or Payment for MPP. |
Content-Type | Request | application/, or multipart/ for uploads. |
Idempotency-Key | Request | Makes an agent's fund or pay call safe to repeat. |
x-approval-id | Request | Releases a request an agent's owner approved. |
x-erc8004-agent | Request | Names the ERC-8004 agent behind a paid request. |
X-Foundry-Title | Request | Your app's name, up to 100 characters, shown in the request's receipt and your activity. X-Title works too. |
X-Foundry-Referer | Request | Your app's URL; its scheme and host are kept and shown beside the name. HTTP-Referer works too. |
PAYMENT-SIGNATURE | Request | An x402 payment. |
x-request-id | Response | The request id, also the receipt id. |
x-cost-units | Response | What the request cost, in units, on a response that is not streamed. A chat or text completion paid per request carries receipt. instead. |
PAYMENT-REQUIRED | Response | The x402 payment requirements, on a 402. |
WWW-Authenticate: Payment | Response | The MPP challenges, on a 402. |
PAYMENT-RESPONSE | Response | The settled x402 payment. |
Payment-Receipt | Response | The settled MPP payment. |
Retry-After | Response | On a 429 or 503: how many seconds to wait. |
One public read shows how the gateway is doing:
| Endpoint | Returns |
|---|---|
GET / | ok, with the state of the chain and the database. |
curl https://api.usdf.fi/health