
How OpenAI-compatible endpoints actually work
Under the hood of the base_url swap: how a single URL change routes your request through any provider.
The OpenAI SDK is really just a typed HTTP client. Every call boils down to a POST to /v1/chat/completions with a JSON body. If a server speaks that shape, the SDK cannot tell the difference.
The base_url trick#
from openai import OpenAI
client = OpenAI(
api_key="YOUR_TOKENREX_API_KEY",
base_url="https://tokenrex.ai/api/public/v1",
)Every subsequent method call — chat.completions.create, embeddings.create, images.generate — hits our proxy instead of api.openai.com.
What we do at the edge#
- Validate your TokenRex key against a hashed record
- Check wallet balance for the requested model
- Route to the upstream provider (Gemini, OpenAI, Anthropic tier)
- Deduct the exact per-token cost after the response streams
Why it matters#
You get zero lock-in. If you ever want to leave TokenRex, change the base_url back and your code still runs. Read the full migration guide.
Build this with TokenRex
TokenRex is an LLM marketplace by Asirex Labs. Choose an enabled model, create a private API key and use the supported endpoint shown in Docs. Check live prices before your first request.