LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/corelanguage_modelsevent
Moduleā—Since v1.1

language_models/event

Chat model streaming event protocol.

Defines a content-block-centric event model for streaming chat model responses. Events carry LangChain ContentBlock types on lifecycle boundaries and explicit delta variants for incremental updates during streaming.

Design Principles

  1. Content-block deltas have explicit merge semantics. Text, reasoning, and data deltas append to named fields. Generic block deltas shallow-merge fields onto the active content block.

  2. Lifecycle completeness. Every streamable entity has explicit start and finish events. Consumers never need to infer boundaries from absence of events.

  3. Interleaving allowed. Content blocks may interleave (e.g., parallel tool calls). The only invariant: a block's start precedes its deltas, and its deltas precede its finish. No ordering constraint between different blocks.

  4. Provider passthrough. Native provider events that don't map to standard types are forwarded as ProviderEvent rather than silently dropped.

Lifecycle Contract

MessageStart
  -> ContentBlockStart(index=0, content=...)
  -> ContentBlockDelta(index=0, delta={ type: "text-delta", text: "Hello" })
  -> ContentBlockDelta(index=0, delta={ type: "text-delta", text: " world" })
  -> ContentBlockFinish(index=0, content=...)
  -> UsageUpdate(...)
-> MessageFinish(reason, usage?)
Copy
import { ... } from "@langchain/core/language_models/event";

Interfaces

interface
BlockDelta

Generic content block field update. Shallow-merge fields onto the active content block.

interface
ContentBlockDeltaEvent

Emitted for each incremental update within a content block.

The delta field carries the incremental content block update. Accumulation rules:

  • text-delta → append text to the active block's text field
  • reasoning-delta → append reasoning to the active block's reasoning field
  • data-delta → append data to the active block's data field
  • block-delta → shallow-merge fields onto the active block
interface
ContentBlockFinishEvent

Emitted when a content block is complete.

interface
ContentBlockStartEvent

Emitted when a new content block begins streaming.

interface
DataDelta

Incremental encoded data. Append data to the active multimodal block's data field.

interface
MessageFinishEvent

Emitted once when the model response is complete.

interface
MessageStartEvent

Emitted once at the start of a model response.

interface
ProviderEvent

Passthrough for native provider events that don't map to standard types.

interface
ReasoningDelta

Incremental reasoning content. Append reasoning to the active block's reasoning field.

interface
StreamErrorEvent

Emitted on unrecoverable stream errors.

interface
TextDelta

Incremental text content. Append text to the active block's text field.

interface
UsageUpdateEvent

Emitted whenever the provider reports updated usage information. Each event carries a running snapshot (not an additive delta).

Type Aliases

typeAlias
ChatModelStreamEvent: MessageStartEvent | MessageFinishEvent | ContentBlockStartEvent | ContentBlockDeltaEvent | ContentBlockFinishEvent | UsageUpdateEvent | ProviderEvent | StreamErrorEvent

Union of all chat model stream event types.

typeAlias
ContentBlockDelta: TextDelta | ReasoningDelta | DataDelta | BlockDelta

Union of all content block delta types.

typeAlias
FinishReason: "stop" | "length" | "tool_use" | "content_filter"

Finish reason for a model response.

  • "stop": Natural end of generation.
  • "length": Hit max token limit.
  • "tool_use": Model is requesting tool execution.
  • "content_filter": Content was filtered by safety systems.
View source on GitHub