> ## Documentation Index
> Fetch the complete documentation index at: https://runinfra.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Qwen Code

> Connect Qwen Code to RunInfra with an explicit OpenAI-compatible model selection.

Use RunInfra models in Qwen Code with an explicit OpenAI-compatible model selection.

Support level: `ready`. Connect supports automatic setup.

## Connect Qwen Code

Have Qwen Code installed, a workspace API key, and available RunInfra credits. The adapter targets Qwen Code 0.23.0 settings.

```bash theme={"dark"}
npx @runinfra/connect qwen-code
```

In an interactive terminal, Connect starts login if needed. Review and approve the proposed changes. Connect saves a snapshot, writes the provider settings and model selection, and makes a real Chat Completions request that uses credits.

To choose a model during setup:

```bash theme={"dark"}
npx @runinfra/connect qwen-code on --model deepseek-v4-flash
```

See [Connect](/docs/tools-sdks/connect) for status, diagnostics, and key replacement.

## What Connect writes

| Platform        | Configuration                       |
| --------------- | ----------------------------------- |
| macOS and Linux | `~/.qwen/settings.json`             |
| Windows         | `%USERPROFILE%\.qwen\settings.json` |

An absolute `QWEN_HOME` replaces the `.qwen` directory directly. Connect writes `settings.json` inside it and refuses a relative override.

Connect adds catalog entries to the `modelProviders.openai` array. It sets `security.auth.selectedType` to `openai`, `model.name` to the selected slug, and `model.baseUrl` to `https://api.runinfra.ai/v1`. Entries include catalog context and output limits. Unrelated provider entries and supported comments are preserved.

Existing RunInfra models absent from the current catalog remain unchanged. Review them before selecting a model.

### Key placement

By default, each managed model's `envKey` names `RUNINFRA_API_KEY`. Literal mode stores the key once under `env.RUNINFRA_API_KEY` in `settings.json`.

For an environment handoff:

```bash theme={"dark"}
npx @runinfra/connect qwen-code on --key-source helper
```

Helper mode removes owned saved assignments that can be safely removed and keeps the `envKey` reference. Set `RUNINFRA_API_KEY` securely in the environment that launches Qwen Code; Connect does not write the key to `settings.env` in helper mode. Connect does not edit dotenv files or trust settings.

If a retained provider entry still references an older credential variable, its saved assignment is kept unchanged. Review retained entries when replacing credentials.

Restart GUI apps and background services with the required environment. On Windows, set `RUNINFRA_API_KEY` in the user environment and fully restart the app. A GUI or Start menu launch does not inherit a terminal-only assignment.

A nonempty process environment takes precedence over discovered dotenv files, which take precedence over `settings.env`. Dotenv discovery walks from the current directory, preferring `.qwen/.env` over `.env` at each level, then checks home. When `security.folderTrust.enabled` is set, project dotenv candidates require a trusted workspace. Environment-name filters also apply; `RUNINFRA_API_KEY` passes the verified filters.

## Verify

Qwen Code 0.23.0 produced a verified headless response through RunInfra with `-p ... --output-format json`, using the Connect-written `settings.json`.

This manual verification template is docs-only. Connect does not execute it:

```bash theme={"dark"}
qwen --safe-mode --approval-mode plan --max-session-turns 1 --max-tool-calls 0 --max-wall-time 30s -p "Reply exactly RUNINFRA_OK. Do not use tools." --output-format json
```

The template sets a zero-tool budget. Confirm the combined flags on your installed version in an authorized isolated scratch environment. A tool-budget error or timeout is not automatically an endpoint failure. Confirm the selected model and request destination separately.

## Restart

Restart Qwen Code fully so the provider, selected model and credentials load together.

## Troubleshooting

<Warning>
  Save `settings.json` as UTF-8 without a BOM. Qwen Code 0.23.0 can copy a BOM-bearing file to `settings.json.corrupted` and overwrite `settings.json` with an empty object. Connect refuses a BOM-bearing file without changing it. Back up the file before correcting its encoding.
</Warning>

New or empty files receive numeric `$version: 4`. Without that version, Qwen can rewrite settings during startup. Connect refuses nonempty unversioned files and unsupported versions; review and migrate those settings in Qwen before connecting. Duplicate keys and trailing commas are not supported by this adapter.

When workspace `.qwen/settings.json` or system settings define `modelProviders` or `providerProtocol`, they replace the corresponding user block as a whole rather than merging entries. Preserving an entry in your user file does not guarantee it remains visible.

| Platform | System settings to review                             |
| -------- | ----------------------------------------------------- |
| macOS    | `/Library/Application Support/QwenCode/settings.json` |
| Linux    | `/etc/qwen-code/settings.json`                        |
| Windows  | `C:\ProgramData\qwen-code\settings.json`              |

Connect refuses an active `QWEN_CODE_SYSTEM_SETTINGS_PATH` override. It also refuses a conflicting launch credential or a target credential variable shared by another provider. Resolve those conflicts before reconnecting.

Runtime snapshots, startup migrations, and selection saves can rewrite files or retain secrets. Keep those copies private and verify restoration on your installed version. Restoring Connect's managed file does not restore or remove external copies.

## Revert

```bash theme={"dark"}
npx @runinfra/connect qwen-code off
```

With intact state and snapshots, `off` restores the original bytes from before the first `on` in the active connection. If the file did not exist then, Connect removes it. Later `on` calls and key rotations keep that restore point.

If Qwen or another editor changed the file, Connect refuses to overwrite it. Back up and review the edits before choosing to discard them:

```bash theme={"dark"}
npx @runinfra/connect qwen-code off --force
```

Connect saves the current contents in a recovery snapshot and prints its id before restoring the origin. Keep the snapshots. If the origin snapshot is missing, cleanup does not guarantee original-byte restoration; see [Connect recovery](/docs/tools-sdks/connect#what-off-restores).

Restore any manual environment changes separately. Connect does not restore workspace settings, system settings, or dotenv files.

## Related

<Columns cols={3}>
  <Card title="Connect" icon="plug" href="/docs/tools-sdks/connect">
    Set up, inspect, and restore your coding agent.
  </Card>

  <Card title="Chat completions" icon="braces" href="/docs/api-reference/chat-completions">
    Read the request contract.
  </Card>

  <Card title="Models" icon="list" href="/docs/api-reference/models">
    Find model ids and context windows.
  </Card>
</Columns>
