Connection basics
Base URLs by client
OpenAI-compatible apps, including Codex and Cursor:
https://api.cheaperinference.com/v1Claude Code and Anthropic SDKs:
https://api.cheaperinference.comClaude Code uses the URL without /v1. Each guide below includes the correct settings.
Before you start
Create an API key, then copy an exact model ID from the live model catalog. Store keys in an environment variable when the app supports it.
OpenAI Node
Set up with AI
Let your agent connect OpenAI Node for you.
OpenAI Node is a library. Choose Cursor, Codex, or Claude Code from Ask AI to set it up in your project. Tool documentation
Keep your API key local. Copy the prompt to use any other agent.
Or set up manually
4 stepsInstall the SDK, add your key, and send a test request.
Install the SDK
WhereYour project’s terminalnpm install openaiRequest gzip is enabled by the supplied transport helper. Server-side Node.js with fetch and node:zlib; a provider accepting custom fetch.
Enable request compression
WhereSave ci-gzip-fetch.mjs beside your application example- Server-side Node.js with fetch and node:zlib; a provider accepting custom fetch.
- Inspect the installed SDK version, existing HTTP client, proxy, TLS, tracing, and retry settings first. Save the helper beside the example and wire it into the CI client. Compose with the existing transport rather than discarding its settings. Do not change other providers or upgrade dependencies automatically.
- The examples were exercised against a local capture server with OpenAI Node 7.47.0, AI SDK 7.0.160 / openai-compatible 3.0.82, and HTTPX 0.28.1 with OpenAI Python 2.24.0, langchain-openai 0.3.35, and LiteLLM 1.83.9. These are tested versions, not instructions to replace an existing dependency lockfile.
- Compress only supported CI JSON inference POST bodies. Do not add Content-Encoding without compressing the bytes, use Accept-Encoding as a substitute, double-compress a body, or compress multipart uploads. Keep streaming responses and the SDK's existing retry policy.
import { promisify } from "node:util";import { gzip } from "node:zlib";const gzipAsync = promisify(gzip);const paths = new Set([ "/chat/completions", "/completions", "/responses", "/messages", "/messages/count_tokens", "/images/generations", "/videos/generations",]);// Server-side Node.js. Pass your existing fetch implementation to retain its// proxy, tracing, and retry behavior. This wrapper never retries a generation.export function createCIGzipFetch({ baseURL = "https://api.cheaperinference.com/v1", fetch: fetchImpl = globalThis.fetch,} = {}) { const base = new URL(baseURL.replace(/\/$/, "")); return async function ciGzipFetch(input, init) { const request = new Request(input, init); // Request does not retain fetch-specific options (for example Undici's // dispatcher). Forward them without restoring the original body/headers. const fetchOptions = { ...init }; delete fetchOptions.body; delete fetchOptions.headers; const url = new URL(request.url); const suffix = url.pathname.slice(base.pathname.length); const json = (request.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase() === "application/json"; if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname + "/") || !paths.has(suffix) || request.method !== "POST" || !json || request.headers.has("content-encoding") || !request.body) { return fetchImpl(request, fetchOptions); } request.signal.throwIfAborted(); const bytes = await request.arrayBuffer(); const compressed = await gzipAsync(new Uint8Array(bytes)); request.signal.throwIfAborted(); const headers = new Headers(request.headers); headers.set("content-encoding", "gzip"); headers.delete("content-length"); headers.delete("transfer-encoding"); return fetchImpl(new Request(request, { headers, body: compressed }), fetchOptions); };}Connect your app
Wherequickstart.mjs- Set
CHEAPER_INFERENCE_API_KEYin your local environment. - Save this example as
quickstart.mjs.
import OpenAI from "openai";import { createCIGzipFetch } from "./ci-gzip-fetch.mjs";const client = new OpenAI({ apiKey: process.env.CHEAPER_INFERENCE_API_KEY, baseURL: "https://api.cheaperinference.com/v1", fetch: createCIGzipFetch(),});const response = await client.chat.completions.create({ model: "gpt-5.4", messages: [{ role: "user", content: "Hello" }],});console.log(response.choices[0].message.content);- Run
node quickstart.mjsin the same terminal.
- Set
Verify your connection
- In your connected app, send:
Reply with: connected. - Open
Dashboard → Requestsand find the request for your selected model.
- Distinguish connection verified from compression verified. Verify compression by inspecting only Content-Encoding and byte counts at the outgoing transport or a local capture server; never log credentials or prompt content. A successful small inference request alone does not prove compression. If inspection is unavailable, report compression configured, not verified.
You should see a reply in your app and a successful request in the dashboard.
- In your connected app, send:
After setup
Check your connection or learn how to reduce repeat-request costs.