Skip to content
Docs

Qwen Code with AI Gateway

Qwen Code is Alibaba's terminal coding agent, a fork of Gemini CLI adapted for Qwen models. Its modelProviders.openai entries support environment-variable keys, which you can point at AI Gateway for unified model access and spend monitoring.

Run the Vercel CLI setup command for Qwen Code:

terminal
npx vercel ai-gateway setup --agent qwen

The command writes modelProviders.openai entries in ~/.qwen/settings.json, each with an envKey reference to AI_GATEWAY_API_KEY so the key never lands in the file. The entries list the newest Qwen models first, followed by the gateway's most-used models. Re-run the command to refresh the list.

If you can't use the Vercel CLI, configure Qwen Code manually:

  1. Go to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a new API key.

  2. Export the key in your shell:

    Terminal
    export AI_GATEWAY_API_KEY="your-ai-gateway-api-key"

    To persist the key, add the same line to your shell's startup file.

  3. Add the gateway entries to ~/.qwen/settings.json:

    ~/.qwen/settings.json
    {
      "modelProviders": {
        "openai": [
          {
            "id": "openai/gpt-6-astra",
            "name": "openai/gpt-6-astra",
            "baseUrl": "https://ai-gateway.vercel.sh/coding-agent/v1",
            "envKey": "AI_GATEWAY_API_KEY"
          },
          {
            "id": "anthropic/claude-sonnet-5",
            "name": "anthropic/claude-sonnet-5",
            "baseUrl": "https://ai-gateway.vercel.sh/coding-agent/v1",
            "envKey": "AI_GATEWAY_API_KEY"
          }
        ]
      },
      "security": {
        "auth": {
          "selectedType": "openai"
        }
      },
      "model": {
        "name": "openai/gpt-6-astra"
      }
    }

    The openai array defines the whole model universe. model.name resolves against it, so add one entry per gateway model you want available. envKey names the environment variable holding your key. Setting security.auth.selectedType to "openai" switches Qwen Code off its default Qwen OAuth login.

  4. Open a new terminal so the key is loaded, then run:

    Terminal
    qwen

    Switch models in-session.

View your usage, spend, and request activity in the AI Gateway section in the Vercel dashboard sidebar. See the observability documentation for more details.

VariableDescription
AI_GATEWAY_API_KEYYour AI Gateway API key, named by envKey. Required

Qwen Code calls AI Gateway through the OpenAI-compatible Chat Completions API, so any model that supports Chat Completions works.

Last updated September 13, 2026

Was this helpful?

supported.