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.
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
- Check current service status and site-key availability.
- Open Qwen Code's
/authcommand and choose Custom Provider → OpenAI-compatible → Chat Completions, or add the settings below to your user-level~/.qwen/settings.json. - Keep the key in
~/.qwen/.envasCHINAGENAI_API_KEY=YOUR_SITE_KEY. Do not commit that file or paste the key into shared settings. - Run Qwen Code and open
/model. Selectfree. If you already have a session open, reopen/modelafter editing settings.
| Qwen Code setting | Value |
|---|---|
| Provider protocol | openai (OpenAI-compatible) |
| API format | chat-completions |
| Base URL | https://chinagenai.com/v1 |
| Model ID | free |
| Key environment variable | CHINAGENAI_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:
{
"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: confirmmodelProviders.openaiis an array, the entry usesid: "free", andmodel.namematches it. Reopen/model. - 401: confirm
~/.qwen/.envcontains the exact variable named byenvKey, then check that the site key is unexpired. - 404: confirm the base URL ends at
/v1andwireApiischat-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 pickerUse 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.
Without a matching providerProtocol entry, a custom provider id is skipped