API reference
Chat completions
Chat, streaming, tools and vision in the OpenAI chat completions format.
On this page
POST/v1/chat/completions
Runs a chat model. Send no key to the same path under /x402 to pay per request.
Auth: API key, or pay per request under https://api.usdf.fi/x402
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Yes | A model id from GET /v1/models. |
messages | array | Yes | The conversation, as role and content pairs. |
max_tokens | integer | No | The most tokens the reply may use. |
stream | boolean | No | Send the reply as server-sent events. |
stream_options | object | No | With include_usage, the last event carries token usage. |
tools | array | No | Tool definitions the model may call. |
POST /v1/chat/completions
curl
curl -X POST https://api.usdf.fi/v1/chat/completions \
-H "Authorization: Bearer $USDF_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "<model>",
"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": "<model>",
"choices": [{ "index": 0, "message": { "role": "assistant", "content": "…" }, "finish_reason": "stop" }],
"usage": { "prompt_tokens": …, "completion_tokens": …, "total_tokens": … },
"receipt": { "request_id": "<request_id>", "cost": { … }, … }
}Foundry documentation