Blog
API Guides2 min read

How to Switch from OpenAI to DeepSeek API

Switch from OpenAI to DeepSeek in 5 Minutes

DeepSeek V3 matches GPT-4 performance at 90% lower cost. The migration takes one line of code.

The One-Line Migration

# Before (OpenAI Direct)
client = openai.OpenAI(api_key="sk-...")

# After (DeepSeek via AI API Hub)
client = openai.OpenAI(
    api_key="your-hub-key",
    base_url="https://api.apiyihe.org/v1"  # ← Only change
)

Everything else stays the same.

What Changes?

| Aspect | Before (OpenAI) | After (DeepSeek) | |---|---|---| | SDK | openai | openai (same) | | Code | Identical | Identical | | Format | Chat completions | Chat completions (same) | | Price | $2.50/1M input | $0.27/1M input (-89%) | | Quality | GPT-4 level | GPT-4 level (comparable) |

What Doesn't Change?

# All of this works identically:

# Chat completions
response = client.chat.completions.create(
    model="deepseek-v3",  # or "gpt-4o" for OpenAI
    messages=[{"role": "user", "content": "Hello"}]
)

# Streaming
stream = client.chat.completions.create(
    model="deepseek-v3",
    messages=[...],
    stream=True
)

# Function calling
response = client.chat.completions.create(
    model="deepseek-v3",
    messages=[...],
    functions=[...]
)

# All parameters: temperature, top_p, max_tokens, etc.

Migration Checklist

  1. Register at AI API Hub → get API key
  2. Add base_url="https://api.apiyihe.org/v1" to your client
  3. Change model name from "gpt-4o" to "deepseek-v3"
  4. Test with a simple prompt
  5. Deploy with 90% lower API costs

When to Use DeepSeek vs GPT-4o

| Task | Best Model | |---|---| | General chat | Either — both excellent | | Coding | DeepSeek V3 (equal quality, cheaper) | | Math/Reasoning | DeepSeek R1 (chain-of-thought) | | Complex vision tasks | GPT-4o (better multimodal) | | Large-scale processing | DeepSeek V3 (cost advantage) |

Get Your API Key Now

Start building with 50+ AI models through one unified gateway.

Create Account
Get API Key