Qwen Code
Connect Qwen Code to RealRelay.ai as an OpenAI-compatible provider: install it, add a model entry to ~/.qwen/settings.json, check the connection and switch models.
- Protocol
- OpenAI Chat Completions · OpenAI Responses
- Base URL
https://www.realrelay.ai/v1- Official docs
- qwenlm.github.io
- Checked against the tool’s docs
- 2026-10
Overview
Qwen Code is a coding agent for the terminal from the Qwen team. It reads your project, edits files and runs commands. It can talk to any OpenAI-compatible service, so it connects to RealRelay.ai's Chat Completions endpoint, /v1/chat/completions.
An API key from the API keys page of the console.
The base URL with
/v1at the end. Qwen Code appends/chat/completionsto it.A model ID exactly as
GET /v1/modelslists it, for examplez-ai/glm-5.2. The model needs tool calling.
Qwen Code's /auth menu offers QwenCloud, Alibaba ModelStudio and a list of third-party services. RealRelay.ai is not one of them; use the settings file below instead.
Install
The npm package needs Node.js 22 or later. Qwen Code's README also lists Homebrew and its own standalone installer.
npm install -g @qwen-code/qwen-code@latestqwen --versionbrew install qwen-codecurl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.sh | bashirm https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.ps1 | iexIf qwen --version prints a version number, the install worked. After the standalone installer, open a new terminal first.
Configure
- 1
Save your key in an environment variable
The settings file reads the key from
REALRELAY_API_KEY, so the file itself holds no secret. Set it in your shell, or put it in~/.qwen/.env, which Qwen Code loads on start.~/.zshrc · ~/.bashrc export REALRELAY_API_KEY="sk-***"Windows PowerShell [Environment]::SetEnvironmentVariable("REALRELAY_API_KEY", "sk-***", "User")Close and reopen the terminal so it sees the new variable.
~/.qwen/.env REALRELAY_API_KEY=sk-*** - 2
Add the model to settings.json
Create the file if it does not exist. On Windows it is
%USERPROFILE%.qwen\settings.json. Qwen Code recommends keeping providers in this user file rather than a project's.qwen/settings.json.~/.qwen/settings.json 1{2 "modelProviders": {3 "openai": [4 {5 "id": "z-ai/glm-5.2",6 "name": "z-ai/glm-5.2 (RealRelay.ai)",7 "baseUrl": "https://www.realrelay.ai/v1",8 "envKey": "REALRELAY_API_KEY",9 "generationConfig": {10 "contextWindowSize": 20000011 }12 }13 ]14 },15 "security": {16 "auth": {17 "selectedType": "openai"18 }19 },20 "model": {21 "name": "z-ai/glm-5.2"22 }23}
openaiundermodelProvidersis the protocol, not a vendor. Every entry in that list is sent as an OpenAI-style request. Do not rename it: Qwen Code skips provider names it does not know.idis the model ID sent to RealRelay.ai.envKeynames the variable that holds the key.contextWindowSizetells Qwen Code how large the model's window is. Without it, Qwen Code guesses from the model name, and RealRelay.ai's model list does not include the number.selectedTypeandmodel.namelet Qwen Code start with this model without asking you to run/auth.model.namemust match anidabove.
For a quick test without a settings file, the three standard OpenAI variables are enough. They also apply to other tools that read OPENAI_API_KEY, so prefer the settings file for everyday use.
1export OPENAI_API_KEY="sk-***"2export OPENAI_BASE_URL="https://www.realrelay.ai/v1"3export OPENAI_MODEL="z-ai/glm-5.2"4qwenVerify
- 1
Call the endpoint directly
Run this with your key. A JSON reply with a
choicesarray means the address, key and model work.Terminal 1curl -sS "https://www.realrelay.ai/v1/chat/completions" \2 -H "Authorization: Bearer sk-***" \3 -H "content-type: application/json" \4 -d '{"model": "z-ai/glm-5.2", "max_tokens": 16, "messages": [{"role": "user", "content": "Reply with OK"}]}' - 2
Send one prompt from the terminal
This runs Qwen Code without the interactive screen and prints the reply.
Terminal qwen -p "Reply with OK" - 3
Check the session
Start
qwenin a project and run/doctor. It shows the authentication type and environment checks. Send a short message; the request appears in the console's usage logs.Qwen Code cd /path/to/your/projectqwen/doctor
Models
Each model you want to use is one entry in the openai list. Add an entry per model, then switch with /model in a session. Your choice is kept for the next session.
1{2 "id": "z-ai/glm-5.2",3 "name": "z-ai/glm-5.2 (RealRelay.ai)",4 "baseUrl": "https://www.realrelay.ai/v1",5 "envKey": "REALRELAY_API_KEY",6 "generationConfig": { "contextWindowSize": 200000 }7},8{9 "id": "<another-model-id>",10 "name": "<another-model-id> (RealRelay.ai)",11 "baseUrl": "https://www.realrelay.ai/v1",12 "envKey": "REALRELAY_API_KEY",13 "generationConfig": { "contextWindowSize": 128000 }14}To pick a model for one run only, pass it on the command line:
qwen --model "z-ai/glm-5.2"The window sizes in these examples are safe starting values. Set contextWindowSize to the real limit from the model's catalog page. To cap output length, set the QWEN_CODE_MAX_OUTPUT_TOKENS environment variable.
A few OpenAI models are served on the Responses endpoint, /v1/responses. Add wireApi to their entry so Qwen Code sends them there:
1{2 "id": "openai/gpt-5.3-codex",3 "name": "openai/gpt-5.3-codex (RealRelay.ai, Responses)",4 "wireApi": "responses",5 "baseUrl": "https://www.realrelay.ai/v1",6 "envKey": "REALRELAY_API_KEY",7 "generationConfig": { "contextWindowSize": 400000 }8}Which models suit an agent, and which ones the Responses endpoint serves, is under Choosing a model.
Troubleshooting
Qwen Code opens the
/authmenu on start. It did not find a usable setup. Check thatselectedTypeisopenaiand thatmodel.namematches anidin the list.The model is missing from
/model. The provider key undermodelProvidersis notopenai, or the JSON has a syntax error.401. The key is not reaching RealRelay.ai. A key exported in the shell wins over
.envfiles, which win over theenvblock ofsettings.json; an old value in a higher place hides the new one.404. The base URL is missing
/v1, or it already ends in/chat/completions. Use the address ending in/v1.Model not found.
idmust match the ID fromGET /v1/modelsexactly, including the part before the slash.Context errors in long sessions.
contextWindowSizeis missing or larger than the model's real window. Set it from the catalog page.Errors on a model with
wireApi: "responses". Only the models listed under Choosing a model are served on/v1/responses. RemovewireApifor other models.
