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.
Check if the provided user was provided by LangGraph Studio.
Get the API key from the environment.
Overrides the fetch implementation used for LangSmith calls.
Get the API key from the environment.
Retrieves the global logger instance for LangGraph Platform.
Calculates the depth of a subagent based on its namespace.
Extracts the parent tool call ID from a namespace.
Extracts the tool call ID from a namespace path.
Checks if a namespace indicates a subagent/subgraph message.
A React hook that provides seamless integration with LangGraph streaming capabilities.
Helper to send and persist UI messages. Accepts a map of component names to React components