API Token Route

Home / Guides / OpenAI-Compatible API Setup

OpenAI-Compatible API Setup

If your code already speaks the OpenAI API, you can switch gateways by changing two values: the base URL and the API key. This guide covers Chat Completions, the Responses API, streaming, and the cases where the two endpoints are not interchangeable.

Set the OpenAI base URL to https://api.apitokenroute.com/v1 and authenticate with Authorization: Bearer sk-atr-.... Chat Completions at POST /v1/chat/completions accepts the catalog's chat models in the standard OpenAI shape. The Responses API at POST /v1/responses accepts GPT models only and returns 400 for Claude or Gemini IDs. Both support streaming with stream: true. Keep /v1 on the base URL for OpenAI clients; the Anthropic-native and Gemini-native formats use the origin without /v1.

Updated: 2026-12-02

Base URL and authentication

ClientBase URLHeader
OpenAI SDK / Chat Completionshttps://api.apitokenroute.com/v1Authorization: Bearer sk-atr-...
OpenAI Responses APIhttps://api.apitokenroute.com/v1Authorization: Bearer sk-atr-...
Anthropic SDKhttps://api.apitokenroute.comx-api-key plus anthropic-version
Gemini nativehttps://api.apitokenroute.comAuthorization: Bearer sk-atr-...

The most common setup error is dropping /v1 from an OpenAI client or adding it to an Anthropic client. Match the table.

Chat Completions

Send a standard OpenAI chat request:

curl https://api.apitokenroute.com/v1/chat/completions -H 'Authorization: Bearer sk-atr-xxxxxx' -H 'content-type: application/json' -d '{"model": "gpt-6.2-sol", "max_tokens": 512, "messages": [{"role": "user", "content": "Hello"}]}'

Python with the OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    api_key="sk-atr-xxxxxx",
    base_url="https://api.apitokenroute.com/v1",
)
resp = client.chat.completions.create(
    model="gpt-6.2-sol",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

The response follows the standard chat.completion object. Use any model ID from the catalog that the deployment serves through this path.

Streaming

Add stream: true. The gateway returns standard OpenAI SSE chunks in the data: {...} format and ends with data: [DONE].

stream = client.chat.completions.create(
    model="gpt-6.2-sol",
    messages=[{"role": "user", "content": "Write a haiku."}],
    stream=True,
)
for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="")

If your client receives one JSON body instead of SSE events, check that stream is the boolean true, not the string true.

Responses API

The Responses endpoint takes the OpenAI Responses shape:

curl https://api.apitokenroute.com/v1/responses -H 'Authorization: Bearer sk-atr-xxxxxx' -H 'content-type: application/json' -d '{"model": "gpt-6.2-sol", "input": "Explain this error in one paragraph."}'

Python:

resp = client.responses.create(
    model="gpt-6.2-sol",
    input="Explain this error in one paragraph.",
)
print(resp.output_text)

This endpoint is GPT-only. A Claude or Gemini model ID returns HTTP 400. Adding stream: true returns OpenAI Responses streaming events.

Which endpoint to use

  1. Existing OpenAI SDK code that calls chat completions: keep Chat Completions. It is the smallest change.
  2. A tool that requires the Responses wire format, such as Codex CLI with wire_api = "responses": use /v1/responses.
  3. Claude models: use /v1/messages with the Anthropic protocol, not Responses.
  4. Gemini models: use the native generateContent endpoint when the client expects Gemini shapes.
  5. A streaming chat UI: either endpoint works with stream: true; pick based on the response object your UI parses.
  6. Billing reconciliation: the billing API is the same regardless of the model protocol.

Codex CLI example

Codex CLI is the clearest case where the Responses endpoint matters. Its provider block points at the same origin with /v1:

model_provider = "apitokenroute"
model = "gpt-6.2-sol"

[model_providers.apitokenroute]
name = "API Token Route"
base_url = "https://api.apitokenroute.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

The API key goes in the OPENAI_API_KEY environment variable. Full install steps are in Codex CLI setup.

Errors and compatibility boundaries

StatusMeaningWhat to do
401Key rejectedCheck the Bearer token and that the key is active
402, or 400 on the OpenAI shapeWallet balance is insufficientTop up from 5 USD and retry
404Model is not available on this deploymentCheck GET /v1/models
429Requests-per-minute limitWait for retry-after or lower concurrency
400 from /v1/responsesNon-GPT model sent to ResponsesUse /v1/messages for Claude or the Gemini native endpoint

Compatibility is at the protocol level, not a guarantee that every provider-specific field behaves identically. Test the fields you depend on, especially tools, structured outputs and vendor-specific parameters. For the Anthropic side, see Anthropic-native API setup; for Claude Code failures, see troubleshooting.

FAQ

What base URL should the OpenAI SDK use?

https://api.apitokenroute.com/v1. Keep the /v1 suffix. The Anthropic-native and Gemini-native formats use https://api.apitokenroute.com without /v1.

Does the Responses API work with Claude or Gemini?

No. /v1/responses accepts GPT models only and returns HTTP 400 for other families. Use /v1/messages for Claude and the Gemini native endpoint for Gemini.

How do I stream a response?

Set stream to the boolean true. Chat Completions returns SSE chunks ending in data: [DONE]. Responses returns OpenAI Responses streaming events.

Can I use the same key for all protocols?

Yes. The API key authenticates the account; the protocol is chosen by the endpoint and headers. Create separate keys per environment for operational hygiene.

Why do I get 400 instead of 402 when my balance is empty?

The OpenAI-compatible shape maps the insufficient-balance error to 400 in some paths, while other protocols return 402. The message still says the wallet balance is insufficient; top up and retry.

Is every OpenAI parameter supported?

No compatibility layer can promise that. Standard chat fields work, but provider-specific or newer fields should be tested before production. Check the model and endpoint you actually use.