Use a custom endpoint with the OpenAI and Anthropic SDKs
Both official SDKs accept a base URL argument. That means switching billing routes is a one-line change — your request and response code stays exactly as it is.
curl https://aicomp.ai/v1/models \
-H "Authorization: Bearer sk-your-gateway-key"
You should get back a JSON list of model IDs. If you see
Invalid token, the key is wrong or was not copied in full.
Python — OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="https://aicomp.ai/v1",
api_key="sk-your-gateway-key", # not your OpenAI key
)
resp = client.chat.completions.create(
model="gpt-5.6-luna",
messages=[{"role": "user", "content": "say OK"}],
)
print(resp.choices[0].message.content)
Node — OpenAI SDK
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://aicomp.ai/v1",
apiKey: "sk-your-gateway-key",
});
const r = await client.chat.completions.create({
model: "gpt-5.6-luna",
messages: [{ role: "user", content: "say OK" }],
});
console.log(r.choices[0].message.content);
Python — Anthropic SDK
import anthropic
client = anthropic.Anthropic(
base_url="https://aicomp.ai/v1",
api_key="sk-your-gateway-key",
)
msg = client.messages.create(
model="claude-sonnet-5",
max_tokens=64,
messages=[{"role": "user", "content": "say OK"}],
)
print(msg.content[0].text)
Plain curl
curl https://aicomp.ai/v1/chat/completions \
-H "Authorization: Bearer sk-your-gateway-key" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-5.6-luna",
"messages":[{"role":"user","content":"say OK"}]}'
Gotchas that cost people an hour
/v1doubling. The OpenAI SDK appends/chat/completions. If your base URL already ends in/v1, do not include it twice.- Streaming. Server-sent events work on most gateways, but confirm before you rely on it in production.
- Model IDs. Use the exact ID the gateway lists.
gpt-5.6-lunaandgpt-5.6-luna-2026-07-09are different entries. - Timeouts. Set an explicit timeout. A gateway adds a hop, so budget slightly more than you would direct.
Migrating an existing codebase
Because only the client constructor changes, the safest rollout is to read the base URL from config:
import os
from openai import OpenAI
client = OpenAI(
base_url=os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1"),
api_key=os.getenv("OPENAI_API_KEY"),
)
Then switching route is an environment change, not a deploy.
What it costs
| Model | Gateway rate in / out per 1M tokens | Official list in / out per 1M tokens | Diff |
|---|---|---|---|
| gpt-5.6-luna | $0.1 / $0.6 | $0.2 / $1.2 | 50% |
| gpt-5.6-terra | $1 / $6 | $2 / $12 | 50% |
| claude-sonnet-5 | $1 / $5 | $2 / $10 | 50% |
| deepseek-v4-pro | $0.66 / $1.98 | — / — | — |
Rates checked 2026-09-16. Gateway rates move with upstream promotions — verify the current number in your dashboard before committing to a budget.
Same client, same code, different per-token rate — that is the whole point of the compatibility layer. Compare on your own volume with the cost calculator.
FAQ
Does base_url work in both Python and Node?
Yes. It is base_url in Python and baseURL in Node; both take the same value and neither changes how you build requests or read responses.
Do I need to rewrite my request code?
No, as long as the endpoint speaks the same contract. The constructor changes; everything after it stays identical. Model IDs are the one thing that differs between providers, so keep them in configuration.
Is streaming supported through a custom endpoint?
Usually, but not universally. Test it explicitly with one streaming request before depending on it — it is the second most common compatibility gap after tool calling.
Can I call non-OpenAI models with the OpenAI SDK?
Only if the endpoint exposes an OpenAI-compatible layer for those models. Anthropic-native models are normally called through the Anthropic SDK; see the migration guide for the differences.
What is the safest way to roll this out?
Read the base URL from an environment variable with the vendor default as the fallback. Switching route then becomes a config change you can revert in seconds rather than a deploy.
Next
Compare rates before you switch: all model prices, or run your volume through the cost calculator.