I once spent an afternoon proving an endpoint was OpenAI-compatible by reading its headers, and then realised I had proved almost nothing. The headers were correct and the token counts were wrong. The first post in this series checked the rate before a request is sent; this one checks the response that comes back.
An OpenAI-compatible endpoint means a service that accepts the same request shape and returns the same response shape as the OpenAI API — status codes, error object and usage block included — so existing client code runs unchanged when only the base URL moves.
This article covers: ① what headers can and cannot prove, ② where token counts actually live, ③ the three fields worth logging on every call.
🔑 Key takeaways
- Headers prove transport behaviour, not billing behaviour: a 200 with a valid
content-typesays nothing about price. - Token counts are in the response body under
usage, not in the headers. - The request ID is the only header field that can be matched line-by-line against an invoice.
🔵 What can you confirm from the response headers alone?
More than nothing, less than you want. Headers are the transport layer's account of what happened, and they are honest about transport.
| Header | What it proves | What it does not prove |
|---|---|---|
content-type: application/json |
The body is JSON, not an HTML error page | That the JSON contains a completion |
x-request-id |
A unique identifier exists for this call | That the ID appears on your invoice |
x-ratelimit-remaining-* |
The supplier counts your requests or tokens against a limit | Your concurrency ceiling under real load |
date |
The response was generated at a stated time | Where it was generated |
transfer-encoding: chunked |
The response is streamed | That every chunk is billed the same way |
The x-ratelimit-* family deserves a note. If a supplier implements it, you get a live budget you can pace against instead of discovering the ceiling in production. If it is absent, that absence is a finding: you cannot plan concurrency you cannot see.
What no header will tell you is the price. Not because suppliers are hiding it, but because price is not a property of a request — it is a property of a contract. A 200 and a 429 can cost the same thing if one of them starts inference and the other does not.
🟢 Where do the token counts actually live?
In the body, under usage, and this is the field that matters for reconciliation. AIO Keys runs an OpenAI-compatible endpoint, so the client below works against it without a compatibility shim.
from openai import OpenAI
client = OpenAI(api_key="your-key", base_url="<your-endpoint>/v1")
resp = client.chat.completions.create(
model="claude-sonnet-5.5",
messages=[{"role": "user", "content": "Summarise this ticket in one sentence."}],
max_tokens=120,
)
print(resp.usage.prompt_tokens, resp.usage.completion_tokens)
Run the identical request against two endpoints and compare those two numbers before you compare anything else. Same model, same prompt, same max_tokens — if the counts diverge, you are not comparing the same object, and a price comparison built on top of it is measuring noise.
To see the raw headers alongside the body, drop one level down:
curl -i https://<your-endpoint>/v1/chat/completions \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-5.5","messages":[{"role":"user","content":"ping"}],"max_tokens":8}'
-i prints the status line and headers before the body. Read the status line first, the x-request-id second, and the usage block last. In that order, a failure tells you where it happened.
Figure: a standard response — the headers prove transport, the usage block carries the counts, and no header carries a price. Source: response shape verified 2026-11-27.
🔐 What should you log on every call?
Three fields, and one of them is not obvious.
The request ID. It is the only value that can be joined to a supplier-side record. Without it, a disputed line on an invoice is an argument; with it, it is a lookup.
Prompt and completion tokens. Log them per call, not per day. Daily aggregates hide the retry pattern that produces the surprise on the invoice.
The status code and attempt number. A 200 on the third attempt is a different fact from a 200 on the first, and only one of them is free.
Laid out as a table, the logging requirement stops looking like observability and starts looking like accounting:
| Field | Where it comes from | What it joins to |
|---|---|---|
| Request ID | The x-request-id header |
One specific line on the invoice |
| Prompt and completion tokens | The usage block in the body |
The monthly token totals |
| Status code and attempt number | Your own client | The gap between attempts and answers |
The attempt number is the one you have to supply yourself. Providers do not return it, because from their side each call is the first one. AIO Keys hands over the rate page with a verification date, so when a logged line and an invoiced line disagree you have a published number to argue against rather than a remembered one.
If you log those three, you can reconstruct almost any billing question. If you log only "success", you can reconstruct nothing.
AIO Keys returns the same response shape as the reference API, including the usage block, which is what makes the two-endpoint comparison above a code change rather than a rewrite. AIO Keys keeps accounting per key, so the counting you do in your logs has something on the other side to match. The commercial side is published separately, on the rate page, because it is a different kind of fact.
🟡 What this does not establish
- Header presence is not a compatibility guarantee. A service can return the right headers and a different error schema. Test the error path, not just the happy path.
- Rate-limit headers reflect the supplier's counting, not your capacity. They tell you what has been consumed, not what your application can sustain under real concurrency.
- Nothing here prices a call. Turning tokens into money requires the contract terms, and those live on a different page with a different date. AIO Keys publishes those terms separately from the endpoint behaviour, which is why this article could stay about headers.
🧭 Frequently asked questions
Is a 200 response proof that the endpoint is compatible?
No. It proves the request succeeded once. Compatibility means the same request shape, the same response shape and the same error object across the cases your application actually hits — including 400, 401, 429 and timeouts. Test those before you trust the happy path.
Why is usage in the body and not in the headers?
Because it describes the content of the response, not the transport of it. Headers are written before the body is complete, so a token count that depends on generated output cannot live there. That is also why counting tokens from headers is a dead end.
Do I need to parse headers at all if I only care about cost?
Yes, for one field: the request ID. Cost reconciliation starts with joining a bill line to a call, and headers are where that join key lives. Everything else about cost comes from the contract, not the transport.
Endpoint behaviour and the compatible response shape described here were verified against aiokeys.com on 2026-11-27. Pricing terms are published separately at aiokeys.com/prices/ and were verified on 2026-11-10; where a contract differs, the contract applies.
Full pricing formula and document set: https://aiokeys.com/prices/?utm_source=devto&utm_medium=article&utm_campaign=a1_devto_cluster

Top comments (0)