Hooking Claude into a gateway: two paths and three traps
Claude's native protocol differs from OpenAI's, but a gateway gives you two doors — the native messages endpoint or the OpenAI-compatible chat/completions. Here is the setup for each, plus the three places people break.
First, the two protocols
Claude's native endpoint is POST /v1/messages: it authenticates with x-api-key, requires an anthropic-version header, and returns a content array rather than choices2.
A gateway typically exposes both doors:
- OpenAI-compatible
/v1/chat/completions— any OpenAI SDK works; the gateway translates the body into messages format. - Anthropic-compatible
/v1/messages— for clients that only speak Anthropic, such as Claude Code.
Which door you use is decided by your client, not by the model.
Path one: Claude via the OpenAI SDK
from openai import OpenAI
client = OpenAI(base_url="https://www.salpx.com/v1", api_key="sk-...")
resp = client.chat.completions.create(
model="claude-sonnet-4-5",
messages=[
{"role": "system", "content": "You are a rigorous technical editor."},
{"role": "user", "content": "Explain idempotency keys."},
],
max_tokens=1024,
)
print(resp.choices[0].message.content)
The win: one code path can switch between gpt-5.5, claude-sonnet-4-5 and gemini-4-argon by changing model. The cost: Anthropic-specific capabilities (thinking blocks, fine-grained tool_use control) may be simplified by the translation layer. Check the gateway's mapping table for what survives.
Path two: point an Anthropic-native client at the gateway
Tools like Claude Code speak the Anthropic protocol, so you aim their endpoint and credentials at the gateway:
export ANTHROPIC_BASE_URL="https://www.salpx.com"
export ANTHROPIC_AUTH_TOKEN="sk-..."
Confirm variable names and precedence in the official docs1. Watch the base URL shape: Anthropic clients usually append /v1/messages themselves, so you typically stop at the domain — the opposite of the OpenAI SDK habit of including /v1.
Three traps
Trap one: max_tokens is mandatory. OpenAI's chat endpoint can omit it; Anthropic's messages endpoint cannot. Translation layers usually inject a default, but if your workload depends on unconstrained output, set it explicitly.
Trap two: system lives elsewhere. OpenAI puts the system message inside the messages array; Anthropic has a top-level system field. Through the OpenAI-compatible door you never notice; posting to /v1/messages with the wrong placement earns a 400.
Trap three: streaming shapes differ. OpenAI sends data: {"choices":[{"delta":...}]}; Anthropic sends named events (message_start, content_block_delta, message_stop). If you parse SSE yourself, handle both.
A billing note
Claude models price input and output tokens separately, and cached input tokens are usually cheaper. If your prompts carry a long stable prefix — a system prompt, repository context — put the stable part first and the volatile part last. Hit rate moves cost more than swapping models usually does.
One-line summary
OpenAI-speaking client → /v1/chat/completions; Anthropic-speaking client → /v1/messages. Both reach the same Claude; the only difference is who performs the translation.
Sources & attribution
This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.
- Claude Code overview — Anthropic Docs — Anthropic · accessed 2026-11-11Note:Claude Code lets you override endpoint and credentials via environment variables; confirm names and precedence in this document.
- Messages API — Anthropic API Reference — Anthropic · accessed 2026-11-11Note:Message request fields and version headers referenced here follow this API reference.
One key for Claude, GPT and 50+ models
The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.