Jump straight to the numbers

← All articles

$0 monthly fee: Go and Rust API calls

01 / Start with $0 in monthly fees and one small request

Your first API experiment needs one successful response, not a background agent running all afternoon. CheapRelay has no monthly fee or subscription: billing is pay as you go, per real token, including cache reads and writes. Usage still costs money, so keep the first request small and check its charge before repeating it.

This walkthrough uses direct HTTP clients in Go and Rust. Both send the same OpenAI-compatible request. You can understand the request first, then move to an SDK when you need more features.

Sign up for CheapRelay, create an API key, and check the current model prices before choosing a model. Copy its exact API model identifier from the service; a display name is not necessarily the identifier your request needs.

02 / Set three environment variables before writing either client

In a Bash-compatible terminal, set OPENAI_BASE_URL to https://api.cheapapirelay.com/v1, OPENAI_API_KEY to your key, and OPENAI_MODEL to the exact model identifier you selected. For example: export OPENAI_BASE_URL='https://api.cheapapirelay.com/v1'. Set the other two variables with the same export syntax. Keep the key out of source files and version control.

The examples append /chat/completions to that base URL. Include /v1 exactly once. These calls use the OpenAI-compatible route; the separate Gemini native route under /v1beta is outside this walkthrough.

03 / Go: send one request with the standard library

Create a directory, run go mod init relay-demo, and save the following as main.go. No third-party Go package is required. The program sends a short prompt, requests a small output, and prints the HTTP status and response body.

package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" "os" "strings" "time" ) func main() { payload, err := json.Marshal(map[string]any{ "model": os.Getenv("OPENAI_MODEL"), "messages": []map[string]string{{"role": "user", "content": "Explain an API in one sentence."}}, "max_tokens": 64, }) if err != nil { panic(err) } url := strings.TrimRight(os.Getenv("OPENAI_BASE_URL"), "/") + "/chat/completions" req, err := http.NewRequest("POST", url, bytes.NewReader(payload)) if err != nil { panic(err) } req.Header.Set("Authorization", "Bearer " + os.Getenv("OPENAI_API_KEY")) req.Header.Set("Content-Type", "application/json") client := &http.Client{Timeout: 30 * time.Second} resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() body, err := io.ReadAll(io.LimitReader(resp.Body, 1048576)) if err != nil { panic(err) } fmt.Println(resp.Status) fmt.Println(string(body)) if resp.StatusCode >= 400 { os.Exit(1) } }

Run go run . once. A successful response should contain a choices array and usually a usage object. Read the returned message and usage before making another call. The response-reading limit protects local memory; it does not limit token charges.

04 / Rust: repeat the request with reqwest

Run cargo new relay-demo-rust, enter that directory, then run cargo add reqwest@0.12 --no-default-features --features blocking,json,rustls-tls and cargo add serde_json. Replace src/main.rs with this program:

use std::{env, time::Duration}; use serde_json::json; fn main() -> Result<(), Box<dyn std::error::Error>> { let base = env::var("OPENAI_BASE_URL")?; let key = env::var("OPENAI_API_KEY")?; let model = env::var("OPENAI_MODEL")?; let client = reqwest::blocking::Client::builder() .timeout(Duration::from_secs(30)).build()?; let response = client .post(format!("{}/chat/completions", base.trim_end_matches('/'))) .bearer_auth(key) .json(&json!({ "model": model, "messages": [{"role": "user", "content": "Explain an API in one sentence."}], "max_tokens": 64 })) .send()?; let status = response.status(); println!("{}\n{}", status, response.text()?); if !status.is_success() { return Err("API request failed".into()); } Ok(()) }

Run cargo run once. Both clients deliberately avoid automatic retries. If a request times out, the server may still have processed it; immediately repeating it can create another billable request.

05 / Calculate ten calls before you automate them

Suppose each call uses 2,000 input tokens and 200 output tokens. Ten calls consume 20,000 input and 2,000 output tokens. If the listed prices per million tokens are I for input and O for output, the estimated charge is 0.02 × I + 0.002 × O. Substitute current prices; this is arithmetic, not a quoted rate. Account for separately priced cache activity where applicable.

The 64-token setting is a requested output limit, not a dollar spending cap. Some models require a different output-limit parameter or have additional token accounting. If you receive a parameter error, check that model’s documented requirements before changing the request.

For a tiny budget, test one client first, inspect usage and billing, then test the other. Keep prompts short, skip conversation history until needed, and add retries only after you understand their cost.

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

More reading

DateAisleWritten inTitle
2026-10-29API pipes and fittingsEN$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-29API pipes and fittingsEN$0.003 example call: log every billable token
Read API usage fields, log token counts safely, and estimate request costs with a tiny budget and a simple local file.
2026-10-29API pipes and fittingsEN$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-28API pipes and fittingsEN$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-28API pipes and fittingsEN$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-28API pipes and fittingsEN$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.