Jump straight to the numbers

← All articles

$1 Test Budget: OpenAI Node SDK Through a Relay

01 / Plan a $1 test before writing the Node script

You do not need a subscription or a large application to test an AI relay. Start with a $1 spending target, one short prompt, and one request at a time. That $1 is a personal planning limit, not a quoted minimum deposit or a spending cap enforced by this tutorial.

CheapRelay is a low-priced, pay-as-you-go AI API relay with no monthly fee and no subscription. One key provides access to multiple model providers through OpenAI-compatible routes. Billing follows real token usage, including cache reads and writes. Sign up for CheapRelay, create an API key, and check the current model prices before adding funds.

02 / Install the SDK in a tiny Node project

Use a currently supported Node.js LTS release. In a terminal, create a project directory and install the official OpenAI package:

mkdir relay-test

Run these commands separately: mkdir relay-test, then cd relay-test, then npm init -y, then npm install openai.

You will create a file named test.mjs. The .mjs extension lets Node use import without changing package.json. No web framework, database, or paid hosting is needed.

03 / Set the key, model ID, and /v1 base URL

The SDK needs three pieces of configuration: your secret key, the relay base URL, and an exact model identifier. CheapRelay's API host is https://api.cheapapirelay.com. For this OpenAI SDK walkthrough, use https://api.cheapapirelay.com/v1, not the Gemini-native /v1beta route.

In macOS or Linux shells, run the following commands separately. Replace both placeholder values before continuing:

export CHEAPRELAY_API_KEY='your-key-here'

export CHEAPRELAY_MODEL='exact-model-id-from-the-dashboard'

On Windows PowerShell, use $env:CHEAPRELAY_API_KEY='your-key-here' and $env:CHEAPRELAY_MODEL='exact-model-id-from-the-dashboard' instead.

Choose a model after checking its current input and output rates. Gemini 2.5 Flash is one available option to inspect, but do not assume its display name is the API identifier. Copy the identifier shown by the service. Keep the key out of source control and browser-side JavaScript.

04 / Send one short chat request with automatic retries disabled

Save the following JavaScript in test.mjs. It can stay on one line; semicolons separate the statements.

import OpenAI from 'openai'; const apiKey = process.env.CHEAPRELAY_API_KEY; const model = process.env.CHEAPRELAY_MODEL; if (!apiKey || !model) throw new Error('Set CHEAPRELAY_API_KEY and CHEAPRELAY_MODEL first.'); const client = new OpenAI({ apiKey, baseURL: 'https://api.cheapapirelay.com/v1', maxRetries: 0, timeout: 20000 }); try { const result = await client.chat.completions.create({ model, messages: [{ role: 'user', content: 'Give three practical ways to reduce API token spending. Keep the answer under 60 words.' }], max_tokens: 120 }); console.log(result.choices[0]?.message?.content); console.log(JSON.stringify(result.usage, null, 2)); } catch (error) { console.error('Request failed:', error.status ?? '', error.message); process.exitCode = 1; }

Run node test.mjs once. This uses Chat Completions rather than assuming every SDK endpoint is supported. The max_tokens setting requests a small completion allowance; support and accounting can vary by model. If it is rejected, check that model's supported parameters rather than repeatedly resending unchanged requests.

Disabling automatic retries makes testing easier to account for. A timeout only stops the client waiting; it does not prove the server stopped processing or that the request was free.

05 / Turn the first usage record into a cost estimate

For ordinary input and output tokens, estimate cost as input tokens multiplied by the input price per million, divided by 1,000,000, plus the equivalent output calculation. Apply separate cache rates where relevant.

For arithmetic only, suppose input costs $0.20 per million tokens and output costs $1.00 per million. A request using 1,000 input tokens and 200 output tokens would cost $0.0004 before other billable categories. These are hypothetical prices, not CheapRelay's quoted rates.

Compare the returned usage with the relay's billing record before running a loop. Keep prompts short, avoid resending unnecessary history, and review spending manually after each early test. The script has no dollar-based cutoff: a small token limit reduces exposure but does not enforce your $1 budget.

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

More reading

DateAisleWritten inTitle
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$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-28API pipes and fittingsEN$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-28API pipes and fittingsEN$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-28API pipes and fittingsEN$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-27API pipes and fittingsEN$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.