Every charge on this API traces back to a single request id carrying its token counts, the model that answered and the exact price, exportable as CSV and totalled in a monthly statement that is signed so you can prove it has not been altered; this is how to reconcile an LLM bill line by line, from one response body up to the month's statement. The method has four levels, each checking the one below it.
Level 1: the request itself
Start where the money leaves: the response. A non-streamed answer in the OpenAI or Anthropic format carries usage.cost, the charge for that call in USD, next to the usual token counts, and the body's model field names the model that answered after any alias, preset or fallback. A streamed answer carries usage.cost in each usage event as a running figure; the last one (OpenAI's usage chunk with stream_options.include_usage set, Anthropic's message_delta) is the whole charge.
from openai import OpenAI
client = OpenAI(base_url="https://api.uplinkswitch.com/v1", api_key=KEY)
r = client.chat.completions.with_raw_response.create(
model="gpt-6.1-sol",
messages=[{"role": "user", "content": "Classify this ticket: billing, bug or other."}],
)
body = r.parse().to_dict()
print(body["model"], body["usage"]["cost"], body["usage"])
request_id = r.headers.get(...) # the request id in the response headersLog three things per call in your own system: the request id from the response headers, the body's model, and usage.cost. That is your side of the ledger, and everything below is checked against it.
Two billing rules matter at this level. Billed input can never exceed what the request could hold, so the tokens on a receipt are the tokens billed, and any fixed prompt a route adds is paid by UplinkSwitch, not you. And an answer that fails or is refused, or that misses a JSON schema the request asked for, is not billed; the refund shows up as a reason on the request's record rather than as a silent zero.
Level 2: look a request up
Within about a minute of finishing, every request lands in the usage log, and any key of the organization can read it:
curl https://api.uplinkswitch.com/v1/requests/REQUEST_ID \
-H "Authorization: Bearer $UPLINKSWITCH_API_KEY"The record has the model (after any alias), status and outcome, usage with input_tokens, cache_read_tokens, cache_write_tokens and output_tokens, charge_usd, the same tokens at the developer's list price as list_cost_usd, saved_usd, latency_ms and a refund field that is null or names the reason. This is also where a stream's figures live, since a stream's headers leave before its tokens exist.
Dispute test: multiply the record's tokens by the model's price on the price index (input, cached input and output are separate rates) and you should land on charge_usd to six decimal places. If the figures disagree, you have a request id to quote.
For latency rather than money, the console shows a timing trace per request: millisecond marks for auth, route, admit, each upstream attempt, first byte, end and settle. A request that cost more time than tokens explains itself there.
Level 3: the month as a file
The Usage page in the console shows each request beside its tokens and charge, filters by key, model and outcome, and exports the rows as CSV. The same file comes from the API:
curl "https://api.uplinkswitch.com/v1/usage/export?from=2026-10-01&to=2026-10-31&key_id=KEY_ID" \
-H "Authorization: Bearer $UPLINKSWITCH_API_KEY" -o october.csvColumns, oldest row first: request_id, created_at, key_id, session_id, model, outcome, status, input_tokens, cache_read_tokens, cache_write_tokens, output_tokens, charge_usd, latency_ms, refund_reason, user. Filters: from and to (dates or Unix milliseconds; the default window is the 30 days before to), key_id, model, status (including failed for upstream errors and rejections together) and user. One file covers at most 92 days and 200,000 rows, so a large month is pulled per key.
With the file, the reconciliation is a group-by:
import csv, collections
by_model = collections.defaultdict(float)
by_key = collections.defaultdict(float)
for row in csv.DictReader(open("october.csv")):
by_model[row["model"]] += float(row["charge_usd"])
by_key[row["key_id"]] += float(row["charge_usd"])
print(dict(by_model)); print(dict(by_key))Compare by_key with GET /v1/keys/{key_id}/usage, which gives a key's request count and spend over three windows: today (UTC), this month (UTC) and all time (add ?group_by=user for a per-end-user split from the user field). Compare the sum of charge_usd with the drop in your balance over the same window, and the refund_reason column tells you which rows were not billed and why. Rows whose status is an upstream error should carry no charge at all.
What to look for in the file, beyond the totals:
- A model you did not expect. The
modelcolumn names what answered. Withmodel: "auto"or an alias, that is the resolved id; with budget autopilot, a cheaper same-developer model near a key's limit. - Cache behaviour.
cache_read_tokensshould be high on a key with long repeated prefixes. If it is zero, the prompt is not caching and you are paying the full input rate. - Waste. A response also carries a signal when a noticeable share of its request was text already sent earlier in the conversation, or a base64 blob pasted inline; media sent as proper file or image parts does not count. A key that trips the signal on most requests has a prompt to fix.
Level 4: the signed statement
Each month has a statement on the console's billing page: a JSON file signed with Ed25519 plus a CSV with one row per request. The signed payload carries the CSV's SHA-256, so one signature covers both files. Fields: org, period, totals, by_model, by_key, payments, usage_csv, with amounts as exact six-place decimals. It becomes final one day after the month ends and is served exactly as stored from then on.
Check it in the browser at /statements/verify: drop in the statement JSON, its CSV, or a single response receipt, and the page verifies the signature with Web Crypto against the public key. Nothing is uploaded, no account is needed, and fetching the public key is the only request the page makes. The key itself is public at GET /v1/statements/public-key, a JWK with no key required, so an accountant or a customer's own script can verify without any access to your account.
Payments are the other half of the ledger. A receipt email goes out when a payment is first credited, each payment has a printable receipt page in the console's billing section, refund and dispute notices are emailed too, and GET /v1/invoices lists invoices with a PDF per invoice number. The statement's payments field should match those receipts, and totals should match the CSV from level 3.
Per-request receipts for the strict case
When a single answer has to be defensible (a customer disputes a charge, a compliance review asks which model produced a text), every non-streamed response also carries a signed receipt, and any request's receipt is a document at GET /v1/requests/{request_id}/receipt. It states the request_id, model, billed_tokens (input, cache_read, cache_write, output), charge_usd, refund and hashes (SHA-256) of both the request and response bodies, signed with the same Ed25519 key as the statements. Hash your stored copy of the request and compare: a matching hash ties the charge to the exact bytes you sent. Whether the id in that field is the one that actually answered is checked separately, every day, on /proof.
A monthly routine
- Pull the month's CSV per key with
/v1/usage/export, sumcharge_usdby key and model. - Compare the sums with each key's
/usagefigures and with the statement'sby_keyandby_model. - Verify the statement and its CSV at /statements/verify; file both with the payment receipts.
- Spot-check a handful of request ids from your own logs against
GET /v1/requests/{id}: tokens times price equalscharge_usd. - Read the
refund_reasoncolumn and the cache columns for anything that points at a prompt or a key to fix.
The whole chain is request id to record to CSV to signed statement; the observability page covers sessions and log export to your own tools, and the SDK guide has the request and receipt routes with examples.