This repository contains the JS/TS SDK for interacting with the LangGraph REST API.
To get started with the JS/TS SDK, install the package
pnpm add @langchain/langgraph-sdk
You will need a running LangGraph API server. If you're running a server locally using langgraph-cli, SDK will automatically point at http://localhost:8123, otherwise
you would need to specify the server URL when creating a client.
import { Client } from "@langchain/langgraph-sdk";
const client = new Client();
// List all assistants
const assistants = await client.assistants.search({
metadata: null,
offset: 0,
limit: 10,
});
// We auto-create an assistant for each graph you register in config.
const agent = assistants[0];
// Start a new thread
const thread = await client.threads.create();
// Start a streaming run
const messages = [{ role: "human", content: "what's the weather in la" }];
const streamResponse = client.runs.stream(
thread["thread_id"],
agent["assistant_id"],
{
input: { messages },
}
);
for await (const chunk of streamResponse) {
console.log(chunk);
}
To generate documentation, run the following commands:
Generate docs.
pnpm typedoc
Consolidate doc files into one markdown file.
npx concat-md --decrease-title-levels --ignore=js_ts_sdk_ref.md --start-title-level-at 2 docs > docs/js_ts_sdk_ref.md
Copy js_ts_sdk_ref.md to MkDocs directory.
cp docs/js_ts_sdk_ref.md ../../docs/docs/cloud/reference/sdk/js_ts_sdk_ref.md
The reference documentation is available here.
More usage examples can be found here.
The change log for new versions can be found here.
Transport used to stream the thread.
Only applicable for custom endpoints using toLangGraphEventStream or toLangGraphEventStreamResponse.
Manages subagent execution state.
Tracks subagents from the moment they are invoked (AI message with tool calls) through streaming to completion (tool message result).
Check if the provided user was provided by LangGraph Studio.
By default, if you add custom authorization on your resources, this will also apply to interactions made from the Studio. If you want, you
Get the API key from the environment. Precedence:
Overrides the fetch implementation used for LangSmith calls. You should use this if you need to use an implementation of fetch other than the default global (e.g. for dealing with proxies).
Get the API key from the environment. Precedence:
Retrieves the global logger instance for LangGraph Platform.
The logger provides structured logging capabilities with various log levels (error, warn, info, debug, etc.) and extra metadata such as no
Calculates the depth of a subagent based on its namespace. Counts the number of "tools:" segments in the namespace.
Extracts the parent tool call ID from a namespace.
For nested subagents, the namespace looks like: ["tools:parent_id", "tools:child_id", ...]
Extracts the tool call ID from a namespace path.
Namespaces follow the pattern: ["tools:call_abc123", "model_request:xyz", ...] This function extracts "call_abc123" from the first "tools:" segment.
Checks if a namespace indicates a subagent/subgraph message.
Subagent namespaces contain a "tools:" segment indicating they originate from a tool call that spawned a subgraph.
A React hook that provides seamless integration with LangGraph streaming capabilities.
The useStream hook handles all the complexities of streaming, state management, and branching logic,
letting y
Helper to send and persist UI messages. Accepts a map of component names to React components
as type argument to provide type safety. Will also write to the options?.stateKey state.