TokenPAPATokenPAPA
利用ガイドAPIリファレンスAIアプリケーションブログ

OpenAI-Compatibility Explained: How One API Connects to 30+ LLMs (DeepSeek, GPT, Claude, Gemini & More)

How OpenAI-compatible APIs let you access 30+ LLM providers (DeepSeek, GPT, Claude, Gemini, Mimo, Qwen, GLM, Kimi) through a single SDK. Technical guide with code examples for seamless model switching.

OpenAI-Compatibility Explained: How One API Connects to 30+ LLMs

If you've built anything with LLMs in 2026, you've used the OpenAI API format. It's become the de facto standard — /v1/chat/completions, messages array, model string, role/content pairs.

But here's the thing: that format isn't exclusive to OpenAI anymore.

DeepSeek, Claude, Gemini, Mimo, Qwen, GLM, Kimi, and dozens more providers now offer OpenAI-compatible APIs. This means you can access any of them using the same code, the same SDK, and the same integration pattern.

This guide explains how OpenAI-compatibility works, why it matters, and how you can use TokenPAPA to switch between 30+ models with a single line change.


What "OpenAI-Compatible" Actually Means

An API is "OpenAI-compatible" when it uses the same:

  • Endpoint: /v1/chat/completions
  • Request body: { model, messages, temperature, max_tokens, stream }
  • Response format: { id, object, choices: [{ message: { role, content } }], usage }
  • Authentication: Authorization: Bearer <key>
  • Streaming: SSE-based text/event-stream with data: {...} deltas

Here's what it looks like in practice:

# This works identically with ANY OpenAI-compatible provider
import requests

response = requests.post(
    "https://api.openai.com/v1/chat/completions",  # <-- Change this
    headers={
        "Authorization": "Bearer <key>",  # <-- Change this
        "Content-Type": "application/json"
    },
    json={
        "model": "gpt-4o",  # <-- Change this
        "messages": [{"role": "user", "content": "Hello!"}],
        "temperature": 0.7
    }
)

Replace the base URL, API key, and model name — and you're talking to a completely different provider.


The Multi-Provider Problem

Without a unified API, connecting to multiple LLMs looks like this:

┌─────────────────────────────────────────────────┐
│                   Your Application               │
├─────────┬─────────┬──────────┬────────┬─────────┤
│ OpenAI  │ DeepSeek│ Anthropic│ Google │ Xiaomi  │
│ SDK     │ SDK     │ SDK      │ SDK    │ SDK     │
├─────────┼─────────┼──────────┼────────┼─────────┤
│ openai  │ deepseek│ anthropic│ google │ xiaomi  │
│ .com    │ .com    │ .com     │ .com   │ .com    │
└─────────┴─────────┴──────────┴────────┴─────────┘

Five different SDKs. Five API keys. Five billing dashboards. Five authentication patterns. Five sets of rate limits.

Now imagine this:

┌─────────────────────────────────────────────────┐
│                   Your Application               │
├─────────────────────────────────────────────────┤
│                 OpenAI SDK                       │
├─────────────────────────────────────────────────┤
│               TokenPAPA (one URL, one key)       │
├─────────┬─────────┬──────────┬────────┬─────────┤
│ OpenAI  │ DeepSeek│ Anthropic│ Google │ Xiaomi  │
│         │         │          │        │         │
└─────────┴─────────┴──────────┴────────┴─────────┘

One SDK. One API key. One billing dashboard. Your code never changes.


Code Examples: The Power of One API

Python: Switching Between Models

from openai import OpenAI

client = OpenAI(
    base_url="https://tokenpapa.ai/v1",
    api_key="your-tokenpapa-key"
)

completion = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Write a Python function to sort a list"}],
    temperature=0.7
)
print(completion.choices[0].message.content)
from openai import OpenAI

client = OpenAI(
    base_url="https://tokenpapa.ai/v1",
    api_key="your-tokenpapa-key"
)

# Only the model name changes!
completion = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Write a Python function to sort a list"}],
    temperature=0.7
)
print(completion.choices[0].message.content)
from openai import OpenAI

client = OpenAI(
    base_url="https://tokenpapa.ai/v1",
    api_key="your-tokenpapa-key"
)

# Same code, different model
completion = client.chat.completions.create(
    model="gemini-3.5-flash",
    messages=[{"role": "user", "content": "Write a Python function to sort a list"}],
    temperature=0.7
)
print(completion.choices[0].message.content)
from openai import OpenAI

client = OpenAI(
    base_url="https://tokenpapa.ai/v1",
    api_key="your-tokenpapa-key"
)

# Same code, different model
completion = client.chat.completions.create(
    model="mimo-v2.5-pro",
    messages=[{"role": "user", "content": "Write a Python function to sort a list"}],
    temperature=0.7
)
print(completion.choices[0].message.content)

JavaScript / Node.js

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://tokenpapa.ai/v1',
  apiKey: 'your-tokenpapa-key',
});

// DeepSeek
const response = await client.chat.completions.create({
  model: 'deepseek-v4-flash',
  messages: [{ role: 'user', content: 'Translate this to French' }],
});

// Or switch to Claude — same code, change model name only
const response2 = await client.chat.completions.create({
  model: 'claude-sonnet-4-6',
  messages: [{ role: 'user', content: 'Translate this to French' }],
});

cURL (for quick testing)

# DeepSeek
curl https://tokenpapa.ai/v1/chat/completions \
  -H "Authorization: Bearer your-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"Hello"}],"temperature":0.7}'

# Claude
curl https://tokenpapa.ai/v1/chat/completions \
  -H "Authorization: Bearer your-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-4-6","messages":[{"role":"user","content":"Hello"}],"stream":true}'

# Gemini
curl https://tokenpapa.ai/v1/chat/completions \
  -H "Authorization: Bearer your-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gemini-3.5-flash","messages":[{"role":"user","content":"Hello"}],"temperature":0.7}'

Advanced Patterns with a Unified API

1. Cost-Optimized Routing

Use cheap models for simple tasks, expensive models for complex ones:

def get_completion(task_complexity, user_message):
    model = "deepseek-v4-flash" if task_complexity == "simple" else "claude-sonnet-4-6"
    
    client = OpenAI(base_url="https://tokenpapa.ai/v1", api_key="your-key")
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": user_message}]
    )
    return response.choices[0].message.content

# Simple greeting → $0.00003
print(get_completion("simple", "Hi!"))

# Complex analysis → $0.015
print(get_completion("complex", "Analyze this financial report..."))

2. Fallback Chains

If one provider is down, try another automatically:

def robust_completion(messages):
    models = [
        "deepseek-v4-flash",    # Try DeepSeek first (cheapest)
        "gpt-5.4-mini",         # Fallback to GPT
        "claude-sonnet-4-6",    # Last resort
    ]
    
    client = OpenAI(base_url="https://tokenpapa.ai/v1", api_key="your-key")
    
    for model in models:
        try:
            response = client.chat.completions.create(
                model=model,
                messages=messages,
                timeout=30
            )
            return response.choices[0].message.content
        except Exception:
            continue
    
    raise Exception("All providers failed")

3. A/B Testing Models

Test different models on the same input to compare quality:

def compare_models(prompt, models):
    client = OpenAI(base_url="https://tokenpapa.ai/v1", api_key="your-key")
    
    results = {}
    for model in models:
        response = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": prompt}]
        )
        results[model] = {
            "content": response.choices[0].message.content,
            "tokens": response.usage.total_tokens,
            "cost": calculate_cost(model, response.usage)
        }
    return results

Which Models Are Available?

TokenPAPA's unified API supports 30+ models across these providers:

ProviderModelsPrice Range (Input)
DeepSeekV4 Flash, V4 Pro$0.14 – $0.28
Mimo (Xiaomi)V2.5, V2.5 Pro$0.08 – $0.12
OpenAIGPT-5.5, GPT-5.4, GPT-5.4 Mini$0.15 – $15
AnthropicClaude Opus 4, Sonnet 4$3 – $15
GoogleGemini 3.1 Pro, 3.5 Flash, 3 Flash$0.25 – $10
Alibaba (Qwen)Qwen 3.5 Flash, 3.5 Plus$0.20 – $0.40
Zhipu AI (GLM)GLM-5, 5.1, 5.2$0.30 – $0.50
Moonshot (Kimi)Kimi K2.6$0.50
MiniMaxM2.5, M2.7, M3$0.60 – $0.80
TencentHunyuan HY3 Preview$1.00

Why OpenAI-Compatibility Won

You might wonder: why did OpenAI's format become the standard instead of Anthropic's or Google's?

Three reasons:

  1. First mover advantage — OpenAI launched the chat completions API first and captured developer mindshare
  2. Simplicity — The /v1/chat/completions format with messages array is clean and intuitive
  3. SDK ecosystem — The OpenAI Python and Node.js SDKs became the de facto tools for LLM integration

By adopting OpenAI-compatibility, every other provider — from DeepSeek to Google to Xiaomi — made it trivially easy for developers to try their models. No new SDK to learn. No migration project. Just a URL change.


Getting Started with TokenPAPA

Step 1: Sign up at tokenpapa.ai — no Chinese phone required, international developers welcome.

Step 2: Get your API key from the dashboard. You'll receive $2 in free credits to start.

Step 3: Install any OpenAI-compatible SDK and point it to TokenPAPA:

pip install openai
from openai import OpenAI

client = OpenAI(
    base_url="https://tokenpapa.ai/v1",
    api_key="your-tokenpapa-key"  # Replace with your key
)

response = client.chat.completions.create(
    model="deepseek-v4-flash",  # Or any model you want to try
    messages=[{"role": "user", "content": "Hello, world!"}]
)

print(response.choices[0].message.content)

That's it. You're now connected to 30+ LLMs through one API.


Summary

CapabilityWithout TokenPAPAWith TokenPAPA
SDKs to install5+ (one per provider)1 (OpenAI SDK)
API keys to manage5+1
Billing dashboards5+1
Model switchingRewrite codeChange 1 parameter
Fallback handlingCustom infrastructureBuilt-in
New model adoptionNew integrationJust the model name

One API. One key. Thirty models. Zero friction.

このガイドはいかがですか?