Use Claude and Gemini with the OpenAI SDK: switch in one line
Most LLM code is written against the OpenAI SDK. Calling Claude or Gemini from the same code usually means a second SDK, a second request format and a second set of keys. With an OpenAI-compatible gateway you keep the SDK you have and change the base URL.
This guide uses ONEWAY, which is live today on your own provider keys and free during the beta. It takes about five minutes.
Before you start
- Create a ONEWAY account and a project. While sign-ups are invite-only, request early access first.
- Add your provider keys under Provider keys: OpenAI, Anthropic, Google Gemini or AWS Bedrock. Each provider bills you directly.
- Create an API key on the project page and keep it in a server-side environment variable, such as
ONEWAY_API_KEY. It's shown once.
The one-line change
Set baseURL to https://oneway-gateway.oneway-gateway.workers.dev/v1 and use your ONEWAY key. Everything else stays as it is.
Node.js
import OpenAI from "openai";
const ai = new OpenAI({
baseURL: "https://oneway-gateway.oneway-gateway.workers.dev/v1",
apiKey: process.env.ONEWAY_API_KEY,
});
const reply = await ai.chat.completions.create({
model: "anthropic/claude-sonnet-5-5",
messages: [{ role: "user", content: "Summarise this inbox" }],
});
console.log(reply.choices[0].message.content);Python
import os
from openai import OpenAI
ai = OpenAI(
base_url="https://oneway-gateway.oneway-gateway.workers.dev/v1",
api_key=os.environ["ONEWAY_API_KEY"],
)
reply = ai.chat.completions.create(
model="anthropic/claude-sonnet-5-5",
messages=[{"role": "user", "content": "Summarise this inbox"}],
)
print(reply.choices[0].message.content)cURL
curl https://oneway-gateway.oneway-gateway.workers.dev/v1/chat/completions \
-H "Authorization: Bearer $ONEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-5-5",
"messages": [{"role": "user", "content": "Summarise this inbox"}]
}'Pick a model by ID
Model IDs are provider/model, so the provider is visible in your code: anthropic/claude-sonnet-5-5, openai/gpt-4.1 or google/gemini-3.1-pro. Switching models is a one-word change. GET /v1/models returns the list in OpenAI's format, so tools that read a model list work unchanged.
curl https://oneway-gateway.oneway-gateway.workers.dev/v1/models \
-H "Authorization: Bearer $ONEWAY_API_KEY"
{
"object": "list",
"data": [
{ "id": "anthropic/claude-sonnet-5-5", "object": "model", "owned_by": "anthropic", "context_window": 200000 },
...
]
}Streaming
Set stream: true to get server-sent events in OpenAI's chunk format, for every provider. Streams are logged and counted for their full usage.
const stream = await ai.chat.completions.create({
model: "anthropic/claude-sonnet-5-5",
messages: [{ role: "user", content: "Write a haiku about latency." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Tools and JSON output
tools and tool_choice work with Claude as well as OpenAI-style models. Other parameters, such as response_format, are passed as sent to providers with OpenAI-compatible APIs. Capabilities differ by model, and the provider's own error message is returned when it doesn't support something.
Prefer Anthropic's SDK for Claude?
If your code uses Anthropic's Messages API, keep it. ONEWAY passes /v1/messages through to Claude, streamed or not, and accepts the x-api-key header that Anthropic's SDKs send. Point the SDK at https://oneway-gateway.oneway-gateway.workers.dev, without /v1:
import Anthropic from "@anthropic-ai/sdk";
const ai = new Anthropic({
baseURL: "https://oneway-gateway.oneway-gateway.workers.dev",
apiKey: process.env.ONEWAY_API_KEY,
});
const message = await ai.messages.create({
model: "anthropic/claude-sonnet-5-5",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});Errors you might see first
403 provider_key_missing: add a key for that model's provider under Provider keys.404 model_not_found: check the ID, or list them withGET /v1/models.401 invalid_api_key: the key is wrong or revoked; check it was copied whole.404 not_found_error: the base URL should end in/v1.
Every response carries an x-request-id header you can search for under Requests. The full list is in the error reference.
What you get once you've switched
- Per-project budgets with soft warnings or hard caps.
- Spend by customer, feature, agent and release through attribution headers.
- Fallbacks and retries with two headers.
- Every request logged with its model, tokens, cost and latency.
Coming from OpenRouter or Portkey? See ONEWAY vs OpenRouter and switching from another gateway.
FAQ
Can I use Claude with the OpenAI SDK?
Yes. Point the OpenAI SDK at an OpenAI-compatible gateway such as ONEWAY and use a Claude model ID, for example anthropic/claude-sonnet-5-5. The gateway translates the request for Claude and returns OpenAI's response shape, including usage, so the rest of your code doesn't change. Streaming and tool calls work too.
Do I need to change my request bodies?
No. Send model and messages exactly as you would to OpenAI. Only the base URL, the API key and the model ID change. Parameters are passed through to the provider, which decides what it supports; if it rejects one, its error message is returned to you.
Should I use the OpenAI SDK or the Anthropic SDK for Claude?
Use the OpenAI SDK when you want one client for Claude, GPT and Gemini. Use Anthropic's SDK when you rely on Messages API features: ONEWAY passes /v1/messages straight through to Claude. Point the Anthropic SDK at the gateway's root URL, without /v1. Budgets and attribution headers work the same on both.