Settings

Language

Migrate from OpenAI to TokenLab in 5 Minutes

T
TokenLab
·February 26, 2026·6 min read·Updated July 14, 2026·1735 views
#tutorial#migration#openai#getting-started
Migrate from OpenAI to TokenLab in 5 Minutes

Questions this answers

  • Do I need to change my prompts when switching to TokenLab?
  • Can I still use the same OpenAI model names through TokenLab?
  • What about streaming, function calling, and vision? Do they work the same?

Switching from OpenAI’s official API to TokenLab requires changing exactly two configuration values: your base_url and api_key. Every prompt, every model name, and every integration you already have stays identical. Once that two‑line change is in place, you also unlock over 300 models across OpenAI, Anthropic, Google, DeepSeek, and others, all through the same API key and the same request shape.

Key Takeaways

  • Migrating from OpenAI to TokenLab means replacing two configuration values. Code, prompts, and model names carry over without any rewrites.
  • Streaming, function calling, and vision all work identically because the endpoint implements the same OpenAI‑compatible contract.
  • One API key gives you access to 300+ models from multiple labs. Switching models is a one‑word change in the model parameter.
  • Before you point production traffic at the new endpoint, test failure paths, timeouts, model allowlists, and billing. Those areas are where hidden migration issues usually hide.

If you are comparing gateway options before you migrate, read the pricing comparison and the OpenRouter vs TokenLab comparison. Teams looking to optimize their visual pipelines can also explore the best AI image models API 2026 or review video generation options in the best AI video models API 2026.

The Shortest Path to Migration

  1. Sign up at TokenLab and create an API key (new accounts receive $1 in free credit).
  2. Replace your base_url and api_key in two locations.
  3. Stop. Your application already works.

The first request you send will use the same model name you already use, for example gpt-5.5, and return an identical response to OpenAI’s direct API. No SDK upgrade, no new headers, no urgent refactoring.

What You Gain After Switching

Beyond the immediate drop‑in replacement, moving to TokenLab gives you a single control plane for every model you might need. Instead of opening separate accounts and integrating different SDKs for Anthropic, Google, or DeepSeek, you send the same request shape and just change the model field. Want to try Claude Sonnet 5 for a coding review task that previously used GPT-5.5? Change one string: "model": "claude-sonnet-5". No new client, no new auth headers. The TokenLab model directory lists every supported model, including fast routers like DeepSeek V4 Flash for low‑cost bulk tasks and Gemini 3.5 Flash for high‑throughput agents.

Because TokenLab negotiates provider pricing and aggregates demand, your per‑token cost often comes in below direct provider rates, though exact pricing varies by model. You can compare offer details against OpenAI’s public pricing to see how much you save on models like GPT-5.5. When you need even cheaper routing for background summarisation or simple Q&A, the low‑cost tier includes DeepSeek V4 Flash, GLM‑5.2, Gemini 3.5 Flash, Laguna XS 2.1, Hy3, Qwen3.7 Plus, and MiniMax M3, which work with zero code changes.

Developers who work heavily with coding assistants will find it easy to A/B test across models. The best AI models for coding article covers how Claude Sonnet 5, Kimi K2.7 Code, DeepSeek V4 Pro, and others compare on real‑world code tasks, all available through the same base URL you just pointed to TokenLab. You can also monitor real-time performance metrics on the TokenLab model leaderboard.

Migrating in Different Environments

The migration stays the same across languages and tools. Any OpenAI‑compatible client needs only the new base URL and key.

Python (OpenAI SDK)

# Before: OpenAI direct
from openai import OpenAI
client = OpenAI(api_key="sk-openai-xxx")

# After: TokenLab (two line changes)
from openai import OpenAI
client = OpenAI(
    api_key="sk-tokenlab-xxx",
    base_url="https://api.tokenlab.sh/v1"
)

# No further changes required
response = client.chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Hello, world!"}]
)
print(response.choices[0].message.content)

Node.js (openai npm package)

// Before: OpenAI direct
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: 'sk-openai-xxx' });

// After: TokenLab
import OpenAI from 'openai';
const openai = new OpenAI({
  apiKey: 'sk-tokenlab-xxx',
  baseURL: 'https://api.tokenlab.sh/v1'
});

// No further changes
const completion = await openai.chat.completions.create({
  model: 'gpt-5.5',
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(completion.choices[0].message.content);

cURL

curl https://api.tokenlab.sh/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-tokenlab-xxx" \
  -d '{
    "model": "gpt-5.5",
    "messages": [{"role": "user", "content": "Say hello"}]
  }'

The same approach works for any library that accepts a custom base URL, including LangChain, TypeChat, and custom REST clients. If your app uses environment variables, simply set OPENAI_BASE_URL to https://api.tokenlab.sh/v1 and OPENAI_API_KEY to your TokenLab key.

Verify Your Migration

Run through this checklist before you replace production traffic.

Step What to check Expectation
1. Basic completion Send a simple chat request with gpt-5.5 Response identical to OpenAI’s API
2. Streaming Set stream: true on a request Tokens arrive as server‑sent events
3. Function calling Send a request with tools and tool_choice Model returns correct function arguments
4. Vision Attach an image in messages Model describes the image content
5. Rate limits / billing Set a spend limit in the TokenLab dashboard and send a high‑volume burst Requests are throttled according to your plan
6. Error handling Simulate an API key with no credit, or delete the key HTTP 401 is returned; your retry logic works
7. Model allowlists Restrict your key to only a few models via the dashboard Requests for non‑whitelisted models return 403

After the checklist passes, update your production environment variables and deploy. The migration is complete.

Frequently Asked Questions

Will my existing OpenAI models still work?

Yes. Current OpenAI-hosted models, including GPT-5.5 and the latest small OpenAI tiers listed in TokenLab, are available through the same TokenLab endpoint and behave like direct OpenAI API calls. Check the TokenLab model directory before deploying, since OpenAI model IDs and availability change over time.

Can I mix providers inside the same application?

Absolutely. Because every model uses the same request format, you can call gpt-5.5 for one step of a pipeline, claude-sonnet-5 for a later code review step, and deepseek-v4-flash for bulk extractions, all with the same API key and base URL.

Do I need to change anything about my prompts or response parsing?

No. The OpenAI‑compatible contract means identical request and response schemas. Any code that handles OpenAI responses will work without modification, including streaming chunk parsers and function‑call return objects.

Start Building on TokenLab

Replacing two configuration lines is all it takes to centralize all your model access. Sign up at TokenLab, grab your API key, swap your base_url, and start testing with over 300 models using the same code you already own.

Sources

Price observed 2026-07-07

Share:

Related models

Recent public models

Build with the models in this guide

Compare pricing, test routes, and move from article research to a working API call.