Qwen Code setup: API key, Base URL, and models
Configure Qwen Code with a BetterToken API Key, Base URL, and Responses model settings. Review the tested limitations for file-reading tasks.
Connect Qwen Code to BetterToken through modelProviders.openai in ~/.qwen/settings.json. In macOS testing with a GPT model, Qwen Code 0.26.0 completed text requests with both Responses and Chat Completions.
Key settings
| Field | Value |
|---|---|
| API Key | BetterToken API Key, referenced by envKey |
| Base URL | https://bettertoken.ai/v1 in baseUrl |
| Model | YOUR_MODEL_ID |
| Provider configuration | modelProviders.openai |
| API format | wireApi: "responses" |
Prerequisites
- Node.js 22 or later for the npm installation below
- A BetterToken API Key: register and get one
- A Model ID copied from the model plaza
Install
Use the npm option from the official quickstart:
npm install -g @qwen-code/qwen-code@latestqwen --versionManual setup
Set the API Key in your terminal, replacing YOUR_API_KEY:
export BETTERTOKEN_API_KEY="YOUR_API_KEY"Merge these settings into ~/.qwen/settings.json. Replace both YOUR_MODEL_ID values with the same exact Model ID:
{ "modelProviders": { "openai": [ { "id": "YOUR_MODEL_ID", "envKey": "BETTERTOKEN_API_KEY", "baseUrl": "https://bettertoken.ai/v1", "wireApi": "responses" } ] }, "security": { "auth": { "selectedType": "openai" } }, "model": { "name": "YOUR_MODEL_ID" }}envKey names an environment variable; it does not contain the API Key itself. The official model provider reference also supports wireApi: "chat-completions". Responses had more successful file-reading attempts in this test, but neither format passed every attempt.
Verify the connection
Run this text-only check in the same terminal:
qwen -p "Reply with only: OK" --output-format stream-json --max-session-turns 4Check the final answer for OK. A successful text request does not establish that a file-reading task will produce a correct final answer; use the limitation above when choosing your workflow.
Switch models
Add a model entry under modelProviders.openai, set model.name to its exact id, and start a new session.
Common errors
| Symptom | What to check |
|---|---|
| Authentication fails | Export the variable named by envKey in the terminal running Qwen Code. |
| Wrong endpoint | Use https://bettertoken.ai/v1 in baseUrl; wireApi selects the request protocol. |
| Model is not found | Make model.name match an id under modelProviders.openai. |
| Empty or incorrect answer after a file read | This occurred even with correct tool results in 0.26.0. Switching to Responses did not eliminate the failures; use another tested client for file-reading tasks. |
Related
Technical details
wireApi: "responses" selects /v1/responses; wireApi: "chat-completions" selects /v1/chat/completions. Both text paths passed in Qwen Code 0.26.0 testing. File-reading outcomes were 2/3 and 0/3 respectively.

