Skip to navigation
DocsMigrating

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.

Updated View .md
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:

  1. Create a key under API keys.
  2. Point your SDK or tool at the base URL for the format it uses.
  3. Replace model ids with ids from the models table.
  4. 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:

.env
# 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_format on 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_control prompt caching, extended thinking, and anthropic-beta headers, which are passed through.
  • Base URL: no /v1 at the end. The SDKs and Claude Code add /v1/messages themselves.
  • Token counting: POST /v1/messages/count_tokens answers a local estimate (about four characters per token, plus four per message), marked X-Count-Method: estimate; it is not the provider’s tokenizer. The billed number is the usage of 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 reasoning object ({"effort": "high"}). Extra attribution headers such as HTTP-Referer or X-Title are not needed and can stay.
  • Routing options such as provider preferences or a models fallback list in the body are not used here. Send the fallback ids in an X-Fallback-Models header 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.

↑ ↓ moveEnter openEsc close
New accounts$10 credit on sign-up
Claim $10 credit →