Qwen Code Integration with CodeGateway: OpenAI-Compatible Provider Setup

(Unofficial)

This guide is independently community-maintained. It is not affiliated with, endorsed by, or sponsored by the vendor of the third-party tool it covers. All third-party trademarks are the property of their respective owners.

One settings.json entry connects Qwen Code to CodeGateway with DeepSeek/Kimi/GLM models, pay as you go.

Prerequisites

  • Register at codegateway.dev — trial credit included after you bind a card (current amount shown on the signup/pricing page).

  • Create an API key in Dashboard → API Keys (starts with sk-cg-).

  • This guide only touches Qwen Code's user-level config; no project files are modified.

Step 1: Install Qwen Code

bash
npm install -g @qwen-code/qwen-code

Run qwen --version to confirm the install (this guide was verified against 0.21.x).

Step 2: Register CodeGateway as a model provider

Qwen Code's user-level config file is ~/.qwen/settings.json. Merge the following into it (keep other fields if the file exists):

json
{
"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:

bash
CG_KEY=sk-cg-your-key

To register more models, append entries to the modelProviders.openai array:

json
{
"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.

Step 3: Verify the call

First check the gateway link:

bash
curl https://api.codegateway.dev/v1/models \
-H "Authorization: Bearer sk-cg-your-key"

Then run Qwen Code headlessly:

bash
qwen -p "Reply with only: hello" --model deepseek-v4-pro

A 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).

FAQ

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.

References

Turn this doc into a real API call

Lacking an official key or facing overseas card payment issues? Create an sk-cg- key after signing up, point your base URL at CodeGateway, and keep your existing SDK or CLI unchanged. Pay per token; binding a card adds free credit.

Sign up free
Author:CodeGateway Team