Qwen Code logo
Coding agents

Use TokenRex with Qwen Code

Add a named OpenAI-compatible model provider to Qwen Code.

Setup checked against the linked official documentation. No live TokenRex session inside this tool has been verified. Use a compatible chat model and its real limits; configuration support does not establish support for every model or feature.

Before you start

  • A current Qwen Code installation
  • A private TokenRex API key
  • An enabled streaming, tool-capable chat model

Setup methods

01

Install Qwen Code

  1. 1

    Install Node.js 22 or newer for the npm method. Open Terminal or PowerShell and run the official command below.

  2. 2

    Open a project folder you are authorized to use, then run qwen. Use /auth for interactive authentication; the old qwen auth command has been removed.

Terminal commands
npm install -g @qwen-code/qwen-code@latest
qwen

Setup reference
02

Add TokenRex as a named provider

  1. 1

    Create a private TokenRex API key and copy an enabled chat model ID from Models & Pricing. The example model is replaceable; image, video, speech and embedding endpoints are not coding-agent chat models.

  2. 2

    Set TOKENREX_API_KEY privately in the environment used to launch Qwen. Do not paste the key into shared settings or screenshots.

  3. 3

    Open ~/.qwen/settings.json and merge the providerProtocol and modelProviders entries below without deleting existing settings. Each provider's models are an array.

  4. 4

    Run qwen, use /model and select the TokenRex model. The envKey field reads your private environment variable, not a literal API key.

  5. 5

    Start a new conversation with the selected model, send a short read-only question and check its response and TokenRex usage. Test streaming and tool calls separately before approving file edits or terminal actions. These checks can incur normal model charges.

Configuration
{
  "providerProtocol": {
    "tokenrex": "openai"
  },
  "modelProviders": {
    "tokenrex": [
      {
        "id": "gpt-6-astra",
        "name": "TokenRex",
        "baseUrl": "https://tokenrex.ai/api/public/v1",
        "envKey": "TOKENREX_API_KEY"
      }
    ]
  }
}

Setup reference

Troubleshooting

Qwen uses subscription authentication instead
Use /auth and /model to check the active protocol and provider. Confirm the launch environment contains the credential named by envKey; do not print its value.
Authentication fails
Check that the saved TokenRex key is active and belongs in the tool's API-key field, not its subscription sign-in. Remove accidental spaces, check your wallet balance, and never share the key in screenshots or exported settings.
The model is missing or the request URL returns 404
Copy an exact enabled model ID from Models & Pricing. Follow this method's URL field: some tools expect the versioned base, others the root or full completion address. Check the documented API protocol before changing the path.
Chat works but streaming or tools fail
Test a short plain-text conversation first. Confirm the selected model and installed tool version support the required protocol and capabilities. Enable agent actions only after separately checking streaming and tool calls.

Further references

Verify the connection

Send a short message with the selected model, read its response, then confirm the exact model appears in your TokenRex usage. Test streaming and tool use separately before larger agent tasks.