Skip to main content
This guide provides instructions for integrating Qwen Code CLI with the TrueFoundry AI Gateway.

Quick setup

With Qwen Code installed, install the setup tool, then run:
Select Qwen Code and any other agents you want to configure. To set up only Qwen Code, run:
Sign in to your organization, choose models and any MCP servers or Skills you need, then review and approve the changes. Follow the completion summary for any remaining steps. See Set Up Your IDEs for the full walkthrough. For manual configuration, follow the instructions below.

Prerequisites

Before integrating Qwen Code with TrueFoundry, ensure you have:
  1. TrueFoundry Account: Create a TrueFoundry account with at least one model provider configured and generate a Personal Access Token by following the instructions in Generating Tokens. For a quick setup guide, see our Gateway Quick Start
  2. Qwen Code installed.

Setup Process

1. Get Configuration Details

Get the base URL and model name from your TrueFoundry AI Gateway playground using the unified code snippet:
TrueFoundry playground showing unified code snippet with base URL and model name highlighted for Qwen Code CLI integration

Get Base URL and Model Name from Unified Code Snippet

2. Configure Qwen Code

Qwen Code uses a settings.json file for configuration. Edit (or create) the file at ~/.qwen/settings.json to route requests through TrueFoundry:
Replace the placeholders:
  • {GATEWAY_BASE_URL} → Your TrueFoundry AI Gateway Base URL
  • your-truefoundry-api-key → Your TrueFoundry Personal Access Token
  • openai-main/gpt-4o → Your desired model in provider-name/model-name format
The id and model.name fields should use the fully qualified model name from TrueFoundry (e.g., openai-main/gpt-4o, anthropic/claude-4-sonnet). You can find the exact model name in the TrueFoundry AI Gateway playground.

3. Configure Multiple Models (Optional)

You can configure multiple models from different providers to switch between them during a session:
Use the /model command inside Qwen Code to switch between all configured models during a session.

Usage Examples

Interactive Mode

Launch the interactive terminal UI in your project directory:
Once inside the session, you can ask questions about your codebase, generate code, and run commands using natural language.

Headless Mode

Use the -p flag to run Qwen Code without the interactive UI — ideal for scripts, automation, and CI/CD:
Qwen Code CLI terminal output showing a prompt to generate a Flask HTTP server and the resulting code

Qwen Code CLI headless mode output showing a generated Flask server

Common Prompts

Observability

All requests routed through TrueFoundry AI Gateway are automatically logged and available for monitoring. You can view request traces, latencies, token usage, and full request/response details in the TrueFoundry dashboard.
TrueFoundry observability dashboard showing traced requests from Qwen Code CLI with model details, latencies, and response content

TrueFoundry trace view showing Qwen Code CLI requests routed through the AI Gateway

This gives you full visibility into:
  • Request traces: See every request made by Qwen Code, including the model used and response times
  • Token usage: Track input and output token consumption across sessions
  • Cost monitoring: Monitor spend across different models and providers
  • Governance: Enforce policies, rate limits, and access controls on all AI requests

Fleet-wide enforcement

Gateway config: per user. Qwen Code has a system settings file, /etc/qwen-code/settings.json (Linux), C:\ProgramData\qwen-code\settings.json (Windows), or /Library/Application Support/QwenCode/settings.json (macOS), that overrides user and project settings and can set modelProviders and security.auth.enforcedType. But OPENAI_BASE_URL / OPENAI_API_KEY environment variables and CLI flags rank above it, so the base URL can’t be hard-locked; push the values through MDM and use network policy. See Qwen Code’s settings doc. MCP servers: enforceable. Remote servers are mcpServers.<name> with httpUrl (Streamable HTTP) or url (SSE), headers, or an oauth block; point them at the MCP Gateway. In the system settings file, mcpServers defined there can’t be overridden by users, and mcp.allowed / mcp.excluded allowlist or block servers by name (mcp.excluded wins). Matching is by name string, so it’s policy rather than a hard boundary. See Qwen Code’s MCP doc.