
Engineering 7 min read· 5 Jul 2026· By Engineering
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#
python
from openai import OpenAI
client = OpenAI(
api_key="sk-tb-...",
base_url="https://tokenbaazar.in/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
sk-tb-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 TokenBaazar, change the base_url back and your code still runs. Read the full migration guide.
Streaming works identically — we pass SSE frames through as they arrive, so first-token latency is upstream latency plus ~40ms.