Qwen API Integration for Python

Connect Python applications to Qwen models in the Frankfurt Global deployment of Alibaba Cloud Model Studio.

All providers

Installation

Use Python 3.10–3.14 and run this command in your virtual environment.

python -m pip install llm-api-adapter==0.11.0 llm-api-adapter-qwen==0.1.3

Authentication

Open Model Studio API key guide. Create an API key for the Frankfurt Global deployment and use the workspace that owns the key. Set the following in the terminal where you will run the example.

Find your Model Studio workspace ID in the same deployment and set both variables.

export QWEN_API_KEY="your-api-key"
export QWEN_WORKSPACE_ID="your-workspace-id"

Quickstart

Send a message

Save the example as chat.py and run python chat.py.

import os

from llm_api_adapter.models.messages.chat_message import UserMessage
from llm_api_adapter.universal_adapter import UniversalLLMAPIAdapter

adapter = UniversalLLMAPIAdapter(
    organization="qwen",
    model="qwen4-max",
    api_key=os.environ["QWEN_API_KEY"],
)

response = adapter.chat(
    messages=[UserMessage("Explain what an API is in one sentence.")],
    max_tokens=1024,
    workspace_id=os.environ["QWEN_WORKSPACE_ID"],
    timeout_s=60,
)
print(response.content)

Supported models

Registry snapshot

Prices are first-tier base rates from the adapter registry. Open a model for all tiers, cache rates, pricing schedules, and capability notes. Unknown means the registry has no value.

  • qwen4-max

    Context tokens
    1,000,000
    Base input per million tokens
    10 CNY
    Maximum output tokens
    262,144
    Base output per million tokens
    30 CNY
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unknown
    PDF bytes
    Unknown
    JSON Schema output
    Unknown
    Pydantic output
    Unknown
  • qwen3.8-max

    Context tokens
    1,000,000
    Base input per million tokens
    12 CNY
    Maximum output tokens
    131,072
    Base output per million tokens
    36 CNY
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unknown
    PDF bytes
    Unknown
    JSON Schema output
    Unknown
    Pydantic output
    Unknown
  • qwen3.8-flash

    Context tokens
    1,000,000
    Base input per million tokens
    0.8 CNY
    Maximum output tokens
    131,072
    Base output per million tokens
    2.7 CNY
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unknown
    PDF bytes
    Unknown
    JSON Schema output
    Unknown
    Pydantic output
    Unknown
  • qwen3.7-plus

    Context tokens
    1,000,000
    Base input per million tokens
    2 CNY
    Maximum output tokens
    131,072
    Base output per million tokens
    8 CNY
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unsupported
    PDF bytes
    Unsupported
    JSON Schema output
    Unknown
    Pydantic output
    Unknown
  • qwen3.7-flash

    Context tokens
    1,000,000
    Base input per million tokens
    0.2 CNY
    Maximum output tokens
    131,072
    Base output per million tokens
    0.8 CNY
    Reasoning
    Supported
    Image URLs
    Unknown
    PDF URLs
    Unsupported
    PDF bytes
    Unsupported
    JSON Schema output
    Unknown
    Pydantic output
    Unknown

Provider-specific features and limitations

  • Pass the Frankfurt Global workspace_id explicitly on each chat or streaming call. The adapter uses it to form the regional endpoint.
  • The adapter maps reasoning_level to the selected Qwen model. On models that cannot combine thinking with a forced tool choice, the adapter turns thinking off for that request.

Metered operations

  • qwen4 max pdf pages · qwen4-max · 0.02 CNY per page
  • qwen38 max pdf pages · qwen3.8-max · 0.02 CNY per page
  • qwen38 flash pdf pages · qwen3.8-flash · 0.02 CNY per page

Resources