$0.445 for 1,000 Calls: A Go and Rust API Receipt
01 / A 1,000-request receipt with every assumption exposed
The cheapest client is not necessarily the one with the fewest dependencies. It is the one that makes its requests, usage, and retries easy to audit. For Go and Rust applications calling an OpenAI-compatible endpoint, start with a token receipt before worrying about SDK ergonomics.
Here is a worked budget, not a CheapRelay price quote. Assume illustrative rates of $0.20 per million uncached input tokens, $0.05 per million cache-read tokens, $0.25 per million cache-write tokens, and $0.80 per million output tokens. Replace all four rates with the selected model’s current rates before funding production traffic.
- ■ Uncached input: 1,000,000 tokens × $0.20 / 1,000,000 = $0.200.
- ■ Cache reads: 400,000 tokens × $0.05 / 1,000,000 = $0.020.
- ■ Cache writes: 100,000 tokens × $0.25 / 1,000,000 = $0.025.
- ■ Output: 250,000 tokens × $0.80 / 1,000,000 = $0.200.
- ■ Total for 1,000 requests: $0.445, or $0.000445 per request.
This example treats the three input categories as separate, non-overlapping buckets. Real providers may report cache writes as an additional charge or expose different usage fields. Follow the applicable billing rules rather than blindly adding every counter.
02 / Give Go and Rust the same endpoint contract
CheapRelay provides pay-as-you-go access through one key, with OpenAI-compatible routes under https://api.cheapapirelay.com/v1. For this article, both clients send POST requests to https://api.cheapapirelay.com/v1/chat/completions. Gemini-native routes use /v1beta instead; they are a different interface, not a replacement base URL for this request.
Store the key in an environment variable such as CHEAPRELAY_API_KEY. Store the exact catalog model identifier separately as MODEL_ID. If selecting DeepSeek V4 Flash, copy its current identifier from the service rather than guessing that the display name is an accepted API value.
The request needs Authorization: Bearer followed by the key, plus Content-Type: application/json. A minimal JSON body is {"model":"MODEL_ID","messages":[{"role":"user","content":"Return a three-item packing list."}]}. Substitute the actual identifier before sending; the literal MODEL_ID is only a placeholder.
03 / Go: reuse one HTTP client and inspect failed responses
Go’s standard library is enough for a small integration. Create one http.Client with a deliberate timeout, such as 60 seconds, and reuse it. That timeout is an application choice, not a relay latency promise. Marshal the request with encoding/json, build it with http.NewRequestWithContext, and set both headers explicitly.
After client.Do, close the response body on every path. Check the HTTP status before decoding a successful completion. Bound how much error text you read, and avoid logging authorization headers or sensitive prompts. Decode the response’s usage object alongside the generated text; discarding usage makes receipt reconciliation unnecessarily difficult.
04 / Rust: keep reqwest reusable and usage fields flexible
In Rust, reqwest with JSON support and serde_json makes a compact equivalent. Build one reqwest::Client with an explicit timeout. Use client.post(endpoint).bearer_auth(key).json(&payload).send().await, then inspect the status and parse the body. An async executable also needs a runtime such as Tokio.
A serde_json::Value is useful during integration because optional cache details can differ between endpoints. Once the response shape is verified, introduce typed structs while preserving optional fields. Keep the client in shared application state rather than rebuilding its connection pool for every request.
05 / Retries turn $0.445 into a different receipt
At the same token mix, 10,000 requests would cost $4.45 under these assumptions. If 20 additional attempts per 1,000 requests each incur the average full-request charge, they add $0.0089, bringing the batch to $0.4539. This is a sensitivity calculation, not a claim that every failed attempt is billed.
Set retry limits deliberately, use backoff, and honor Retry-After when supplied. A timeout does not prove that generation never happened. Log attempts separately from logical requests and reconcile billed usage rather than multiplying successful calls by an average.
06 / Reconcile tokens before expanding the workload
CheapRelay bills real tokens, including cache reads and writes, with no monthly fee or subscription. Sign up for CheapRelay when you are ready to test a small, capped workload. Compare recorded usage with billed charges, then scale the same client configuration only after the receipt makes sense.
Sign up Try the prices yourself, sign-up credit included.
More reading
| Date | Aisle | Written in | Title |
|---|---|---|---|
| 2026-10-26 | API pipes and fittings | EN | $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-26 | API pipes and fittings | EN | $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-26 | API pipes and fittings | EN | $0.0048 per Request: Make Usage a Receipt Turn API usage fields into a cost receipt, separate cached tokens correctly, and log enough detail to reconcile requests with billing. |
| 2026-10-26 | API pipes and fittings | EN | $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-26 | API pipes and fittings | EN | $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-26 | Model price-offs | EN | $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. |