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-sdkstreamAgentServerOptions
Interface●Since v1.9

AgentServerOptions

Agent-server branch: caller points useStream at an assistant on a LangGraph-Platform-compatible server. Discriminated against CustomAdapterOptions by transport being absent or a string.

Copy
interface AgentServerOptions

Bases

UseStreamCommonOptions<StateType, ThreadIdType>

Properties

property
apiKey: ApiKeyType

API key for authentication.

  • If a string is provided, that key will be used
  • If undefined (default), the key will be auto-loaded from environment variables (LANGGRAPH_API_KEY, LANGSMITH_API_KEY, or LANGCHAIN_API_KEY)
  • If null, no API key will be set (skips auto-loading)
property
apiUrl: ApiUrlType
property
assistantId: string
property
callerOptions: AsyncCallerParams

Options forwarded to the internal AsyncCaller, such as retry, concurrency, or custom fetch behavior.

property
client: Client<DefaultValues, DefaultValues, unknown>

LangGraph SDK client used to send requests and receive responses.

property
defaultHeaders: Record<string, HeaderValue>

Headers applied to every request.

The configured API key, when present, is added as the x-api-key header after these defaults are initialized.

property
fetch: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>

Optional fetch override, forwarded to the SSE transport. Useful for auth proxies, Next.js route handlers, or tests with injected mocks. Ignored when webSocketFactory is also supplied.

property
initialValues: StateType

Initial values to display immediately when loading a thread. Useful for displaying cached thread data while official history loads. These values will be replaced when official thread data is fetched.

Note: UI components from initialValues will render immediately if they're predefined in LoadExternalComponent's components prop, providing instant cached UI display without server fetches.

property
messagesKey: string

Specify the key within the state that contains messages. Defaults to "messages".

property
onCompleted: (info: RunCompletedInfo) => void

Convenience callback fired when a run's active streaming phase ends. runId may be omitted for re-attached in-flight runs because no local dispatch response was observed.

property
onCreated: (info: RunExecutionInfo) => void

Callback that is called when a new stream is created.

property
onThreadId: (threadId: string) => void

Callback that is called when the thread ID is updated (ie when a new thread is created).

property
onTool: OnToolCallback
property
optimistic: boolean

Optimistic UI for submit(). When enabled (the default), the input passed to submit() is reflected in values / messages immediately — before the server responds — then reconciled against the authoritative server state as it streams in:

  • Messages in the input are appended right away. Any message without an id is assigned a stable client id (sent to the server, which add_messages preserves) so the server echo reconciles by id instead of duplicating. Per-message progress is exposed via useMessageMetadata(stream, id).optimisticStatus ("pending" → "sent", or "failed" if the run errors before the message is echoed; failed optimistic messages are kept for retry UIs and dropped on the next hydrate()).
  • Other input keys are shallow-merged into values and converge to server truth on the first values event (or are rolled back if the run fails before any echo).

Set to false to dispatch input verbatim with no client-side echo or id minting (server-authoritative only) — useful for non-chat state graphs or deterministic SSR/tests.

property
threadId: ThreadIdType

Thread ID this transport currently targets.

property
tools: AnyHeadlessToolImplementation[]
property
transport: "sse" | "websocket"

How this thread talks to the agent server. Accepts either a built-in transport string or a custom AgentServerAdapter:

  • "sse": HTTP commands + one SSE event stream per subscription.
  • "websocket": single bidirectional WebSocket.
  • an AgentServerAdapter: custom transport that replaces the built-in factories entirely. fetch / webSocketFactory are ignored in this mode.

Defaults to the client-level streamProtocol ("v2-websocket" → "websocket", otherwise "sse").

property
webSocketFactory: (url: string) => WebSocket

Optional WebSocket factory. Supplying it flips the adapter into WebSocket mode — SSE is bypassed entirely.

Inherited fromUseStreamCommonOptions

Properties

PinitialValues: StateType | null
—

Initial values to display immediately when loading a thread.

PmessagesKey: string
—

Specify the key within the state that contains messages.

PonCompleted: (info: RunCompletedInfo)
—

Convenience callback fired when a run's active streaming phase ends.

PonCreated: (run: RunCallbackMeta)
—

Callback that is called when a new stream is created.

PonThreadId: (threadId: string)
—

Callback that is called when the thread ID is updated (ie when a new thread is created).

PonTool: OnToolCallbackPoptimistic: boolean
—

Optimistic UI for submit(). When enabled (the default), the input

PthreadId: string
—

Thread ID this transport currently targets.

Ptools: "tools"
View source on GitHub