LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
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
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
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

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.

function
matchesSubscription→ boolean

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

function
getApiKey→ string | undefined

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

Classes

class
AssistantsClient
class
BaseClient
class
CronsClient
class
RunsClient
class
StoreClient
class
ThreadsClient
class
Client
class
HttpAgentServerAdapter

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.

class
MediaAssembler
class
MediaAssemblyError

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.

class
MessageAssembler

Incrementally assembles messages events into complete message objects.

class
ProtocolError

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

class
ProtocolSseTransportAdapter

Transport adapter that speaks the thread-centric protocol over HTTP commands plus SSE event streams. Bound to a specific threadId at construction. Each openEventStream call opens an independent filtered SSE connection via POST /threads/:thread_id/stream/events.

class
ProtocolWebSocketTransportAdapter

Transport adapter that speaks the thread-centric protocol over a bidirectional WebSocket. Bound to a specific threadId — the socket connects to ws://.../threads/:thread_id/stream/events.

class
SubscriptionHandle

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.

class
ThreadStream

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? }).

Interfaces

interface
InputModule
interface
StateModule
interface
ThreadModules

Modules exposed by the high-level ThreadStream wrapper.

interface
AgentServerAdapter

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.

interface
AssembledMessage

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

interface
AudioMedia

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.
interface
ClientConfig

Configuration for BaseClient and the exported LangGraph SDK Client.

interface
EventSubscription
interface
FileMedia

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.
interface
HttpAgentServerAdapterOptions
interface
ImageMedia

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.
interface
MediaAssemblerCallbacks

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

interface
MediaAssemblerOptions

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

interface
MediaBase

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.
interface
MessageSubscription
interface
ProtocolSseTransportOptions
interface
ProtocolTransportPaths
interface
ProtocolWebSocketTransportOptions
interface
SessionOrderingState
interface
ThreadExtension

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.

interface
ThreadStreamOptions

Options for ThreadStream construction.

interface
TransportAdapter

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

In the thread-centric protocol, transports are bound to a specific thread at construction time — the thread ID is part of the connection URL.

interface
VideoMedia

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.

Type Aliases

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

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

typeAlias
ProtocolHeaderValue: string | undefined | null
typeAlias
SubscribeOptions: Omit<SubscribeParams, "channels">
typeAlias
ThreadStreamTransport: ThreadStreamTransportKind | AgentServerAdapter

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.
typeAlias
ThreadStreamTransportKind: "sse" | "websocket"

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.
typeAlias
AnyMediaHandle: AudioMedia | ImageMedia | VideoMedia | FileMedia
typeAlias
MediaAssemblyErrorKind: "message-error" | "stream-closed" | "fetch-failed"

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).
typeAlias
MediaBlockType: "audio" | "image" | "video" | "file"

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

typeAlias
ProtocolRequestHook: (url: URL, init: RequestInit)
typeAlias
RequestHook: (url: URL, init: RequestInit)
typeAlias
ThreadExtensions: { [K in keyof TExtensions]: ThreadExtension<UnwrapExtension<TExtensions[K]>> } & __type

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.

typeAlias
UnwrapExtension: T extends PromiseLike<U> ? U : T extends AsyncIterable<U> ? U : T

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.

View source on GitHub