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.

In short: Both the OpenAI and Anthropic SDKs accept a base URL argument, so changing billing route is a constructor change rather than a rewrite — Python uses base_url, Node uses baseURL, and all request and response code stays identical.
Don't have an account yet? You need an API key from the gateway before the steps below will work. Create one free → (no prepay, $1 minimum top-up)
Check current rates → Free to sign up · $1 minimum top-up · No prepayment
Quick self-check. Before wiring anything into your app, confirm the key works. This lists every model your account can call — it costs nothing and works from any machine:
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

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

Models you can reach through the same client — gateway rate vs official list
ModelGateway 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.250%
gpt-5.6-terra$1 / $6$2 / $1250%
claude-sonnet-5$1 / $5$2 / $1050%
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.

Get API access