$0.003 example call: log every billable token
01 / A $0.003 receipt starts with token counts
A successful API response tells you what the model said. Its usage fields help explain what the request cost. If your budget is $1, recording those fields is a useful first step: you can spot expensive requests before repeating them hundreds of times.
Consider an illustrative request with 1,000 input tokens and 500 output tokens. At hypothetical rates of $0.50 per million input tokens and $5 per million output tokens, it costs $0.0005 + $0.0025 = $0.003. These are teaching numbers, not CheapRelay prices. At that exact cost, 333 requests would total $0.999.
02 / Find usage in the returned response
Start with one short, non-streaming request. It is easier to inspect because the completed response arrives together. With an OpenAI SDK, look for the response object's usage property. If you inspect raw JSON, look for a top-level usage object.
On Chat Completions-style responses, the common fields are prompt_tokens, completion_tokens, and total_tokens. For example: {"prompt_tokens":1000,"completion_tokens":500,"total_tokens":1500}. Input includes the conversation and instructions sent with the request, not just your latest sentence. Output covers generated tokens according to the endpoint's accounting rules.
Other endpoints use different names. Responses-style APIs commonly expose input_tokens and output_tokens. Gemini native responses commonly provide usageMetadata, with fields such as promptTokenCount and candidatesTokenCount. Preserve the original usage object so you can investigate details without guessing how fields map.
03 / Write one small receipt after each request
You do not need a database or a paid monitoring service. A local JSON Lines file works: each completed request adds one JSON object on its own line. In your application, read the usage object after the API call returns, build a record, serialize it, and append a newline.
Keep these fields in each record:
- ■ timestamp: when the request finished, preferably in UTC.
- ■ request_id: the provider's request identifier, when available.
- ■ model and endpoint: what you requested and where you sent it.
- ■ input_tokens and output_tokens: normalized counts for simple totals.
- ■ usage_raw: the complete usage object, including nested details.
- ■ status and estimated_cost_usd: the outcome and your calculated estimate.
A minimal receipt could look like {"timestamp":"2026-06-01T12:00:00Z","input_tokens":1000,"output_tokens":500,"estimated_cost_usd":0.003}. Add the other fields as your logger grows. Keep API keys, prompts, and generated text out of this file; token accounting usually does not need them. If usage is absent, record a missing value rather than zero.
04 / Count cached tokens without counting them twice
Cache fields need extra care. Some APIs report cached input inside the input total, with a nested field identifying the cached portion. Adding that cached count to the input total would count those tokens twice.
If 1,000 input tokens include 800 cache-read tokens, the ordinary input portion is 200 tokens. Apply the appropriate rate to each category. Cache writes may have separate fields and prices, depending on the model and endpoint. Do not assume every API reports them identically.
Likewise, reasoning-token details can describe tokens already included in an output total. Save the details, then check the endpoint's accounting rules before adding categories together.
05 / Turn your log into a daily spending check
For a request without special billing categories, estimate cost as input tokens divided by 1,000,000 times the input rate, plus output tokens divided by 1,000,000 times the output rate. Save the rates used alongside the estimate so later price changes do not rewrite your history.
CheapRelay offers pay-as-you-go access with no monthly fee or subscription, billing per real token, including cache reads and writes. For an OpenAI SDK, its base URL is https://api.cheapapirelay.com/v1. Sign up for CheapRelay, check the current rates, and make one short request to verify your log.
For streaming, usage may arrive only in a final event or require an option such as stream_options.include_usage where supported. Test this before relying on it. Total your estimates daily, compare them with billed usage, and set a local spending threshold. Leave headroom: concurrent requests and missing usage can make a local estimate lag behind the bill.
Sign up Try the prices yourself, sign-up credit included.
More reading
| Date | Aisle | Written in | Title |
|---|---|---|---|
| 2026-10-29 | API pipes and fittings | EN | $1 Monitoring Budget: Price 60 AI Probes First Monitor an AI endpoint with curl, two daily generation checks, simple alerts, and a measured $1 monthly spending target. |
| 2026-10-29 | API pipes and fittings | EN | $1 Budget? Start With 2 Parallel API Requests Choose a small concurrency limit, estimate token costs, and handle retries without letting parallel AI requests drain your budget. |
| 2026-10-29 | API pipes and fittings | EN | $0 monthly fee: Go and Rust API calls Make OpenAI-compatible requests from Go and Rust with small outputs, explicit timeouts, and a token budget you can calculate. |
| 2026-10-28 | API pipes and fittings | EN | $0 monthly: Go and Rust API clients A tiny-budget guide to sending OpenAI-compatible requests from Go and Rust without monthly fees or framework overhead. |
| 2026-10-28 | API pipes and fittings | EN | $1 Test Budget: OpenAI Node SDK Through a Relay Connect the OpenAI Node SDK to CheapRelay, make one small request, and estimate token costs before scaling beyond a $1 test budget. |
| 2026-10-28 | API pipes and fittings | EN | $0 Monthly Fee: Set Your Python SDK Base URL Configure the OpenAI Python SDK for CheapRelay, avoid doubled /v1 paths, and make a small first request without wasting tokens. |