LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corelanguage_modelschat_model_streamAsyncChatModelStream
    Class●Since v1.3

    AsyncChatModelStream

    Copy
    AsyncChatModelStream(
      self,
      *,
      namespace: list[str] | None = None,
      node: str

    Bases

    _ChatModelStreamBase

    Constructors

    Attributes

    Methods

    View source on GitHub
    |
    None
    =
    None
    ,
    message_id
    :
    str
    |
    None
    =
    None
    )
    constructor
    __init__
    NameType
    namespacelist[str] | None
    nodestr | None
    message_idstr | None
    attribute
    text: AsyncProjection
    attribute
    reasoning: AsyncProjection
    attribute
    tool_calls: AsyncProjection
    attribute
    output: AsyncProjection
    method
    set_arequest_more
    method
    set_start
    method
    aclose
    method
    fail

    Asynchronous per-message streaming object for a single LLM response.

    Returned by BaseChatModel.astream_v2(). Content-block events are fed into this object by a background producer task.

    Projections:

    • .text — async iterable of text deltas; awaitable for full text
    • .reasoning — async iterable of reasoning deltas; awaitable
    • .tool_calls — async iterable of ToolCallChunk deltas; awaitable for list[ToolCall]
    • .output — awaitable for assembled AIMessage

    Usage info is available on .output.usage_metadata once the stream has finished.

    Output shape is always v1 content blocks

    The assembled message's content is always a list of v1 protocol blocks, regardless of the model's output_version setting — see ChatModelStream for the full rationale.

    The stream itself is awaitable (msg = await stream) and async-iterable (async for event in stream).

    Text content — async iterable of deltas, awaitable for full.

    Reasoning content — same interface as :attr:text.

    Tool calls — async iterable, awaitable for finalized list.

    Assembled AIMessage — awaitable.

    Fan the async pump callback out to every projection.

    Used by langgraph's AsyncGraphRunStream._wire_arequest_more so cursors on stream.text, stream.reasoning, etc. can drive the shared graph pump when their buffer is empty.

    Install a lazy-start callback on this stream and its projections.

    Cancel the background producer task and release resources.

    If a consumer cancels mid-stream or decides to stop iterating early, the producer task keeps pumping the provider HTTP call to completion because asyncio.Task has no implicit link to its awaiter. Call this method to cancel the producer explicitly; the stream transitions to an errored state with CancelledError.

    If the stream has already produced a message successfully (for example, after await stream.output), the producer may still be running post-stream work such as on_llm_end callbacks. In that case aclose() awaits the task rather than cancelling it — turning a successful run into a cancelled one would drop the end callback and corrupt tracing.

    Idempotent: safe to call multiple times, including after the stream has finished normally. Also invoked by the async context manager protocol on __aexit__.

    Fail base projections and async-only projections.