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

NameTypeRequiredDescription
modelstringYesA model id from GET /v1/models.
messagesarrayYesThe conversation, as role and content pairs.
max_tokensintegerNoThe most tokens the reply may use.
streambooleanNoSend the reply as server-sent events.
stream_optionsobjectNoWith include_usage, the last event carries token usage.
toolsarrayNoTool 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": { … }, … }
}