> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/QwenLM/qwen-code/llms.txt
> Use this file to discover all available pages before exploring further.

# Model Providers

> Configure AI model providers for Qwen Code

Qwen Code supports multiple AI model providers through a unified `modelProviders` configuration in `settings.json`.

## Overview

Model providers are configured by authentication type (protocol), with each type supporting multiple models:

```json theme={null}
{
  "modelProviders": {
    "openai": [ /* OpenAI-compatible models */ ],
    "anthropic": [ /* Anthropic Claude models */ ],
    "gemini": [ /* Google Gemini models */ ],
    "vertex-ai": [ /* Vertex AI models */ ]
  }
}
```

## Supported Providers

### OpenAI-Compatible

The `openai` protocol supports any OpenAI-compatible API, including:

* **Alibaba Cloud DashScope** (Qwen models)
* **OpenAI** (GPT models)
* **OpenRouter** (multiple providers)
* **ModelScope**
* **Custom OpenAI-compatible endpoints**

### Anthropic

Supports Claude models through the Anthropic API.

### Google GenAI

Supports Gemini models through the Google Generative AI API.

### Vertex AI

Supports models through Google Cloud Vertex AI.

## Model Configuration Schema

Each model configuration has the following structure:

<ParamField path="id" type="string" required>
  The model ID sent to the API (e.g., `qwen3-coder-plus`, `gpt-4o`, `claude-sonnet-4-20250514`).
</ParamField>

<ParamField path="name" type="string" required>
  Display name shown in the UI and model selector.
</ParamField>

<ParamField path="envKey" type="string" required>
  The name of the environment variable that holds your API key.

  Common values:

  * `DASHSCOPE_API_KEY` for Alibaba Cloud
  * `OPENAI_API_KEY` for OpenAI
  * `ANTHROPIC_API_KEY` for Anthropic
  * `GEMINI_API_KEY` for Google Gemini
</ParamField>

<ParamField path="baseUrl" type="string">
  The API endpoint URL. Required for non-default endpoints.

  Examples:

  * `https://dashscope.aliyuncs.com/compatible-mode/v1` (DashScope)
  * `https://api.openai.com/v1` (OpenAI)
  * `https://coding.dashscope.aliyuncs.com/v1` (Bailian Coding Plan)
</ParamField>

<ParamField path="description" type="string">
  Optional description of the model shown in the UI.
</ParamField>

<ParamField path="generationConfig" type="object">
  Model-specific generation configuration.

  <ParamField path="generationConfig.extra_body" type="object">
    Additional parameters passed to the API request body.

    Example for enabling thinking mode:

    ```json theme={null}
    {
      "extra_body": {
        "enable_thinking": true
      }
    }
    ```
  </ParamField>

  <ParamField path="generationConfig.timeout" type="number">
    Request timeout in milliseconds.
  </ParamField>

  <ParamField path="generationConfig.maxRetries" type="number">
    Maximum number of retries for failed requests.
  </ParamField>
</ParamField>

## Configuration Examples

### Qwen Models (DashScope)

<CodeGroup>
  ```json Basic Configuration theme={null}
  {
    "modelProviders": {
      "openai": [
        {
          "id": "qwen3-coder-plus",
          "name": "Qwen3 Coder Plus",
          "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
          "description": "Qwen3-Coder via Dashscope",
          "envKey": "DASHSCOPE_API_KEY"
        }
      ]
    },
    "env": {
      "DASHSCOPE_API_KEY": "sk-xxxxxxxxxxxxx"
    },
    "security": {
      "auth": {
        "selectedType": "openai"
      }
    },
    "model": {
      "name": "qwen3-coder-plus"
    }
  }
  ```

  ```json With Thinking Mode theme={null}
  {
    "modelProviders": {
      "openai": [
        {
          "id": "qwen3.5-plus",
          "name": "qwen3.5-plus (thinking)",
          "envKey": "DASHSCOPE_API_KEY",
          "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
          "generationConfig": {
            "extra_body": {
              "enable_thinking": true
            }
          }
        }
      ]
    },
    "env": {
      "DASHSCOPE_API_KEY": "sk-xxxxxxxxxxxxx"
    },
    "model": {
      "name": "qwen3.5-plus"
    }
  }
  ```
</CodeGroup>

### Alibaba Cloud Bailian Coding Plan

The Coding Plan provides fixed monthly pricing with higher quotas and access to multiple models:

```json theme={null}
{
  "modelProviders": {
    "openai": [
      {
        "id": "qwen3.5-plus",
        "name": "qwen3.5-plus (Coding Plan)",
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "description": "qwen3.5-plus with thinking enabled from Bailian Coding Plan",
        "envKey": "BAILIAN_CODING_PLAN_API_KEY",
        "generationConfig": {
          "extra_body": {
            "enable_thinking": true
          }
        }
      },
      {
        "id": "qwen3-coder-plus",
        "name": "qwen3-coder-plus (Coding Plan)",
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "envKey": "BAILIAN_CODING_PLAN_API_KEY"
      },
      {
        "id": "glm-4.7",
        "name": "glm-4.7 (Coding Plan)",
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "envKey": "BAILIAN_CODING_PLAN_API_KEY",
        "generationConfig": {
          "extra_body": {
            "enable_thinking": true
          }
        }
      },
      {
        "id": "kimi-k2.5",
        "name": "kimi-k2.5 (Coding Plan)",
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "envKey": "BAILIAN_CODING_PLAN_API_KEY",
        "generationConfig": {
          "extra_body": {
            "enable_thinking": true
          }
        }
      }
    ]
  },
  "env": {
    "BAILIAN_CODING_PLAN_API_KEY": "sk-xxxxxxxxxxxxx"
  },
  "model": {
    "name": "qwen3-coder-plus"
  }
}
```

<Note>
  Subscribe to the Coding Plan and get your API key at [Alibaba Cloud Bailian](https://modelstudio.console.aliyun.com/?tab=dashboard#/efm/coding_plan).
</Note>

### OpenAI Models

```json theme={null}
{
  "modelProviders": {
    "openai": [
      {
        "id": "gpt-4o",
        "name": "GPT-4o",
        "envKey": "OPENAI_API_KEY",
        "baseUrl": "https://api.openai.com/v1"
      },
      {
        "id": "gpt-4o-mini",
        "name": "GPT-4o Mini",
        "envKey": "OPENAI_API_KEY",
        "baseUrl": "https://api.openai.com/v1"
      }
    ]
  },
  "env": {
    "OPENAI_API_KEY": "sk-xxxxxxxxxxxxx"
  },
  "security": {
    "auth": {
      "selectedType": "openai"
    }
  },
  "model": {
    "name": "gpt-4o"
  }
}
```

### Anthropic Claude

```json theme={null}
{
  "modelProviders": {
    "anthropic": [
      {
        "id": "claude-sonnet-4-20250514",
        "name": "Claude Sonnet 4",
        "envKey": "ANTHROPIC_API_KEY"
      },
      {
        "id": "claude-opus-4-20250514",
        "name": "Claude Opus 4",
        "envKey": "ANTHROPIC_API_KEY"
      }
    ]
  },
  "env": {
    "ANTHROPIC_API_KEY": "sk-ant-xxxxxxxxxxxxx"
  },
  "security": {
    "auth": {
      "selectedType": "anthropic"
    }
  },
  "model": {
    "name": "claude-sonnet-4-20250514"
  }
}
```

### Google Gemini

```json theme={null}
{
  "modelProviders": {
    "gemini": [
      {
        "id": "gemini-2.5-pro",
        "name": "Gemini 2.5 Pro",
        "envKey": "GEMINI_API_KEY"
      },
      {
        "id": "gemini-2.5-flash",
        "name": "Gemini 2.5 Flash",
        "envKey": "GEMINI_API_KEY"
      }
    ]
  },
  "env": {
    "GEMINI_API_KEY": "AIzaxxxxxxxxxxxxx"
  },
  "security": {
    "auth": {
      "selectedType": "gemini"
    }
  },
  "model": {
    "name": "gemini-2.5-pro"
  }
}
```

### Multiple Providers

You can configure multiple providers and switch between them using the `/model` command:

```json theme={null}
{
  "modelProviders": {
    "openai": [
      {
        "id": "qwen3-coder-plus",
        "name": "Qwen3 Coder Plus",
        "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
        "envKey": "DASHSCOPE_API_KEY"
      },
      {
        "id": "gpt-4o",
        "name": "GPT-4o",
        "envKey": "OPENAI_API_KEY",
        "baseUrl": "https://api.openai.com/v1"
      }
    ],
    "anthropic": [
      {
        "id": "claude-sonnet-4-20250514",
        "name": "Claude Sonnet 4",
        "envKey": "ANTHROPIC_API_KEY"
      }
    ],
    "gemini": [
      {
        "id": "gemini-2.5-pro",
        "name": "Gemini 2.5 Pro",
        "envKey": "GEMINI_API_KEY"
      }
    ]
  },
  "env": {
    "DASHSCOPE_API_KEY": "sk-xxxxxxxxxxxxx",
    "OPENAI_API_KEY": "sk-xxxxxxxxxxxxx",
    "ANTHROPIC_API_KEY": "sk-ant-xxxxxxxxxxxxx",
    "GEMINI_API_KEY": "AIzaxxxxxxxxxxxxx"
  },
  "security": {
    "auth": {
      "selectedType": "openai"
    }
  },
  "model": {
    "name": "qwen3-coder-plus"
  }
}
```

## Switching Models

Once configured, you can switch models in several ways:

### Using the `/model` Command

In an interactive session:

```bash theme={null}
qwen
# In the session:
/model
# Choose from configured models
```

### Using the `--model` Flag

```bash theme={null}
qwen --model gpt-4o
```

### Setting Default in Settings

```json theme={null}
{
  "model": {
    "name": "qwen3-coder-plus"
  }
}
```

## Authentication Type

The `security.auth.selectedType` determines which API protocol to use:

```json theme={null}
{
  "security": {
    "auth": {
      "selectedType": "openai"  // or "anthropic", "gemini", "vertex-ai", "qwen-oauth"
    }
  }
}
```

### Available Auth Types

* `openai` - OpenAI-compatible APIs (DashScope, OpenAI, OpenRouter, etc.)
* `anthropic` - Anthropic Claude API
* `gemini` - Google Generative AI
* `vertex-ai` - Google Cloud Vertex AI
* `qwen-oauth` - Qwen OAuth (free tier, no API key needed)

## Environment Variables

API keys can be provided in three ways (in order of priority):

1. **System/Shell environment variables** (highest priority)
   ```bash theme={null}
   export DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxx
   ```

2. **`.env` files** (see [Environment Variables](/configuration/environment-variables))

3. **`settings.json` → `env` field** (lowest priority)
   ```json theme={null}
   {
     "env": {
       "DASHSCOPE_API_KEY": "sk-xxxxxxxxxxxxx"
     }
   }
   ```

<Warning>
  Never commit API keys to version control. Use `.env` files or system environment variables for sensitive credentials.
</Warning>

## Best Practices

1. **Store API keys securely**: Use `.env` files or system environment variables instead of committing them to `settings.json`.

2. **Use descriptive names**: Give your models clear, distinguishable names to make switching easier.

3. **Set a default model**: Configure `model.name` to set your preferred default.

4. **Organize by use case**: You can configure the same model multiple times with different settings (e.g., with/without thinking mode).

5. **Document custom endpoints**: Use the `description` field to note what each model configuration is for.

## Troubleshooting

### "Missing API key" Error

Ensure your API key environment variable is set:

```bash theme={null}
# Check if the variable is set
echo $DASHSCOPE_API_KEY

# Set it if needed
export DASHSCOPE_API_KEY=sk-xxxxxxxxxxxxx
```

### Model Not Available

Verify:

1. The model `id` matches what the provider expects
2. The `baseUrl` is correct for your provider
3. The `envKey` matches your environment variable name
4. The `security.auth.selectedType` matches the provider protocol

### Rate Limiting

Configure retry and timeout settings:

```json theme={null}
{
  "model": {
    "generationConfig": {
      "timeout": 120000,
      "maxRetries": 3
    }
  }
}
```

## See Also

* [Settings.json Reference](/configuration/settings)
* [Environment Variables](/configuration/environment-variables)
* [Authentication Guide](https://qwenlm.github.io/qwen-code-docs/en/users/configuration/auth/)
