How to Use an AI API Relay: Setup Guide for Every Major Tool
Once you've got a base_url and API key from a relay, what's left is genuinely simple — most relays are compatible with the standard OpenAI or Anthropic request format, so in whatever code or tool you were already pointing at the official API, you just swap the endpoint and key. Below are config examples for the tools people use most.
The general pattern: only two parameters change
Regardless of language or tool, the logic is identical: swap the base_url (some tools call it api_base or endpoint) that used to point at the official provider for the domain your relay gave you, and swap api_keyfor the key generated in the relay's dashboard. Every other request parameter and the response format stay essentially the same as the official API — your code logic doesn't need a rewrite.
Setup for common tools
Python (official OpenAI SDK)
from openai import OpenAI
client = OpenAI(
api_key="your-key",
base_url="https://provider-domain/v1",
)
resp = client.chat.completions.create(
model="model-name",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)Node.js (openai package)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "your-key",
baseURL: "https://provider-domain/v1",
});
const resp = await client.chat.completions.create({
model: "model-name",
messages: [{ role: "user", content: "Hello" }],
});
console.log(resp.choices[0].message.content);Claude Code CLI
Set two environment variables, then reopen your terminal or source your config file to apply them.
export ANTHROPIC_BASE_URL="https://provider-domain"
export ANTHROPIC_AUTH_TOKEN="your-key"Codex CLI
Also environment variables — note the prefix here is OPENAI, not ANTHROPIC.
export OPENAI_BASE_URL="https://provider-domain/v1"
export OPENAI_API_KEY="your-key"Cursor / Cline and similar editor plugins
Find the "Custom API" or "OpenAI Compatible" option in the model provider settings, paste the relay's address into Base URL, its key into API Key, and manually type the exact model name from that provider's list. Save, and the editor will start calling it normally.
Quick test with curl
Before touching your code, confirm the endpoint itself is reachable with a single curl command.
curl https://provider-domain/v1/chat/completions \
-H "Authorization: Bearer your-key" \
-H "Content-Type: application/json" \
-d '{"model":"model-name","messages":[{"role":"user","content":"Hello"}]}'Common pitfalls
Does base_url need a trailing /v1?
Most OpenAI-compatible relays expect /v1 appended after the domain, like https://provider-domain/v1. Check that specific provider's docs — a few SDK wrappers add it automatically, and getting it wrong usually throws a plain 404.
Use the exact model name from that provider's list
The same model can be named slightly differently across relays (version numbers, suffixes, casing all vary). Copying the official model name verbatim sometimes gets you a "model not found" error — pull the exact string from that provider's model list or dashboard instead.
Some providers default to streaming responses
If your code doesn't handle streamed output (Server-Sent Events), what you get back may be chunked raw data instead of one complete response. Explicitly set stream to false in the request, or parse the streamed format properly.
How to confirm it's set up correctly
Send the simplest possible request through any of the methods above — say, asking the model to reply "hello" — and getting a normal text response back means the config is working. If what you actually care about is whether you're getting the real official model rather than just "does it respond," run a fixed, sufficiently hard question against both the official API and the relay and compare, or use this site'srelay verification tool— enter the base_url and a throwaway key and it runs an automated check.
FAQ
Is a relay's API compatible with the official SDK, or do I need a separate package?
Most relays are compatible with the official OpenAI or Anthropic request format, so the official SDKs (the openai and anthropic packages) work as-is — no separate client library needed. Just swap in the new base_url and api_key.
I changed base_url and now everything errors. How do I debug it?
Start with a standalone curl request to rule out an issue in your own code. Then check three things: whether base_url needs a trailing /v1, whether api_key was pasted correctly (watch for stray whitespace), and whether the model name matches that provider's list exactly. Those three cover most errors.
How do I know if the relay I'm using is giving me the real model?
Response content alone is hard to judge. A more direct approach is running the same hard question against both the official API and the relay and comparing results, or using this site's relay verification tool — enter the base_url and a throwaway key and it runs an automated check for you.