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:
npx vercel ai-gateway setup --agent qwenThe 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:
Go to the AI Gateway section in the Vercel dashboard sidebar and click API keys to create a new API key.
Export the key in your shell:
Terminalexport AI_GATEWAY_API_KEY="your-ai-gateway-api-key"To persist the key, add the same line to your shell's startup file.
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
openaiarray defines the whole model universe.model.nameresolves against it, so add one entry per gateway model you want available.envKeynames the environment variable holding your key. Settingsecurity.auth.selectedTypeto"openai"switches Qwen Code off its default Qwen OAuth login.Open a new terminal so the key is loaded, then run:
TerminalqwenSwitch 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.
| Variable | Description |
|---|---|
AI_GATEWAY_API_KEY | Your AI Gateway API key, named by envKey. Required |
- Browse the models catalog for available models
- Configure spend limits on your API key
- Read the Qwen Code documentation for commands and configuration
Was this helpful?