Skip to main content
ChatQwQ connects Qwen thinking models to LangChain’s chat model interface. The langchain-qwq package also provides ChatQwen, which exposes thinking controls as constructor arguments.
Alibaba retired qwq-plus in the Beijing and Singapore regions on October 10, 2026. See the model retirement notice.ChatQwQ still defaults to qwq-plus. Set model explicitly and enable thinking as shown below. The package name and imports remain unchanged.

Overview

Integration details

Model features

The following features apply to the Qwen Plus text model used in this guide. Model capabilities and availability vary by endpoint and region.

Setup

Use an Alibaba Cloud Model Studio account with access to the selected model. The examples require Python 3.10 or later.

Credentials

Generate an API key on Alibaba’s API key page, then set DASHSCOPE_API_KEY:
The default base URL is https://dashscope-intl.aliyuncs.com/compatible-mode/v1. Set DASHSCOPE_API_BASE or pass base_url to use the endpoint for your region. The API key and model must be available at that endpoint.

Installation

Install the langchain-qwq package:

Instantiation

Select a supported Qwen model and enable thinking through extra_body:
Alternatively, use ChatQwen with its enable_thinking argument:
For supported models and thinking controls, see Alibaba’s thinking-mode documentation.

Invocation

The following examples use the llm instance of ChatQwQ:
When the provider returns reasoning, additional_kwargs also contains its reasoning_content field:
content_blocks provides LangChain’s normalized view of text and reasoning. Accessing this property does not require output_version="v1", which this integration does not support.

Stream responses

Streaming returns message chunks as the model generates its response:
For asynchronous invocation, use ainvoke:
In a notebook with an active event loop, use await main() instead of asyncio.run(main()).

Tool calling

Tool calling lets the model request a function and supply its arguments. bind_tools sends tool definitions to the model; it does not execute the tools.

Use with bind_tools

Complete tool-argument buffering requires langchain-qwq>=0.4.0.
ChatQwQ buffers tool arguments until the provider finishes the generation or ends the stream cleanly. It preserves valid JSON and attempts to repair malformed JSON only after assembling the complete arguments. Text and reasoning continue streaming immediately. Errors and canceled streams do not emit unfinished tool calls. This behavior applies to synchronous and asynchronous streams, including callbacks.

Structured output

ChatQwQ uses function calling to return a structured result. A Pydantic schema validates the parsed result:
Passing method="json_mode" or method="json_schema" to ChatQwQ also selects function calling. These values do not enable native JSON mode on this wrapper.

Vision support

The text model in this guide does not accept image or video inputs. For vision tasks, select a compatible model and endpoint through ChatQwen. Check the provider’s supported input formats before sending multimodal messages.

See also