Cost & usage metadata

Every /v1 response carries the real cost and metered usage of the call in X-RelayX-* headers — reconcile spend without scraping /pricing or guessing usage. JSON endpoints include it in the body too.

Response headers

Present on every /v1 response, including binary ones (TTS audio, etc.) where the body cannot carry metadata.

HeaderDescription
X-RelayX-Request-IdUnique id for this call. Stable handle for support & reconciliation.
X-RelayX-ModelThe model id actually served (public id, never the upstream id).
X-RelayX-Cost-UsdReal charge for this call, USD, fixed 6 decimals (e.g. 0.024100).
X-RelayX-UsageMetered usage as JSON — shape depends on the endpoint (see below).
X-RelayX-Upstream-Latency-MsUpstream provider latency for this call, in milliseconds.
$ curl -i https://relayx.timor419.com/v1/chat/completions ...

HTTP/2 200
x-relayx-request-id: rx_chat_Ycst4mFQdHllDMq1
x-relayx-model: deepseek/deepseek-v4-flash
x-relayx-cost-usd: 0.000002
x-relayx-usage: {"input_tokens":11,"output_tokens":1}

X-RelayX-Usage by endpoint

EndpointUsage
POST /v1/chat/completions{"input_tokens":N,"output_tokens":N}
POST /v1/embeddings{"input_tokens":N,"vectors":N}
POST /v1/audio/speech{"chars":N}
POST /v1/audio/transcriptions{"seconds":N}
POST /v1/images/generations{"images":N,"size":"1024x1024"}
POST /v1/videos/generations{"seconds":N}

In the JSON body

JSON endpoints also carry the cost in the body, so you do not have to read headers. For chat, the OpenAI usage object gains cost_usd and model — the standard prompt_tokens / completion_tokens fields are unchanged, so existing OpenAI SDKs keep working.

"usage": {
  "prompt_tokens": 11,
  "completion_tokens": 1,
  "total_tokens": 12,
  "cost_usd": 0.000002,
  "model": "deepseek/deepseek-v4-flash"
}

TTS, ASR, image and video JSON responses expose the same figure as x_relayx.cost_usd.

Streaming

Streaming chat (stream: true) cannot return the Cost-Usd or Usage headers: token totals are only known when the stream ends, after the headers have already been sent. Streamed responses still carry X-RelayX-Request-Id and X-RelayX-Model. To get cost/usage for a streamed call, pass stream_options: { include_usage: true } to receive a final usage chunk, or reconcile later by X-RelayX-Request-Id.

Cost precision

X-RelayX-Cost-Usd is a fixed 6-decimal string — read this for the exact charge. The body cost_usd is a JSON number. Costs are quantized to micro-cents ($0.000001), so the smallest non-zero charge is 0.000001 and values never use exponential notation.

Reconciliation

Pull real charges for your account over any window with GET /v1/usage, or look up a single call by its id with GET /v1/usage/{request_id}. Both are scoped to your account; summary totals the whole range. Usage is written asynchronously, so a call made moments ago may take a few seconds to appear.

$ curl "https://relayx.timor419.com/v1/usage?from=2026-05-01&to=2026-05-31" \
    -H "Authorization: Bearer $RELAYX_KEY"

{
  "object": "list",
  "from": "2026-05-01T00:00:00.000Z",
  "to": "2026-05-31T00:00:00.000Z",
  "summary": { "count": 128, "cost_usd": 1.234567 },
  "has_more": false,
  "next_cursor": null,
  "data": [
    {
      "request_id": "rx_chat_Ycst4mFQdHllDMq1",
      "created": 1779860223,
      "modality": "llm",
      "model": "deepseek/deepseek-v4-flash",
      "status": "success",
      "cost_usd": 0.000002,
      "usage": { "input_tokens": 11, "output_tokens": 1 },
      "upstream_latency_ms": 2533
    }
  ]
}

# single call by id
$ curl https://relayx.timor419.com/v1/usage/rx_chat_Ycst4mFQdHllDMq1 \
    -H "Authorization: Bearer $RELAYX_KEY"

Params (all optional): from, to (ISO 8601 or unix seconds; default last 30 days), modality, limit (1–1000), cursor (from next_cursor for the next page).