# Alibaba Cloud Model Studio (Qwen)

Add Alibaba Cloud Model Studio as a provider in your key's region, call Qwen models such as qwen3.8-max and set their thinking budget.

Connect Alibaba Cloud Model Studio's OpenAI-compatible API using your API key to serve Qwen models (such as `qwen3.8-max`) in regions outside the Chinese mainland. Adding a provider requires Owner or LLM Gateway Admin on the organization, or on a project for a project-scoped provider.

## Add Alibaba Cloud Model Studio [#add-alibaba-cloud-model-studio]

1. Create an API key in [Model Studio's console](https://modelstudio.console.alibabacloud.com/ap-southeast-1/settings/api-key). Each key works only in its own region.
2. In your organization, click **LLM Gateway**, then **Providers**, then **Add a provider**, then **Alibaba Cloud Model Studio** under **Model providers**.
3. For a key from outside Singapore, enter its region's **Base URL (optional)**, from the table below.
4. Paste the key into **API key**, select which projects can create models with this provider, click **Test** and click **Add provider**.

See [Add a provider](/guides/llm-gateway/add-a-provider) for adding a project provider, sharing and key rotation.

| Region            | Base URL                                                               |
| ----------------- | ---------------------------------------------------------------------- |
| Singapore         | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`, the default  |
| US (Virginia)     | `https://dashscope-us.aliyuncs.com/compatible-mode/v1`                 |
| China (Hong Kong) | `https://cn-hongkong.dashscope.aliyuncs.com/compatible-mode/v1`        |
| Custom workspace  | `https://{workspace-id}.{region}.maas.aliyuncs.com/compatible-mode/v1` |

kosem rejects Model Studio's Chinese mainland regions, such as Beijing, because their list prices differ from the international pricing kosem uses for usage tracking.

## What kosem uses [#what-kosem-uses]

- **API:** Model Studio's Chat Completions, at the base URL. kosem translates calls with Anthropic's Messages or OpenAI's Responses to it.
- **Type, for the API:** `providerTypes/alibaba`, with the base URL as `base_url` in `config`, such as `{"base_url": "https://dashscope-us.aliyuncs.com/compatible-mode/v1"}`.
- **Models to start with:** `qwen3.8-max` and `qwen3.8-flash`. The provider list omits image, video, speech, embedding, ranking and translation models.
- **Prices:** Model Studio's international list prices, for usage and spend limits.

## Reasoning and tool calls [#reasoning-and-tool-calls]

Recent Qwen models return their reasoning in `reasoning_content`, which kosem passes back to each model in agents and translated calls. In direct Chat Completions calls, preserve each full assistant message.

`enable_thinking` turns reasoning on or off. Qwen3.8 models accept either `reasoning_effort` (`low`, `medium` or `xhigh`) or a `thinking_budget` in tokens, not both. kosem forwards these fields as sent; with OpenAI's SDK, pass `enable_thinking` and `thinking_budget` in `extra_body`:

```python
import os

from openai import OpenAI

client = OpenAI(
    base_url=f"https://api.kosem.ai/v1/projects/{os.environ['KOSEM_PROJECT']}/llm/openai/v1",
    api_key=os.environ["KOSEM_API_KEY"],
)
response = client.chat.completions.create(
    model="qwen",
    messages=[{"role": "user", "content": "Summarize the release notes in three bullets."}],
    extra_body={"enable_thinking": True, "thinking_budget": 2048},
)
print(response.choices[0].message.content)
```

## If adding it fails [#if-adding-it-fails]

| Error                                                           | What it means                                                       | What to do                               |
| --------------------------------------------------------------- | ------------------------------------------------------------------- | ---------------------------------------- |
| **Alibaba Cloud Model Studio refused the API key.**             | The key is for another region than the base URL                     | Enter the base URL of the key's region   |
| **Base URL must be an address of Alibaba Cloud Model Studio …** | The base URL is in the Chinese mainland or isn't a Model Studio URL | Enter a region's base URL from the table |

## Related [#related]

- [Add a provider](/guides/llm-gateway/add-a-provider)
- [Call models from your code](/guides/llm-gateway/call-models-from-code)
- [Compatible servers](/guides/llm-gateway/providers/compatible-servers#move-a-model-to-its-makers-provider), to move a Qwen model off an OpenAI-compatible provider
