Connect Qwen Code to a Chat Completions endpoint.

Configure the Qwen Code CLI with the site Chat Completions endpoint, current provider-array shape and a key loaded from the environment.

Connect Qwen Code to ChinaGenAI through its OpenAI-compatible Chat Completions provider. The example uses the site's free model label; the upstream model is selected by the shared route and is not guaranteed to be Qwen.

Use this for a short connection check, not an unverified coding-agent workflow

ChinaGenAI allows up to 6 messages and 6,000 serialized input characters and caps each answer at 256 tokens. Qwen Code tool-loop compatibility with the current upstream route has not been verified. Tool schemas and conversation history can reach the input cap quickly.

Set the connection in Qwen Code

  1. Check current service status and site-key availability.
  2. Open Qwen Code's /auth command and choose Custom Provider → OpenAI-compatible → Chat Completions, or add the settings below to your user-level ~/.qwen/settings.json.
  3. Keep the key in ~/.qwen/.env as CHINAGENAI_API_KEY=YOUR_SITE_KEY. Do not commit that file or paste the key into shared settings.
  4. Run Qwen Code and open /model. Select free. If you already have a session open, reopen /model after editing settings.
Qwen Code settingValue
Provider protocolopenai (OpenAI-compatible)
API formatchat-completions
Base URLhttps://chinagenai.com/v1
Model IDfree
Key environment variableCHINAGENAI_API_KEY

Use the API root ending in /v1. Qwen Code appends the Chat Completions path. Do not enter /chat/completions as the base URL or select the Responses API; ChinaGenAI exposes Chat Completions only.

Use the current settings shape

Qwen Code expects each modelProviders entry to be an array of model definitions. This example references the key through envKey instead of putting its value in the JSON file:

Qwen Code settings.json
{
  "modelProviders": {
    "openai": [
      {
        "id": "free",
        "name": "ChinaGenAI",
        "envKey": "CHINAGENAI_API_KEY",
        "baseUrl": "https://chinagenai.com/v1",
        "wireApi": "chat-completions"
      }
    ]
  },
  "security": {
    "auth": {
      "selectedType": "openai"
    }
  },
  "model": {
    "name": "free"
  }
}

Some older preview configs wrapped provider models in an object containing protocol and models. Current Qwen Code documentation says that wrapped shape can be silently skipped in migrated settings. Keep openai as the built-in protocol key; a custom provider ID requires a separate providerProtocol mapping.

Check what the model picker proves

Qwen Code's /model list confirms that the local provider configuration was discovered. GET https://chinagenai.com/v1/models checks model discovery at the endpoint. Neither check sends a chat request or proves that a key is valid for inference. The endpoint requires a ChinaGenAI site key for POST https://chinagenai.com/v1/chat/completions.

No Qwen Code session or model request was run for this guide. Use the local request builder to prepare a short Chat Completions body without sending it.

Check whether the shared limits fit

  • Output: the 256-token cap can stop longer explanations or code before they are complete.
  • Input: up to 6 messages and 6,000 serialized characters, including tool schemas.
  • Shared allowance: 20 attempts per network or verified account per UTC day, one active request per key, two across the site, and 48-hour keys. Failed attempts count.
  • Delivery: streaming uses buffered SSE after the upstream response completes, not token-by-token delivery.
  • Agent tools: the gateway forwards standard Chat Completions tool fields when present, but support in the automatically selected upstream model and Qwen Code's full tool loop is not verified.

For regular coding tasks, choose a route whose context, output and tool behavior you have verified for that workload. See the complete endpoint limits before connecting.

If the model does not appear or a request fails

  • Missing from /model: confirm modelProviders.openai is an array, the entry uses id: "free", and model.name matches it. Reopen /model.
  • 401: confirm ~/.qwen/.env contains the exact variable named by envKey, then check that the site key is unexpired.
  • 404: confirm the base URL ends at /v1 and wireApi is chat-completions.
  • 429: a shared daily or concurrency limit may have been reached. Waiting for the relevant window is required; replacing the key does not reset allowance.
  • Short answer: inspect finish_reason; the 256-token cap can end generation early.

For Qwen provider features rather than the Qwen Code CLI, see Qwen API access routes and Qwen thinking and tool-choice behavior.

Official references

Qwen Code: Model Providers
Qwen Code: Authentication

Official Qwen Code documentation checked 27 October 2026. Written setup guidance only; no client, key or model request was tested.

Free API access and limits

Check the site free API access and limits before trying to obtain a site key. Read the current status and request limits before using a site key. It is not a source of official provider keys.

ChinaGenAI is not affiliated with the providers named here. This release contains setup guidance and explicitly labeled fictional examples, not claimed live model benchmarks.

Exact symptom wording and source

Use the quoted text to locate the relevant check. Providers and clients can phrase the same failure differently; compare the complete response before applying a fix.

  • Reported text: Qwen Code custom provider missing from /model picker

    Use the built-in openai provider key for an OpenAI-compatible endpoint, or add a providerProtocol mapping for a custom provider ID. The same guide explains the current array shape and older wrapped config migration issue.

    Open this check

    Without a matching providerProtocol entry, a custom provider id is skipped

    Qwen Code Model Providers, checked 27 October 2026