Prerequisites
Register at codegateway.dev — $2 trial credit included.
Create an API key in Dashboard → API Keys (starts with sk-cg-).
Loading…
One settings.json entry connects Qwen Code to CodeGateway with DeepSeek/Kimi/GLM models, pay as you go.
Register at codegateway.dev — $2 trial credit included.
Create an API key in Dashboard → API Keys (starts with sk-cg-).
npm install -g @qwen-code/qwen-codeRun qwen --version to confirm the install (this guide was verified against 0.21.x).
Qwen Code's user-level config file is ~/.qwen/settings.json. Merge the following into it (keep other fields if the file exists):
{
"modelProviders": {
"openai": [
{
"id": "deepseek-v4-pro",
"name": "DeepSeek V4 Pro via CodeGateway",
"envKey": "CG_KEY",
"baseUrl": "https://api.codegateway.dev/v1"
}
]
}
}Field notes:
id: model id, must match CodeGateway's model list exactly.
baseUrl: CodeGateway's OpenAI-compatible base URL, always https://api.codegateway.dev/v1.
envKey: the environment variable that holds your key (recommended); if omitted, OPENAI_API_KEY is used.
Then add the key to ~/.qwen/.env:
CG_KEY=sk-cg-your-keyTo register more models, append entries to the modelProviders.openai array:
{
"id": "kimi-k2.7-code",
"name": "Kimi K2.7 Code via CodeGateway",
"envKey": "CG_KEY",
"baseUrl": "https://api.codegateway.dev/v1"
}openai is a built-in provider key, so no providerProtocol entry is needed.
First check the gateway link:
curl https://api.codegateway.dev/v1/models \
-H "Authorization: Bearer sk-cg-your-key"Then run Qwen Code headlessly:
qwen -p "Reply with only: hello" --model deepseek-v4-proA reply means it works. After that, run qwen in your project to enter interactive mode and switch models with /model.
Under the OpenAI-compatible protocol these models are verified working:
deepseek-v4-pro: main workhorse for coding, best value.
kimi-k2.7-code: strong on long coding tasks.
glm-5.3: balanced all-rounder.
qwen3.8-27b: light reasoning option.
Note: GPT-series models (gpt-5.3-codex, gpt-5.5, etc.) are subject to upstream regional restrictions — calls from some countries/regions return a 400. Claude- and Gemini-series models are not available on the OpenAI-compatible protocol (they run on the Anthropic Messages surface; see Claude Code setup).
Q: "Model not found" after configuring? Check that id matches the model list exactly (case-sensitive) and that baseUrl ends with /v1.
Q: 401 Unauthorized? Check the key in ~/.qwen/.env — complete, with the sk-cg- prefix — and that envKey matches the env var name.
Q: How do I switch back to Qwen's official models? Remove the modelProviders field from ~/.qwen/settings.json (or restore your backup).
Q: Does Qwen Code read project-level settings? Yes — a project-level settings.json overrides the user-level ~/.qwen/settings.json.
Q: Why is Gemini/Claude not in the recommended list? Gemini- and Claude-series models run on the Anthropic Messages protocol only; Qwen Code speaks OpenAI-compatible, so it must use OpenAI-compatible models (DeepSeek/Kimi/GLM/Qwen, etc.). To use Gemini models, see the alternatives in Gemini CLI compatibility note.