๐Ÿ“… July 24, 2026 ยท ๐Ÿ“– 10 min read ยท Last updated: July 2026

OpenAI Compatible API:
How to Switch in 5 Minutes

You've been using OpenAI's API. The pricing is climbing. You've heard about cheaper alternatives. But rewriting your entire codebase? That's a non-starter.

Good news: you don't need to rewrite anything. Dozens of world-class LLM providers now offer OpenAI-compatible APIs. You change two lines of code โ€” the base URL and API key โ€” and you're running on models that are 80โ€“97% cheaper.

Total migration time:

โ‰ค 5 minutes

Two lines of code. Zero refactoring. Same SDK.

1. Why You Need an OpenAI Compatible API

OpenAI's API has become the de facto standard for LLM interactions. But relying on a single provider creates risks:

An OpenAI compatible API solves all of these. You keep the same SDK, same code patterns, same mental model โ€” but gain access to 38+ models from multiple providers, at dramatically lower costs.

2. What "OpenAI Compatible" Actually Means

An API is "OpenAI compatible" when it implements the same HTTP endpoints, request format, and response format as OpenAI's API. Specifically:

FeatureStatus
Chat Completions (/v1/chat/completions)โœ… Fully compatible
Streaming responsesโœ… Fully compatible
Function calling / Tool useโœ… Fully compatible
JSON mode (structured output)โœ… Fully compatible
Embeddings (/v1/embeddings)โœ… Most providers
Standard params (temperature, top_p, max_tokens)โœ… Fully compatible
OpenAI Python/Node.js SDKโœ… Works as-is

In practice, this means: if your code works with OpenAI, it works with any compatible provider. Period.

3. The Migration: Step by Step

1

Get your new API key

Sign up at AI Token and grab your API key. This single key gives you access to 38+ models from DeepSeek, Qwen, GLM, Kimi, MiniMax, Step, and more.

2

Change your base URL

Replace the OpenAI endpoint with the AI Token endpoint. That's it โ€” everything else stays the same.

What changes in your code:

Python โ€” OpenAI SDK
- client = OpenAI(api_key="sk-your-openai-key") + client = OpenAI( + base_url="http://47.237.87.92:3001/v1", + api_key="your-ai-token-key" + )
Model name change
- model="gpt-4o" + model="deepseek-ai/DeepSeek-V4-Flash" # or any of 38+ models
3

Run your code

That's it. Your existing prompts, streaming logic, function definitions, and error handling all work unchanged.

4. Complete Code Examples

Python โ€” Full Migration Example

from openai import OpenAI

# ============================================
# BEFORE: OpenAI
# ============================================
# client = OpenAI(api_key="sk-your-openai-key")
# response = client.chat.completions.create(
#     model="gpt-4o",
#     messages=[{"role": "user", "content": "Hello!"}]
# )

# ============================================
# AFTER: AI Token (2 lines changed!)
# ============================================
client = OpenAI(
    base_url="http://47.237.87.92:3001/v1",
    api_key="your-ai-token-key"
)

# DeepSeek V4 Flash โ€” 97% cheaper than GPT-4o
response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Flash",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello!"}
    ],
    temperature=0.7,
    max_tokens=1024
)
print(response.choices[0].message.content)


# ============================================
# Streaming works too โ€” no changes needed!
# ============================================
stream = client.chat.completions.create(
    model="qwen/Qwen2.5-72B-Instruct",
    messages=[{"role": "user", "content": "Write a poem about code"}],
    stream=True
)
for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")


# ============================================
# Function calling works too!
# ============================================
import json

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Get weather for a location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
    tools=tools
)
print(response.choices[0].message.tool_calls)

Node.js โ€” Full Migration Example

import OpenAI from 'openai';

// BEFORE: OpenAI
// const client = new OpenAI({ apiKey: 'sk-your-openai-key' });

// AFTER: AI Token โ€” just change baseURL and apiKey!
const client = new OpenAI({
  baseURL: 'http://47.237.87.92:3001/v1',
  apiKey: 'your-ai-token-key'
});

// Basic chat completion
const response = await client.chat.completions.create({
  model: 'deepseek-ai/DeepSeek-V4-Flash',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Explain recursion in one paragraph.' }
  ]
});
console.log(response.choices[0].message.content);

// Streaming
const stream = await client.chat.completions.create({
  model: 'qwen/Qwen2.5-72B-Instruct',
  messages: [{ role: 'user', content: 'Write a haiku about APIs' }],
  stream: true
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

cURL

# Same format as OpenAI โ€” just different base URL and model
curl http://47.237.87.92:3001/v1/chat/completions \
  -H "Authorization: Bearer your-ai-token-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-ai/DeepSeek-V4-Flash",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "What is 2+2?"}
    ],
    "temperature": 0.7,
    "max_tokens": 100,
    "stream": false
  }'

5. Available Models Through AI Token

Once connected, you can use any of these models by changing the model parameter:

ProviderModel NameBest ForCost vs GPT-4o
DeepSeekdeepseek-ai/DeepSeek-V4-FlashGeneral, coding97% cheaper
DeepSeekdeepseek-ai/DeepSeek-V4-ProComplex tasks80% cheaper
DeepSeekdeepseek-ai/DeepSeek-R1Reasoning, math78% cheaper
Qwenqwen/Qwen2.5-72B-InstructChinese, long context94% cheaper
GLMzhipu/glm-4-flashBudget, prototypingFREE
Kimimoonshot/kimi-128kDocument analysis92% cheaper
MiniMaxminimax/abab6.5-chatMultimodal, voice93% cheaper
OpenAIopenai/gpt-4oFrontier taskssame price
๐Ÿ’ก Pro tip: Use cheap models for 90% of your traffic and route only quality-critical requests to GPT-4o. Most teams save 70โ€“90% with zero perceived quality loss.

6. Advanced: Smart Routing

With AI Token, you can implement intelligent model routing โ€” using the cheapest model that's good enough for each task:

from openai import OpenAI

client = OpenAI(
    base_url="http://47.237.87.92:3001/v1",
    api_key="your-ai-token-key"
)

def smart_complete(messages, task_type="general"):
    """Route to the best model based on task type."""
    model_map = {
        "general":    "deepseek-ai/DeepSeek-V4-Flash",   # $0.14/M โ€” fast & cheap
        "chinese":    "qwen/Qwen2.5-72B-Instruct",       # $0.15/M โ€” best Chinese
        "reasoning":  "deepseek-ai/DeepSeek-R1",         # $0.55/M โ€” deep thinking
        "long_doc":   "moonshot/kimi-128k",              # $0.20/M โ€” 128K context
        "free":       "zhipu/glm-4-flash",               # $0.00 โ€” completely free
        "premium":    "openai/gpt-4o",                   # $2.50/M โ€” frontier quality
    }
    
    model = model_map.get(task_type, model_map["general"])
    
    return client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=0.7
    )

# Usage โ€” just specify the task type!
result = smart_complete(
    messages=[{"role": "user", "content": "Summarize this meeting transcript..."}],
    task_type="general"
)

# Chinese content โ€” auto-routed to Qwen
result = smart_complete(
    messages=[{"role": "user", "content": "ๅธฎๆˆ‘็ฟป่ฏ‘่ฟ™ๆฎต่ฏๆˆ่‹ฑๆ–‡..."}],
    task_type="chinese"
)

7. Common Migration Concerns

โš ๏ธ "What if the response format is slightly different?"
The response format is identical โ€” same JSON structure, same field names, same streaming format. That's the whole point of OpenAI compatibility. If you encounter differences, it's usually in provider-specific extensions (like token usage details), not the core response.
โš ๏ธ "What about rate limits?"
Each model has its own rate limits. DeepSeek V4 Flash handles very high throughput. If you need higher limits, the AI Token team can configure custom rate limits for your account.
โš ๏ธ "Can I use this in production?"
Yes. AI Token provides enterprise-grade uptime with automatic failover between providers. If DeepSeek is down, requests can automatically route to Qwen or GLM as backup.

8. Migration Checklist

  1. โ˜ Get your AI Token API key from /pay/starter
  2. โ˜ Update base_url in your OpenAI client initialization
  3. โ˜ Update api_key to your new key
  4. โ˜ Change model names to your preferred alternatives
  5. โ˜ Test with the free playground first
  6. โ˜ Run your test suite to verify responses
  7. โ˜ Deploy to production ๐Ÿš€

Switch in 5 Minutes. Save 90%+ Forever.

One line of code. 38+ models. OpenAI-compatible. Zero risk.

Get Your API Key โ†’ Try Before You Buy

FAQ

What is an OpenAI compatible API?

An OpenAI compatible API uses the exact same HTTP endpoints, request format, and response format as OpenAI's API. This means the official OpenAI SDK (Python, Node.js, etc.) works without any modifications โ€” you just change the base URL and API key. It's like having a universal remote control that works with every TV brand.

How do I switch from OpenAI to a cheaper alternative?

It takes literally 2 lines of code. Change base_url to the new provider's endpoint and update your api_key. All your existing prompts, streaming logic, function calling, and error handling remain exactly the same. We recommend testing in the free playground first, then updating your production config.

Which models work with the OpenAI SDK?

DeepSeek, Qwen, GLM, Kimi, MiniMax, Step, Yi, Baichuan, and 30+ other models all provide OpenAI-compatible endpoints. Through AI Token, all 38+ models work seamlessly with the standard OpenAI SDK โ€” Python, Node.js, Go, Ruby, etc.

Will streaming and function calling still work?

Yes. Streaming (Server-Sent Events), function calling, JSON mode, and all standard parameters work identically. The wire format is the same โ€” that's what "compatible" means. Some providers may have slight differences in advanced features like logprobs, but core functionality is identical.

Can I use multiple models at the same time?

Absolutely. With AI Token, you can call different models in different requests using the same client. Use DeepSeek V4 Flash for general tasks, Qwen for Chinese content, Kimi for long documents โ€” all through the same endpoint with the same API key. You can even implement smart routing to automatically select the best model per request.

What if I need to go back to OpenAI?

Just change the base_url and api_key back to OpenAI's. Since all your code uses the same OpenAI SDK format, there's zero lock-in. You can switch between providers freely โ€” or use AI Token to access OpenAI models alongside Chinese alternatives through the same endpoint.

Related Resources

๐Ÿš€ Switch in 5 min ยท 38+ Models ยท Save 90%+ ็ซ‹ๅณ่ฎข้˜… โ†’ ๐ŸŽฎ Free Playground

๐Ÿ“š Related Articles

DeepSeek API Tutorial
Try the most popular OpenAI alternative
DeepSeek vs OpenAI Comparison
See why developers are switching
Cheapest LLM APIs
Compare pricing after migration