One OpenAI SDK Client, Many Models: GPT-6.2 Sol plus DeepSeek, Kimi, GLM and Qwen via base_url
As of 2026-11-25, setting the official OpenAI SDK's base_url to https://api.qcode.cc/openai/v1 and api_key to your QCode cr_ key gives you one client that calls gpt-6.2-sol, deepseek-v4.1-flash, kimi-k3.1-pro, glm-5.3, qwen3.8-max and more through Chat Completions. Switching models means changing the model field and nothing else. GPT models can also use the Responses API; on the OpenAI protocol, Chinese models support Chat Completions only. Claude models do not run on the OpenAI protocol at all and need the Anthropic SDK.
QCode is an independent third-party API service with no official relationship or partnership with OpenAI, Zhipu, Moonshot, DeepSeek or Alibaba. Path and protocol rules here come from the endpoints and Chinese-models pages on docs.qcode.cc; SDK usage follows the official OpenAI SDK.
Updated 2026-11-26
Key facts
- Base URL:
https://api.qcode.cc/openai/v1. The SDK builds/openai/v1/chat/completionsor/openai/v1/responses. Users in Asia can switch the host toasia.qcode.cc, and users in North America or Europe tous.qcode.cc. The key is the same. - One key, protocol chosen by path: GPT runs on Chat Completions and Responses. GLM, Kimi, DeepSeek and Qwen run on Chat Completions (not Responses). Claude runs only on Anthropic Messages.
- GPT-6.2 Sol (released by OpenAI on 2026-11-17) is listed on QCode's /models page at $2 / $10 per million tokens; see /models for cache-read and long-context rates.
- Model IDs must match exactly:
glm-5.3, notGLM-5.3. The model list may be empty in OpenAI-compatible mode, so take IDs from /models and the docs; if your code depends onmodels.list(), test it with a small request first. - Billing: official price × service multiplier, currently ×1.0 for OpenAI models. For Chinese models, use the live prices on /models.
Protocol and model matrix
| Model family | Example IDs on QCode | Chat Completions | Responses | Anthropic Messages |
|---|---|---|---|---|
| OpenAI GPT | gpt-6.2-sol, gpt-6.2-astra, gpt-6.1-sol |
Yes | Yes | No |
| Zhipu GLM | glm-5.3, glm-5.3-flash |
Yes | No | Yes |
| Moonshot Kimi | kimi-k3.1-pro, kimi-k3 |
Yes | No | Yes |
| DeepSeek | deepseek-v4-pro, deepseek-v4.1-flash |
Yes | No | Yes |
| Alibaba Qwen | qwen3.8-max, qwen3.8-flash, qwen3.7-plus |
Yes | No | Yes |
| Anthropic Claude | claude-opus-5-5, claude-sonnet-5-5 |
No | No | Yes |
Sources: docs.qcode.cc endpoints and Chinese-models pages, and qcode.cc/models, read 2026-11-25. Qwen4-Max is not on QCode /models as of 2026-11-26; check /models before you depend on it. Alibaba released Qwen4-Max on 2026-11-16 (per HPCwire). Gemini is not on QCode /models as of 2026-11-26; check /models.
Setup and a curl self-test
pip install openai # Python
npm install openai # Node.js / TypeScript
export QCODE_API_KEY="cr_your_key"
# End-to-end test: replace glm-5.3 with the ID you want
curl -sS https://api.qcode.cc/openai/v1/chat/completions \
-H "Authorization: Bearer $QCODE_API_KEY" \
-H "content-type: application/json" \
-d '{"model":"glm-5.3","messages":[{"role":"user","content":"ping"}]}'
This is the self-test from QCode's Chinese-models docs. If you test only the path with no body, a 400 is expected and means the path and key are fine. A 401 means the key is invalid. A 404 means the prefix or the model ID is wrong.
Python: one client, five vendors
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.qcode.cc/openai/v1",
api_key=os.environ["QCODE_API_KEY"], # starts with cr_
)
def ask(model: str, prompt: str) -> str:
resp = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}],
)
return resp.choices[0].message.content
for m in ["gpt-6.2-sol", "deepseek-v4.1-flash", "kimi-k3.1-pro", "glm-5.3", "qwen3.8-max"]:
print(f"{m}: {ask(m, 'Explain a race condition in one sentence.')}")
You can also use environment variables and write OpenAI() with no arguments:
export OPENAI_BASE_URL="https://api.qcode.cc/openai/v1"
export OPENAI_API_KEY="cr_your_key"
If the same machine also uses an OpenAI account directly, these variables affect every program that reads them. Prefer explicit arguments or a per-project .env file.
TypeScript: change baseURL only
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.qcode.cc/openai/v1",
apiKey: process.env.QCODE_API_KEY,
});
const models = ["gpt-6.2-sol", "deepseek-v4.1-flash", "kimi-k3.1-pro"];
for (const model of models) {
const r = await client.chat.completions.create({
model,
messages: [{ role: "user", content: "Explain a race condition in one sentence." }],
});
console.log(model, "→", r.choices[0].message.content);
}
Chat Completions or Responses?
| Aspect | Chat Completions | Responses |
|---|---|---|
| Path | /openai/v1/chat/completions |
/openai/v1/responses |
| Input | messages array (system / user / assistant / tool) |
input (string or item list) plus instructions |
| Output | choices[0].message |
output item list, with the output_text helper |
| Tools | tools: [{type: "function", function: {...}}], returns tool_calls |
tools: [{type: "function", name, parameters}], returns function_call items |
| Streaming | chat.completion.chunk, read delta.content |
Semantic events such as response.output_text.delta |
| Models on QCode | GPT and all Chinese models | GPT only |
| Typical tools | Cursor, Cline, Cherry Studio and other OpenAI-compatible clients | Codex CLI (wire_api = "responses") |
The rule of thumb: if one codebase mixes GPT and Chinese models, standardize on Chat Completions. Use Responses only for GPT-only agents where you want its item-based output. For GPT-6.2 Sol tool calling and caching on Responses, see the GPT-6.2 Sol Responses API guide.
A minimal Responses call (GPT only):
r = client.responses.create(
model="gpt-6.2-sol",
instructions="You are a senior Python reviewer. Be concise.",
input="Review: def add(a, b): return a+b",
)
print(r.output_text)
For multi-turn work, send the earlier items in input yourself instead of relying on conversation state stored on the server.
Route by task, with failover
The biggest win of one client is picking a model per task. The routing table below is only an example; test on your own tasks before you settle on one:
import os
from openai import OpenAI, APIStatusError
client = OpenAI(base_url="https://api.qcode.cc/openai/v1",
api_key=os.environ["QCODE_API_KEY"])
ROUTES = {
"plan": ["gpt-6.2-sol", "kimi-k3.1-pro"], # design, hard reasoning
"bulk": ["deepseek-v4.1-flash", "glm-5.3-flash"], # high volume, low cost
"zh_docs": ["qwen3.8-max", "glm-5.3"], # Chinese docs and comments
}
def run(task: str, prompt: str) -> tuple[str, str]:
last_err = None
for model in ROUTES[task]:
try:
r = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}],
)
return model, r.choices[0].message.content
except APIStatusError as e:
if e.status_code in (400, 401, 402):
raise # parameter, key or quota problems: switching won't help
last_err = e # 404 / 429 / 5xx: try the next model
raise last_err
model, answer = run("bulk", "Group these log lines by error type: ...")
print(model, answer)
You get three things: cost control (bulk jobs default to cheaper models), automatic failover when one model is busy, and all usage billed to one key. More patterns: multi-model routing guide.
Streaming
stream = client.chat.completions.create(
model="kimi-k3.1-pro",
messages=[{"role": "user", "content": "Write a Python HTTP client with retries."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Streaming with the Responses API (GPT):
stream = client.responses.create(model="gpt-6.2-sol", input="Write a haiku about CI.", stream=True)
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
Tool calling (function calling)
The Chat Completions tool format is shared by GPT and the Chinese models, so the same tools list works when you switch models:
import json, os
tools = [{
"type": "function",
"function": {
"name": "get_file_size",
"description": "Return the size in bytes of a file in the repository.",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string", "description": "Relative file path"}},
"required": ["path"],
},
},
}]
def chat_with_tools(model: str, question: str) -> str:
messages = [{"role": "user", "content": question}]
r = client.chat.completions.create(model=model, messages=messages, tools=tools)
msg = r.choices[0].message
if msg.tool_calls:
messages.append(msg.model_dump(exclude_none=True))
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
size = os.path.getsize(args["path"])
messages.append({"role": "tool", "tool_call_id": call.id, "content": str(size)})
r = client.chat.completions.create(model=model, messages=messages, tools=tools)
return r.choices[0].message.content
print(chat_with_tools("glm-5.3", "How big is README.md?"))
print(chat_with_tools("gpt-6.2-sol", "How big is README.md?"))
Tool calling support varies by model on QCode, so test a model with a small request before you put it in a tool chain. Always parse tool arguments with json.loads; models differ in how they escape strings, so never string-match the raw arguments.
Parameter differences between models
- Output length: models differ in which output-length parameter they expect (
max_tokens,max_completion_tokensormax_output_tokens). When mixing, pass the parameter per model family, omit it and let the server default apply, or test it with a small request first. A related case: Cline and GPT-6 max_completion_tokens. - Long-context billing: GPT models may have a higher long-context rate above a threshold; check /models for the current threshold and multipliers before you send very large requests.
- Reasoning parameters: parameter names and defaults differ by vendor, and some models count reasoning tokens as output. Check each model's documentation and do not pass vendor-specific parameters through blindly when you reuse code across models.
- Output caps: maximum output tokens differ by model; check /models before you set a large limit.
Common errors and fixes
| Symptom | Usual cause | Fix |
|---|---|---|
| 404 | The Anthropic prefix /api used as the OpenAI base_url; model ID misspelled or wrong case (GLM-5.3) |
Use https://api.qcode.cc/openai/v1; copy IDs from /models |
model_not_available_on_endpoint |
A Claude model on the OpenAI path, or a Chinese model on /responses |
Claude via the Anthropic SDK; Chinese models via Chat Completions |
| 400 parameter error | max_tokens sent to GPT; an OpenAI-only parameter sent to a Chinese model |
Pass parameters per model family |
401 Invalid API key |
Key copied wrong or with a space; OPENAI_API_KEY still holds a direct-OpenAI key |
Pass api_key explicitly; check OPENAI_API_KEY |
402 insufficient_quota |
Daily quota or pack credit used up | Plans reset at 00:00 Beijing time; packs can be stacked |
| 429 | Too much concurrency | Lower concurrency and back off |
models.list() may be empty |
Model lists may be empty in OpenAI-compatible mode | Take IDs from /models; test models.list() with a small request if your code depends on it |
One more: Codex CLI's config uses base_url = "https://api.qcode.cc/openai" without /v1. That form is specific to Codex. With the OpenAI SDK, use /openai/v1 as shown here.
What about Claude?
QCode's rule: Claude models run only on the Anthropic endpoint, GPT models only on the OpenAI endpoint, and Chinese models on either. If your project needs both GPT and Claude, the clean setup is two clients, one key: the OpenAI SDK on /openai/v1 for GPT and Chinese models, and the Anthropic SDK on /api for Claude. See the Anthropic SDK custom base_url guide. To use Chinese models inside Claude Code instead, see Claude Code with DeepSeek, GLM, Kimi and Qwen.
Log usage and cost per model
Once you mix models, cost is the thing most likely to drift: the same task on a different model can cost an order of magnitude more or less. Log the model ID and token usage of every request from day one, then convert with the prices on /models. Chat Completions usage is in resp.usage:
import json, time
def ask_logged(model: str, prompt: str) -> str:
t0 = time.time()
resp = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}],
)
u = resp.usage
print(json.dumps({
"model": resp.model,
"prompt_tokens": u.prompt_tokens,
"completion_tokens": u.completion_tokens,
"seconds": round(time.time() - t0, 2),
}))
return resp.choices[0].message.content
With that log you can answer three questions: which task type costs the most, whether quality drops noticeably on a cheaper model, and whether a model's latency is creeping up. The resp.model field is the model name the server returned, which lets you check that requests landed on the model you asked for. On the billing side, the QCode dashboard shows usage per key, so you can reconcile the two. For teams, one key per project keeps each project's spend separate from the start.
FAQ
What base_url do I use with the OpenAI SDK?
Use https://api.qcode.cc/openai/v1. The SDK appends /chat/completions or /responses. Users in Asia can switch the host to asia.qcode.cc, and users in North America or Europe to us.qcode.cc, with the same key.
Can one key call GPT plus DeepSeek, Kimi, GLM and Qwen?
Yes. One key and one OpenAI client: change the model field to switch, and all usage is billed to that key.
Can Chinese models use the Responses API?
Not on QCode. Per QCode's endpoints doc, Chinese models support OpenAI Chat Completions and Anthropic Messages, not Responses. Responses is for GPT models.
Can I call Claude through the OpenAI SDK?
No. Claude models run only on the Anthropic Messages endpoint, and the OpenAI path returns model_not_available_on_endpoint. Use the Anthropic SDK with base_url https://api.qcode.cc/api.
Why may client.models.list() return nothing?
QCode's docs note that model lists may be empty in OpenAI-compatible mode. Take model IDs from /models, matching case exactly, and test models.list() with a small request if your code depends on it.
Is qwen4-max available?
Qwen4-Max is not on QCode /models as of 2026-11-26; check /models before you depend on it. Stable Qwen IDs include qwen3.8-max, qwen3.8-flash and qwen3.7-plus.
How much does GPT-6.2 Sol cost?
Per QCode's /models page (read 2026-11-25), gpt-6.2-sol is $2 input and $10 output per million tokens; cache-read and long-context rates are on /models. That matches OpenAI's list price (multiplier ×1.0).
Is Gemini supported?
No. Gemini is not on QCode /models as of 2026-11-26; check /models.
Recommended plan
For multi-model experiments, side-by-side evaluations and short projects, pay-as-you-go packs fit best: no subscription, 7-day validity, stackable, starting at $4 (see /pay-as-you-go). Once usage is steady, pick a daily-quota subscription on /pricing. Live per-model prices are on /models.