$0 monthly: Go and Rust API clients
01 / Start with a $0 monthly API plan
A small project does not need a large SDK stack. If your endpoint speaks the OpenAI-compatible API format, a Go or Rust program can send a chat request with ordinary HTTP. CheapRelay uses https://api.cheapapirelay.com as its API base, with OpenAI-compatible routes under /v1. There is no monthly fee and no subscription. You pay for actual usage, so your first budget decision is the request size, not a fixed platform bill.
Create an account, add only the amount you are comfortable spending, and sign up before putting the key into an application. Keep the key in an environment variable. Never commit it to Git, paste it into a public issue, or ship it inside a browser application.
02 / Send one controlled request from Go
Go's standard net/http package is enough for a first client. Set API_KEY in your shell, then create a POST request to https://api.cheapapirelay.com/v1/chat/completions. Use the Authorization header with the value Bearer followed by your key, and set Content-Type to application/json.
The JSON body can contain model, messages, and max_tokens. For example, use model Claude Haiku 4.5, a user message asking for a one-sentence explanation, and max_tokens set to 80. A short output limit makes accidental spending easier to detect. Encode a Go struct with encoding/json, send it with http.Client, check that the HTTP status is in the 200 range, and decode the response into a struct containing choices and message content.
A minimal flow is: define Request with Model, Messages, and MaxTokens fields; marshal Request; call http.NewRequest with POST; add the two headers; execute with client.Do; defer response.Body.Close; reject non-success status codes; and decode the JSON body. Set a context timeout, such as 20 seconds, so a network problem does not leave a command waiting forever.
03 / Repeat the same request in Rust
Rust needs a little dependency setup, but the request shape stays the same. A practical beginner choice is reqwest with its json and blocking features, plus serde and serde_json. Use an environment variable for the key and construct a blocking Client with a timeout.
Define a serializable request struct with model, messages, and max_tokens fields. The messages field can be a vector containing one object with role set to user and content set to your prompt. Send the request to https://api.cheapapirelay.com/v1/chat/completions with client.post, bearer_auth, json, and send. Call error_for_status before deserializing the response. This turns a 401, 429, or server error into a visible failure instead of letting your program treat an error document as a successful answer.
For the response, deserialize only the fields you need: choices as a vector, then message, then content. Add a fallback for an empty choices array. Rust's Result type makes it natural to return errors to main and print a concise diagnostic to stderr.
04 / Keep token spending visible
Do not estimate cost from character count alone. CheapRelay bills per real token, including cache reads and cache writes. The exact amount depends on the selected model, input, output, and cache activity. Inspect the returned usage object when available and compare it with your account usage page. Log request ID, model, input token count, output token count, and elapsed time, but never log the prompt if it may contain secrets.
- ■ Start with max_tokens between 50 and 150.
- ■ Keep prompts specific and short while testing.
- ■ Use one request at a time until error handling works.
- ■ Set a local spending alert or check balance before batch jobs.
- ■ Retry only transient failures, with a small capped backoff.
05 / Make the client reliable before adding features
Handle 401 as a key or authorization problem, 429 as a rate or balance problem, and 5xx responses as temporary provider or relay failures. Do not retry every error immediately. Add a request timeout, validate the response shape, and return the model's text separately from diagnostic data.
Once the basic path works, wrap it in a small function such as ask in Go or ask in Rust. Keep the endpoint, model, timeout, and output limit configurable through environment variables. That gives you a cheap test client today and a reusable application boundary later, without locking the rest of your code to a vendor-specific SDK.
Sign up Try the prices yourself, sign-up credit included.
More reading
| Date | Aisle | Written in | Title |
|---|---|---|---|
| 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. |
| 2026-10-28 | API pipes and fittings | EN | $0 in extra software: rotate API keys safely A beginner-friendly API key rotation plan using overlapping credentials, a small test request, and a rollback window—without buying more tools. |
| 2026-10-28 | API pipes and fittings | EN | $1 a day: stay below your API key’s rate limits A tiny-budget walkthrough of per-key request limits, token limits, queues and retries, using a hypothetical $1 daily spending target. |
| 2026-10-28 | API pipes and fittings | EN | $2 Budget: Handle 401, 402 and 429 Without Waste A beginner’s guide to API errors: fix authentication, stop on payment issues, and retry rate limits without exhausting a tiny budget. |
| 2026-10-27 | API pipes and fittings | EN | $1 test budget: Anthropic Messages for OpenAI users Learn Anthropic’s Messages format, translate OpenAI chat requests, and keep your first API experiments within a $1 budget. |