Introduction
If you're building AI applications with Chinese LLMs like DeepSeek, Qwen, or Kimi, you've probably noticed that each provider has its own API format. This means rewriting your code every time you want to switch models or test different providers.
There's a better way: use an OpenAI-compatible API gateway that lets you access all Chinese LLMs with minimal code changes.
In this tutorial, I'll show you how to integrate DeepSeek V3, Qwen 2.5, and other Chinese LLMs using just one API key and the familiar OpenAI SDK.
Why Use an OpenAI-Compatible Gateway?
Chinese LLMs offer competitive pricing and strong performance, but integrating them traditionally requires:
- Learning different API formats for each provider
- Managing multiple API keys
- Rewriting code when switching models
- Handling different authentication methods
An OpenAI-compatible gateway solves all of these problems by providing:
- One API format - Use the same code for all models
- One API key - Manage billing in one place
-
Easy migration - Just change
base_urlandmodelname - Unified features - Streaming, function calling, and more work consistently
Quick Start: Python Example
Here's how to call DeepSeek V3 using the OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(
base_url="https://api.chinawhapi.com/v1",
api_key="your_api_key"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "Hello! What can you do?"}
]
)
print(response.choices[0].message.content)
That's it! The only differences from standard OpenAI usage are:
- Change the
base_urlto the gateway endpoint - Use the model name provided by the gateway (e.g.,
deepseek-chat)
Supported Models
With ChinaWHAPI, you get access to:
- DeepSeek: deepseek-chat (V3), deepseek-reasoner (R1)
- Qwen: qwen-turbo, qwen-plus, qwen-max
- Kimi: moonshot-v1-8k, moonshot-v1-32k, moonshot-v1-128k
- GLM: glm-4, glm-4-flash
- Doubao: doubao-pro-4k, doubao-pro-32k
- MiniMax: abab6.5, abab6.5s
All accessible through the same API format.
Streaming Support
Streaming works exactly the same as OpenAI:
from openai import OpenAI
client = OpenAI(
base_url="https://api.chinawhapi.com/v1",
api_key="your_api_key"
)
stream = client.chat.completions.create(
model="qwen-plus",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Cost Comparison
One major advantage of Chinese LLMs is pricing. Here's a rough comparison (per 1M tokens):
| Model | Input Price | Output Price |
|---|---|---|
| GPT-4 | $10.00 | $30.00 |
| DeepSeek V3 | $0.27 | $1.10 |
| Qwen Plus | $0.80 | $2.00 |
| Kimi | $0.50 | $1.50 |
You can reduce costs by 10-30x while maintaining good quality for many use cases.
Error Handling
The gateway returns standard HTTP status codes:
-
401- Invalid API key -
429- Rate limit exceeded -
500- Server error
Handle them the same way you would with OpenAI:
from openai import OpenAI, APIError
client = OpenAI(
base_url="https://api.chinawhapi.com/v1",
api_key="your_api_key"
)
try:
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello"}]
)
except APIError as e:
print(f"API error: {e}")
Getting Started
To try this yourself:
- Sign up at ChinaWHAPI to get your API key
-
Install the OpenAI SDK:
pip install openai - Copy the code examples above
-
Replace
your_api_keywith your actual key - Run and start experimenting!
New users get 200K free credits to test different models.
Conclusion
Using an OpenAI-compatible gateway makes it trivial to add Chinese LLMs to your applications. You get:
- Access to 200+ models from one API
- Dramatically lower costs
- Minimal code changes
- Consistent developer experience
Whether you're building a chatbot, RAG system, or AI agent, this approach lets you focus on your application logic instead of API integration details.
Have questions? Drop them in the comments below!
Top comments (0)