LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraph-sdkclient
Module●Since v0.0

client

Copy
import { ... } from "@langchain/langgraph-sdk/client";

Functions

function
inferChannel→ Channel | undefined
function
matchesSubscription→ boolean
function
resolveClientApiUrl→ string | undefined
function
getApiKey→ string | undefined

Classes

class
AssistantsClient
class
BaseClient
class
CronsClient
class
RunsClient
class
StoreClient
class
ThreadsClient
class
Client
class
HttpAgentServerAdapter
class
MediaAssembler
class
MediaAssemblyError
class
MessageAssembler
class
ProtocolError
class
ProtocolSseTransportAdapter
class
ProtocolWebSocketTransportAdapter
class
SubscriptionHandle
class
ThreadStream

Interfaces

Type Aliases

View source on GitHub
interface
InputModule
interface
StateModule
interface
ThreadModules
interface
AgentServerAdapter
interface
AssembledMessage
interface
AudioMedia
interface
ClientConfig
interface
EventSubscription
interface
FileMedia
interface
HttpAgentServerAdapterOptions
interface
ImageMedia
interface
MediaAssemblerCallbacks
interface
MediaAssemblerOptions
interface
MediaBase
interface
MessageSubscription
interface
ProtocolSseTransportOptions
interface
ProtocolTransportPaths
interface
ProtocolWebSocketTransportOptions
interface
SessionOrderingState
interface
ThreadExtension
interface
ThreadStreamOptions
interface
TransportAdapter
interface
VideoMedia
typeAlias
EventForChannel: TChannel extends keyof EventMethodByChannel ? Extract<Event, __type> : TChannel extends string ? Extract<Event, __type> : never
typeAlias
EventForChannels: EventForChannel<TChannels[number]>
typeAlias
EventMethodByChannel
typeAlias
HeaderValue: string | undefined | null
typeAlias
MessageAssemblyUpdate: __type | __type | __type | __type | __type | __type
typeAlias
ProtocolHeaderValue: string | undefined | null
typeAlias
SubscribeOptions: Omit<SubscribeParams, "channels">
typeAlias
ThreadStreamTransport: ThreadStreamTransportKind | AgentServerAdapter
typeAlias
ThreadStreamTransportKind: "sse" | "websocket"
typeAlias
AnyMediaHandle: AudioMedia | ImageMedia | VideoMedia | FileMedia
typeAlias
MediaAssemblyErrorKind: "message-error" | "stream-closed" | "fetch-failed"
typeAlias
MediaBlockType: "audio" | "image" | "video" | "file"
typeAlias
ProtocolRequestHook: (url: URL, init: RequestInit)
typeAlias
RequestHook: (url: URL, init: RequestInit)
typeAlias
ThreadExtensions: { [K in keyof TExtensions]: ThreadExtension<UnwrapExtension<TExtensions[K]>> } & __type
typeAlias
UnwrapExtension: T extends PromiseLike<U> ? U : T extends AsyncIterable<U> ? U : T

Maps a protocol event method to its subscription channel.

Returns undefined for unrecognized methods so that new server-side channels (e.g. from extension transformers) don't break existing clients.

Returns whether an event should be delivered for a subscription definition.

Resolve the LangGraph SDK Client base URL for hydration and history reads when the caller uses a custom AgentServerAdapter.

Explicit apiUrl wins; otherwise inherit from adapters that expose apiUrl (e.g. HttpAgentServerAdapter).

Get the API key from the environment. Precedence:

  1. explicit argument (if string)
  2. LANGGRAPH_API_KEY
  3. LANGSMITH_API_KEY
  4. LANGCHAIN_API_KEY

Public v1 name for TransportAdapter plus optional high-level capabilities. Renamed to reflect that this interface now denotes the full agent-server protocol contract (not merely wire transport): any object that satisfies it can back a useStream call. See plan-custom-transport.md §4 for the rollout.

The extra optional methods let adapters surface thread state and history without the framework needing to issue a parallel HTTP request — useStream.hydrate() calls getState?() when present and falls back to client.threads.getState otherwise. Adapters that don't know how to produce these values can simply omit them.

The legacy TransportAdapter export is retained for back-compat and resolves to the same structural type; new code should prefer AgentServerAdapter.

Typed error thrown through media.stream / rejected from media.blob / media.objectURL when a handle fails before its message completes. Carries the bytes accumulated up to the failure point on partialBytes for callers that want to salvage or diagnose.

Incrementally assembles messages events into complete message objects.

Error wrapper for protocol-level error responses returned by the server.

Transport adapter that speaks the thread-centric protocol over HTTP commands plus SSE event streams. Bound to a threadId at construction or later via setThreadId; request URLs derive from the currently-bound thread. Each openEventStream call opens an independent filtered SSE connection via POST /threads/:thread_id/stream/events.

Transport adapter that speaks the thread-centric protocol over a bidirectional WebSocket. Bound to a threadId at construction or later via setThreadId — the socket connects to ws://.../threads/:thread_id/stream/events.

On unexpected disconnect the adapter reconnects with exponential backoff (see ProtocolWebSocketTransportOptions.maxReconnectAttempts). The server replays buffered events on the new socket; the SDK deduplicates by event_id. ProtocolWebSocketTransportOptions.onReconnected runs after each successful reconnect so ThreadStream can re-issue subscription.subscribe commands.

Async iterable handle for raw event subscriptions.

An optional transform maps each incoming event before it is queued or delivered to a waiting consumer. This is used by named custom channel subscriptions (e.g. "custom:a2a") to unwrap the payload so callers receive the raw emitted data instead of the protocol event envelope.

High-level wrapper around a protocol connection to a specific thread.

In the thread-centric protocol, threads are durable (backed by checkpoints) and connections are ephemeral. A ThreadStream is the client-side handle for interacting with a thread: starting runs, subscribing to events, consuming assembled projections (messages, values, toolCalls, etc.), and responding to interrupts.

Construct via client.threads.stream(threadId?, { assistantId? }).

Modules exposed by the high-level ThreadStream wrapper.

Public v1 name for TransportAdapter plus optional high-level capabilities. Renamed to reflect that this interface now denotes the full agent-server protocol contract (not merely wire transport): any object that satisfies it can back a useStream call. See plan-custom-transport.md §4 for the rollout.

The extra optional methods let adapters surface thread state and history without the framework needing to issue a parallel HTTP request — useStream.hydrate() calls getState?() when present and falls back to client.threads.getState otherwise. Adapters that don't know how to produce these values can simply omit them.

The legacy TransportAdapter export is retained for back-compat and resolves to the same structural type; new code should prefer AgentServerAdapter.

Mutable view of a streamed message as message and content-block events are assembled into a single structure.

Shared surface across every media handle returned by MediaAssembler.

The handle is live while its parent message is active:

  • partialBytes is a snapshot of all bytes received so far.
  • stream is a lazy, single-consumer byte stream (see accessor docstring).
  • blob / objectURL settle on message-finish.
  • error becomes set if the handle terminates in any of the MediaAssemblyErrorKind failure modes.

Configuration for BaseClient and the exported LangGraph SDK Client.

Shared surface across every media handle returned by MediaAssembler.

The handle is live while its parent message is active:

  • partialBytes is a snapshot of all bytes received so far.
  • stream is a lazy, single-consumer byte stream (see accessor docstring).
  • blob / objectURL settle on message-finish.
  • error becomes set if the handle terminates in any of the MediaAssemblyErrorKind failure modes.

Shared surface across every media handle returned by MediaAssembler.

The handle is live while its parent message is active:

  • partialBytes is a snapshot of all bytes received so far.
  • stream is a lazy, single-consumer byte stream (see accessor docstring).
  • blob / objectURL settle on message-finish.
  • error becomes set if the handle terminates in any of the MediaAssemblyErrorKind failure modes.

Dispatch callbacks receive a freshly-started handle on its first matching content-block-start. Exactly one callback fires per (messageId, blockType) pair.

Dispatch callbacks receive a freshly-started handle on its first matching content-block-start. Exactly one callback fires per (messageId, blockType) pair.

Shared surface across every media handle returned by MediaAssembler.

The handle is live while its parent message is active:

  • partialBytes is a snapshot of all bytes received so far.
  • stream is a lazy, single-consumer byte stream (see accessor docstring).
  • blob / objectURL settle on message-finish.
  • error becomes set if the handle terminates in any of the MediaAssemblyErrorKind failure modes.

Remote counterpart of an in-process run.extensions.<name> projection.

Each extension is the client-side view of a compile-time StreamTransformer projection. The server auto-forwards named StreamChannel.remote(name) outputs on the custom:<name> channel, and this handle exposes them via two dual interfaces:

  • AsyncIterable<T> — iterate every item pushed by a streaming transformer (e.g. a StreamChannel).
  • PromiseLike<T> — await resolves with the final value observed when the run terminates. For streaming transformers this is the last item pushed; for final-value transformers it is the single value emitted on run end.

Subscribing is lazy: the underlying custom:<name> subscription is opened on first property access and cached.

Options for ThreadStream construction.

Transport abstraction implemented by concrete client transports such as WebSocket or SSE adapters.

In the thread-centric protocol the thread ID is part of the request URLs. Transports may be bound at construction time, or left unbound and bound later via setThreadId (see that method) — which lets a single instance follow a lazily-created thread.

Shared surface across every media handle returned by MediaAssembler.

The handle is live while its parent message is active:

  • partialBytes is a snapshot of all bytes received so far.
  • stream is a lazy, single-consumer byte stream (see accessor docstring).
  • blob / objectURL settle on message-finish.
  • error becomes set if the handle terminates in any of the MediaAssemblyErrorKind failure modes.

Emitted by MessageAssembler.consume() to describe how a message changed in response to a single protocol event.

Accepted values for ThreadStreamOptions["transport"].

  • A ThreadStreamTransportKind string picks one of the built-in factories; fetch / webSocketFactory tune that path.
  • An AgentServerAdapter bypasses the built-in factories entirely; the adapter is used for every command and subscription.

Built-in wire transport used by ThreadStream.

  • "sse": HTTP commands + one SSE event stream per subscription. Works in browsers without extra setup.
  • "websocket": single bidirectional WebSocket. Lower overhead for long-lived, multi-subscription sessions.

Kinds of failure that can terminate a media handle prematurely.

  • "message-error" — the upstream message emitted an error event before completion.
  • "stream-closed" — the transport stream closed before message-finish arrived (thread closed, transport dropped, etc.).
  • "fetch-failed" — the block was url-sourced and the lazy fetch() rejected (CORS, 404, 5xx, network).

Block types this assembler knows how to reassemble into media handles.

Keyed map of ThreadExtension handles, typed off a declared transformer projection shape.

Used as the return type of ThreadStream.extensions. TExtensions is expected to match the in-process run.extensions shape (i.e. the output of InferExtensions<TTransformers> from @langchain/langgraph); each value type is unwrapped via UnwrapExtension so thread.extensions.foo resolves with the transformer's emitted payload, not the in-process Promise<T> / StreamChannel<T> wrapper.

Access any string key to obtain a ThreadExtension<unknown>; keys that appear in TExtensions narrow to their declared payload type.

Unwrap a single in-process projection value to its observable payload type:

  • Promise<T> / PromiseLike<T> → T (final-value transformers)
  • StreamChannel<T> / AsyncIterable<T> → T (streaming transformers)
  • anything else → the value itself

This lets a ThreadStream<TExtensions> generic accept the same shape that graph.streamEvents(..., { version: "v3" }) returns in-process (via InferExtensions<TTransformers> from @langchain/langgraph), without forcing users to redeclare payload types on the remote side.