大模型网摘deepseek.wang

Tutorials · 2026-11-16

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

Providerbase_urlCurrent primary model name
DeepSeekhttps://api.deepseek.com/v1deepseek-flash (V4.1-Flash-1017)
Kimi (Moonshot)https://api.moonshot.cn/v1K3.1 family — see platform model list
Zhipu GLMhttps://open.bigmodel.cn/api/paas/v4glm-5.3 / glm-5.3-flash
Qwen (Bailian compatible mode)https://dashscope.aliyuncs.com/compatible-mode/v1qwen-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

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.