Skip to content
Sign Up Free
Coding Agent setup

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

FieldValue
API KeyBetterToken API Key, referenced by envKey
Base URLhttps://bettertoken.ai/v1 in baseUrl
ModelYOUR_MODEL_ID
Provider configurationmodelProviders.openai
API formatwireApi: "responses"

Prerequisites

Install

Use the npm option from the official quickstart:

Terminal window
npm install -g @qwen-code/qwen-code@latest
qwen --version

Manual setup

Set the API Key in your terminal, replacing YOUR_API_KEY:

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

Terminal window
qwen -p "Reply with only: OK" --output-format stream-json --max-session-turns 4

Check 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

SymptomWhat to check
Authentication failsExport the variable named by envKey in the terminal running Qwen Code.
Wrong endpointUse https://bettertoken.ai/v1 in baseUrl; wireApi selects the request protocol.
Model is not foundMake model.name match an id under modelProviders.openai.
Empty or incorrect answer after a file readThis 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.

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.