Jump straight to the numbers

← All articles

$0.0048 per Request: Make Usage a Receipt

01 / A $0.0048 request, item by item

An API response can tell you more than whether your request succeeded. Its usage fields can provide the quantities for a receipt: input tokens, output tokens, and sometimes cache activity. Attach the applicable rates, and you can explain a charge instead of guessing from the length of the answer.

Start with a deliberately hypothetical rate card: $1 per million ordinary input tokens, $0.10 per million cached input tokens, and $4 per million output tokens. These are arithmetic examples, not advertised CheapRelay prices. Use the rates applicable to your actual request when calculating production costs.

Suppose a response reports 10,000 input tokens, including 8,000 cached tokens, plus 500 output tokens. The receipt is:

  • ■ Ordinary input: 2,000 × $1 ÷ 1,000,000 = $0.0020.
  • ■ Cache reads: 8,000 × $0.10 ÷ 1,000,000 = $0.0008.
  • ■ Output: 500 × $4 ÷ 1,000,000 = $0.0020.
  • ■ Total estimated cost: $0.0048.

At exactly that usage and those rates, 1,000 requests would cost $4.80. That is a projection from the receipt, not a promise about future traffic: longer answers, different cache behavior, or a different model change the result.

02 / Read the field names before adding the tokens

OpenAI-compatible chat responses commonly expose usage.prompt_tokens, usage.completion_tokens, and usage.total_tokens. Cached input may appear in usage.prompt_tokens_details.cached_tokens. Other response formats use input_tokens and output_tokens, with their own detail objects. Check the endpoint’s actual response instead of assuming every route returns the same structure.

In the example above, cached tokens are already included in the 10,000 input tokens. Subtract 8,000 to obtain 2,000 ordinary input tokens. Charging all 10,000 at the ordinary rate and then adding a cache-read charge would count the cached portion twice.

Likewise, a reasoning-token detail may describe a subset of output tokens. Do not add it again unless the documented accounting rules require it. total_tokens is useful as a quantity check, but it cannot determine the bill when token categories have different prices.

03 / Cache writes need their own receipt line

Some provider formats report cache creation separately from cache reads. Their input totals may also follow different inclusion rules. Preserve those distinctions when converting native responses into a common logging format.

For example, if a request separately reports 1,000 cache-write tokens at a hypothetical $1.25 per million, that line costs $0.00125. Establish whether those tokens are already included in another reported input count before calculating the remaining ordinary input. Never infer cache writes merely because the prompt repeats.

04 / Save one usage record per API attempt

Log usage after each completed attempt, alongside enough context to reproduce the calculation. A practical record contains:

  • ■ A timestamp, your operation ID, the provider request ID when available, and the attempt number.
  • ■ The requested and returned model identifiers, endpoint, response status, and currency.
  • ■ The original usage object, plus normalized ordinary input, cache-read, cache-write, and output counts.
  • ■ The applicable rates, their effective date or version, and the calculated estimated cost.

Keep token counts as integers and use decimal arithmetic for money. Store more precision than you display: rounding every $0.0048 request to $0.00 would hide $4.80 across 1,000 identical requests. Logging usage usually requires neither prompt text nor generated text, so avoid storing those just to track spending.

05 / Streaming and retries can leave gaps in the receipt

For streaming calls, request usage reporting where supported and capture the final usage-bearing event. If the connection ends before usage arrives, record the amount as unknown rather than zero. A retry should create another attempt record because more than one attempt may incur charges.

CheapRelay offers pay-as-you-go access with no monthly fee or subscription, and bills real tokens, including cache reads and writes. Its OpenAI-compatible routes use https://api.cheapapirelay.com/v1; Gemini native routes use /v1beta. Preserve each route’s original usage alongside your normalized fields, then reconcile local estimates with billing records to catch missing attempts or rate mismatches. Sign up for CheapRelay and use your first request to build a receipt you can audit.

Sign up Try the prices yourself, sign-up credit included.

More reading

DateAisleWritten inTitle
2026-10-26API pipes and fittingsEN$0.05184 for 8,640 AI health probes
A practical AI endpoint monitoring plan with a token-by-token receipt, timeout rules, retry limits, and clear limits on what a probe proves.
2026-10-26API pipes and fittingsEN$0.084 instead of $0.052: the timeout receipt
A concrete retry-cost receipt and practical timeout settings for long AI streams, with clear limits on what a disconnected client can tell you.
2026-10-26API pipes and fittingsEN$3.85 API Receipt, $20 Chat Subscription
A worked migration budget: $3.85 in illustrative API charges, a $20 subscription baseline, and the costs that can erase the saving.
2026-10-26API pipes and fittingsEN$4 for 1,000 Requests: Parallelism Is Not a Discount
A concrete concurrency receipt: token costs, retry overhead, rate-limit math, and a practical way to choose between 4, 6, and 16 parallel requests.
2026-10-26API pipes and fittingsEN$0.445 for 1,000 Calls: A Go and Rust API Receipt
Build Go and Rust clients for OpenAI-compatible APIs, then price tokens, cache traffic, and retries with an explicit example receipt.
2026-10-26Model price-offsEN$0.144 for One Reasoning Run—If the Rates Fit
A receipt-style cost worksheet for Gemini 3.1 Pro and Claude Opus 5, separating input, reasoning, retries, and cache charges.