Optimize
Migrating
In short: Migrating from OpenAI, Anthropic, OpenRouter or another gateway means changing the base URL, key and model ids, then checking the few features that differ.
On this page
Migrating to One AI API Key means making three changes in most code: the base URL, the API key, and the model id. Request and response shapes stay the same, because One AI API Key speaks the OpenAI and Anthropic formats directly. This page lists those changes and the features that behave differently.
What are the steps to migrate?
Migrating takes four steps:
- Create a key under API keys.
- Point your SDK or tool at the base URL for the format it uses.
- Replace model ids with ids from the models table.
- Run your tests, then read the section below for where you came from.
If your code reads the standard environment variables, you may not need to touch it at all:
# OpenAI SDKs (Python, Node, and most tools built on them)
OPENAI_BASE_URL=https://api.oneaiapikey.com/v1
OPENAI_API_KEY=<your One AI API Key key>
# Anthropic SDKs (no /v1 at the end)
ANTHROPIC_BASE_URL=https://api.oneaiapikey.com
ANTHROPIC_API_KEY=<your One AI API Key key>How do I migrate from the OpenAI API?
You migrate from the OpenAI API by setting the base URL and API key on the client and using a model id from the models table:
from openai import OpenAI
# Before: client = OpenAI()
client = OpenAI(
base_url="https://api.oneaiapikey.com/v1",
api_key=os.environ["ONEAIAPIKEY_API_KEY"],
)
reply = client.chat.completions.create(
model="gpt-6-luna:free", # an id from the models table
messages=[{"role": "user", "content": "Hello"}],
)import OpenAI from "openai";
// Before: const client = new OpenAI();
const client = new OpenAI({
baseURL: "https://api.oneaiapikey.com/v1",
apiKey: process.env.ONEAIAPIKEY_API_KEY,
});
const reply = await client.chat.completions.create({
model: "gpt-6-luna:free", // an id from the models table
messages: [{ role: "user", content: "Hello" }],
});- Works the same: chat completions, streaming with
stream_options, tools and parallel tool calls,response_formaton GPT models, images in messages,reasoning_effort, and the Responses API on GPT models. - Stateless only: the Responses API does not store responses for you to fetch later. Send the full history each time instead of relying on stored state.
- Not available: Assistants, Threads, Files, Batch, fine-tuning and image variations. Those routes answer
501. - Other models, same code: you can now send the same request to Claude, Grok, GLM and other families. Read Claude models in this format before you switch a request that uses
response_format.
How do I migrate from the Anthropic API?
You migrate from the Anthropic API by setting the base URL (without /v1) and API key on the client:
import anthropic
# Before: client = anthropic.Anthropic()
client = anthropic.Anthropic(
base_url="https://api.oneaiapikey.com", # no /v1: the SDK adds /v1/messages
api_key=os.environ["ONEAIAPIKEY_API_KEY"],
)
message = client.messages.create(
model="qwen-qwen3.8-27b:free",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)import Anthropic from "@anthropic-ai/sdk";
// Before: const client = new Anthropic();
const client = new Anthropic({
baseURL: "https://api.oneaiapikey.com", // no /v1: the SDK adds /v1/messages
apiKey: process.env.ONEAIAPIKEY_API_KEY,
});
const message = await client.messages.create({
model: "qwen-qwen3.8-27b:free",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});- Works the same: Messages with streaming, system prompts, tools, images and PDFs,
cache_controlprompt caching, extendedthinking, andanthropic-betaheaders, which are passed through. - Base URL: no
/v1at the end. The SDKs and Claude Code add/v1/messagesthemselves. - Token counting:
POST /v1/messages/count_tokensanswers a local estimate (about four characters per token, plus four per message), markedX-Count-Method: estimate; it is not the provider’s tokenizer. The billed number is theusageof a real reply. See Anthropic Messages. - Not available: Message Batches and the Files API.
- Claude Code and agents: see the Claude Code guide for the two environment variables it needs.
How do I migrate from OpenRouter or another gateway?
Migrating from OpenRouter or another gateway mostly means new model ids; these points differ:
- Model ids have no provider prefix here. Look up each model in the models table; spellings and version numbers can differ from other gateways, so copy the id rather than editing the old one.
- The OpenAI-style request is the same, including the
reasoningobject ({"effort": "high"}). Extra attribution headers such asHTTP-RefererorX-Titleare not needed and can stay. - Routing options such as provider preferences or a
modelsfallback list in the body are not used here. Send the fallback ids in anX-Fallback-Modelsheader instead (up to 3), or pick a fallback model in the console (fallback). - Billing is a prepaid balance in US dollars. Each request is billed at the rates on the models page; there is no per-request platform fee on top.
Which features differ by model?
Three features behave differently on Claude models, so check them before you switch:
How do I check that the migration worked?
To check that the migration worked, send one cheap request, then open the usage page. The request should be listed with its model, key, tokens and cost. If it fails, the Errors page explains each status code.
Related
- Quickstart: your first request from scratch.
- SDKs and frameworks: base URL settings for each library.