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.
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 setDASHSCOPE_API_KEY:
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 thelangchain-qwq package:
Instantiation
Select a supported Qwen model and enable thinking throughextra_body:
ChatQwen with its enable_thinking argument:
Invocation
The following examples use thellm instance of ChatQwQ:
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:ainvoke:
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:
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 throughChatQwen. Check the provider’s supported input formats before sending multimodal messages.
See also
Connect these docs to your agent of choice via MCP for real-time answers.

