One Codebase, Four Providers: OpenAI-Compatible Endpoints for DeepSeek, Kimi, GLM and Qwen
In the November 2026 flagship lineup, DeepSeek (deepseek-flash), Kimi (K3.1 family), Zhipu GLM (GLM-5.3) and Alibaba Qwen (Qwen4-Max preview) all expose OpenAI-compatible endpoints. One codebase built on the openai SDK, two lines of config — and you can move between all four. Below is a runnable template plus the gotchas to watch when switching.
Endpoint cheat sheet
| Provider | base_url | Current primary model name |
|---|---|---|
| DeepSeek | https://api.deepseek.com/v1 | deepseek-flash (V4.1-Flash-1017) |
| Kimi (Moonshot) | https://api.moonshot.cn/v1 | K3.1 family — see platform model list |
| Zhipu GLM | https://open.bigmodel.cn/api/paas/v4 | glm-5.3 / glm-5.3-flash |
| Qwen (Bailian compatible mode) | https://dashscope.aliyuncs.com/compatible-mode/v1 | qwen-max family; preview per platform |
Note Zhipu's path is /api/paas/v4, not /v1 — the most common beginner stumble — and Qwen uses Bailian's dedicated "compatible mode" path, distinct from the native DashScope route.
Unified call template
Install the SDK first: pip install openai. Keep each provider's key in an environment variable; switching providers means changing exactly three values — base_url, key and model name:
import os
from openai import OpenAI
PROVIDERS = {
"deepseek": ("https://api.deepseek.com/v1", "DEEPSEEK_API_KEY", "deepseek-flash"),
"kimi": ("https://api.moonshot.cn/v1", "MOONSHOT_API_KEY", "kimi-k3.1"),
"glm": ("https://open.bigmodel.cn/api/paas/v4", "ZHIPU_API_KEY", "glm-5.3"),
"qwen": ("https://dashscope.aliyuncs.com/compatible-mode/v1", "DASHSCOPE_API_KEY", "qwen-max"),
}
def ask(provider: str, prompt: str) -> str:
base_url, key_env, model = PROVIDERS[provider]
client = OpenAI(api_key=os.environ[key_env], base_url=base_url)
resp = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a rigorous technical assistant."},
{"role": "user", "content": prompt},
],
temperature=0.3,
)
return resp.choices[0].message.content
print(ask("deepseek", "Explain context caching in one sentence."))
Streaming, tool calling and JSON-output parameters follow the same OpenAI spec across all four, so business code largely ports as-is; per-field support varies, so run a regression pass on real traffic before shipping.
Three gotchas when switching
- Model names churn with releases: DeepSeek's current alias is deepseek-flash; legacy aliases and snapshot models still resolve. The platform model list is the source of truth — never hardcode stale versions;
- Tool and multimodal parameters are not fully aligned: web search and file input are private extensions. On DeepSeek they now ship via the official full-stack app API (see our full-stack app API recap); other providers use their own parameters, so budget separate adaptation work here;
- Billing structures differ: peak/off-peak pricing, context caching and per-call tool fees vary by provider — the cost-saving playbook is in our API cost-saving guide.
Starting from zero
If you have not activated any provider yet, walk through DeepSeek end to end first (sign-up, key creation, first call) with our getting-started tutorial; the official OpenAI-compatibility details are in the compatibility guide. Once one provider works, the template above ports directly to the other three. Compiled from publicly available sources; API details follow each platform's documentation.
大模型网摘