Coding agents

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 /v1 at the end. Qwen Code appends /chat/completions to it.

  • A model ID exactly as GET /v1/models lists it, for example z-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 (Node.js 22+)
npm install -g @qwen-code/qwen-code@latestqwen --version
Homebrew (macOS · Linux)
brew install qwen-code
macOS · Linux
curl -fsSL https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.sh | bash
Windows PowerShell
irm https://qwen-code-assets.oss-cn-hangzhou.aliyuncs.com/installation/install-qwen-standalone.ps1 | iex

If qwen --version prints a version number, the install worked. After the standalone installer, open a new terminal first.

Configure

  1. 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. 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}
  • openai under modelProviders is 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.

  • id is the model ID sent to RealRelay.ai. envKey names the variable that holds the key.

  • contextWindowSize tells 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.

  • selectedType and model.name let Qwen Code start with this model without asking you to run /auth. model.name must match an id above.

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.

Terminal
1export OPENAI_API_KEY="sk-***"2export OPENAI_BASE_URL="https://www.realrelay.ai/v1"3export OPENAI_MODEL="z-ai/glm-5.2"4qwen

Verify

  1. 1

    Call the endpoint directly

    Run this with your key. A JSON reply with a choices array 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. 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. 3

    Check the session

    Start qwen in 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.

~/.qwen/settings.json → modelProviders.openai
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:

Terminal
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:

~/.qwen/settings.json → modelProviders.openai
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 /auth menu on start. It did not find a usable setup. Check that selectedType is openai and that model.name matches an id in the list.

  • The model is missing from /model. The provider key under modelProviders is not openai, or the JSON has a syntax error.

  • 401. The key is not reaching RealRelay.ai. A key exported in the shell wins over .env files, which win over the env block of settings.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. id must match the ID from GET /v1/models exactly, including the part before the slash.

  • Context errors in long sessions. contextWindowSize is 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. Remove wireApi for other models.