Skip to content

SDK (JS/TS)

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk

Classes

Functions

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / AssistantsClient

Class: AssistantsClient

Extends

  • BaseClient

Constructors

new AssistantsClient()

new AssistantsClient(config?): AssistantsClient

Parameters

config?: ClientConfig

Returns

AssistantsClient

Inherited from

BaseClient.constructor

Defined in

client.ts:83

Methods

create()

create(payload): Promise\<Assistant>

Create a new assistant.

Parameters

payload

Payload for creating an assistant.

payload.assistantId?: string

payload.config?: Config

payload.graphId: string

payload.ifExists?: OnConflictBehavior

payload.metadata?: Metadata

payload.name?: string

Returns

Promise\<Assistant>

The created assistant.

Defined in

client.ts:330


delete()

delete(assistantId): Promise\<void>

Delete an assistant.

Parameters

assistantId: string

ID of the assistant.

Returns

Promise\<void>

Defined in

client.ts:382


get()

get(assistantId): Promise\<Assistant>

Get an assistant by ID.

Parameters

assistantId: string

The ID of the assistant.

Returns

Promise\<Assistant>

Assistant

Defined in

client.ts:272


getGraph()

getGraph(assistantId, options?): Promise\<AssistantGraph>

Get the JSON representation of the graph assigned to a runnable

Parameters

assistantId: string

The ID of the assistant.

options?

options.xray?: number | boolean

Whether to include subgraphs in the serialized graph representation. If an integer value is provided, only subgraphs with a depth less than or equal to the value will be included.

Returns

Promise\<AssistantGraph>

Serialized graph

Defined in

client.ts:282


getSchemas()

getSchemas(assistantId): Promise\<GraphSchema>

Get the state and config schema of the graph assigned to a runnable

Parameters

assistantId: string

The ID of the assistant.

Returns

Promise\<GraphSchema>

Graph schema

Defined in

client.ts:296


getSubgraphs()

getSubgraphs(assistantId, options?): Promise\<Subgraphs>

Get the schemas of an assistant by ID.

Parameters

assistantId: string

The ID of the assistant to get the schema of.

options?

Additional options for getting subgraphs, such as namespace or recursion extraction.

options.namespace?: string

options.recurse?: boolean

Returns

Promise\<Subgraphs>

The subgraphs of the assistant.

Defined in

client.ts:307


getVersions()

getVersions(assistantId, payload?): Promise\<AssistantVersion[]>

List all versions of an assistant.

Parameters

assistantId: string

ID of the assistant.

payload?

payload.limit?: number

payload.metadata?: Metadata

payload.offset?: number

Returns

Promise\<AssistantVersion[]>

List of assistant versions.

Defined in

client.ts:416


search(query?): Promise\<Assistant[]>

List assistants.

Parameters

query?

Query options.

query.graphId?: string

query.limit?: number

query.metadata?: Metadata

query.offset?: number

Returns

Promise\<Assistant[]>

List of assistants.

Defined in

client.ts:393


setLatest()

setLatest(assistantId, version): Promise\<Assistant>

Change the version of an assistant.

Parameters

assistantId: string

ID of the assistant.

version: number

The version to change to.

Returns

Promise\<Assistant>

The updated assistant.

Defined in

client.ts:444


update()

update(assistantId, payload): Promise\<Assistant>

Update an assistant.

Parameters

assistantId: string

ID of the assistant.

payload

Payload for updating the assistant.

payload.config?: Config

payload.graphId?: string

payload.metadata?: Metadata

payload.name?: string

Returns

Promise\<Assistant>

The updated assistant.

Defined in

client.ts:357

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / Client

Class: Client

Constructors

new Client()

new Client(config?): Client

Parameters

config?: ClientConfig

Returns

Client

Defined in

client.ts:1283

Properties

assistants

assistants: AssistantsClient

The client for interacting with assistants.

Defined in

client.ts:1261


crons

crons: CronsClient

The client for interacting with cron runs.

Defined in

client.ts:1276


runs

runs: RunsClient

The client for interacting with runs.

Defined in

client.ts:1271


store

store: StoreClient

The client for interacting with the KV store.

Defined in

client.ts:1281


threads

threads: ThreadsClient

The client for interacting with threads.

Defined in

client.ts:1266

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / CronsClient

Class: CronsClient

Extends

  • BaseClient

Constructors

new CronsClient()

new CronsClient(config?): CronsClient

Parameters

config?: ClientConfig

Returns

CronsClient

Inherited from

BaseClient.constructor

Defined in

client.ts:83

Methods

create()

create(assistantId, payload?): Promise\<Run>

Parameters

assistantId: string

Assistant ID to use for this cron job.

payload?: CronsCreatePayload

Payload for creating a cron job.

Returns

Promise\<Run>

Defined in

client.ts:210


createForThread()

createForThread(threadId, assistantId, payload?): Promise\<Run>

Parameters

threadId: string

The ID of the thread.

assistantId: string

Assistant ID to use for this cron job.

payload?: CronsCreatePayload

Payload for creating a cron job.

Returns

Promise\<Run>

The created background run.

Defined in

client.ts:181


delete()

delete(cronId): Promise\<void>

Parameters

cronId: string

Cron ID of Cron job to delete.

Returns

Promise\<void>

Defined in

client.ts:236


search()

search(query?): Promise\<Cron[]>

Parameters

query?

Query options.

query.assistantId?: string

query.limit?: number

query.offset?: number

query.threadId?: string

Returns

Promise\<Cron[]>

List of crons.

Defined in

client.ts:247

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / RunsClient

Class: RunsClient

Extends

  • BaseClient

Constructors

new RunsClient()

new RunsClient(config?): RunsClient

Parameters

config?: ClientConfig

Returns

RunsClient

Inherited from

BaseClient.constructor

Defined in

client.ts:83

Methods

cancel()

cancel(threadId, runId, wait, action): Promise\<void>

Cancel a run.

Parameters

threadId: string

The ID of the thread.

runId: string

The ID of the run.

wait: boolean = false

Whether to block when canceling

action: CancelAction = "interrupt"

Action to take when cancelling the run. Possible values are interrupt or rollback. Default is interrupt.

Returns

Promise\<void>

Defined in

client.ts:976


create()

create(threadId, assistantId, payload?): Promise\<Run>

Create a run.

Parameters

threadId: string

The ID of the thread.

assistantId: string

Assistant ID to use for this run.

payload?: RunsCreatePayload

Payload for creating a run.

Returns

Promise\<Run>

The created run.

Defined in

client.ts:808


createBatch()

createBatch(payloads): Promise\<Run[]>

Create a batch of stateless background runs.

Parameters

payloads: RunsCreatePayload & object[]

An array of payloads for creating runs.

Returns

Promise\<Run[]>

An array of created runs.

Defined in

client.ts:841


delete()

delete(threadId, runId): Promise\<void>

Delete a run.

Parameters

threadId: string

The ID of the thread.

runId: string

The ID of the run.

Returns

Promise\<void>

Defined in

client.ts:1082


get()

get(threadId, runId): Promise\<Run>

Get a run by ID.

Parameters

threadId: string

The ID of the thread.

runId: string

The ID of the run.

Returns

Promise\<Run>

The run.

Defined in

client.ts:963


join()

join(threadId, runId, options?): Promise\<void>

Block until a run is done.

Parameters

threadId: string

The ID of the thread.

runId: string

The ID of the run.

options?

options.signal?: AbortSignal

Returns

Promise\<void>

Defined in

client.ts:998


joinStream()

joinStream(threadId, runId, signal?): AsyncGenerator\<object, any, unknown>

Stream output from a run in real-time, until the run is done. Output is not buffered, so any output produced before this call will not be received here.

Parameters

threadId: string

The ID of the thread.

runId: string

The ID of the run.

signal?: AbortSignal

An optional abort signal.

Returns

AsyncGenerator\<object, any, unknown>

An async generator yielding stream parts.

data

data: any

event

event: StreamEvent

Defined in

client.ts:1019


list()

list(threadId, options?): Promise\<Run[]>

List all runs for a thread.

Parameters

threadId: string

The ID of the thread.

options?

Filtering and pagination options.

options.limit?: number

Maximum number of runs to return. Defaults to 10

options.offset?: number

Offset to start from. Defaults to 0.

Returns

Promise\<Run[]>

List of runs.

Defined in

client.ts:932


stream()

Create a run and stream the results.

Param

The ID of the thread.

Param

Assistant ID to use for this run.

Param

Payload for creating a run.

stream(threadId, assistantId, payload)

stream(threadId, assistantId, payload?): AsyncGenerator\<object, any, unknown>

Create a run and stream the results.

Parameters

threadId: null

assistantId: string

payload?: Omit\<RunsStreamPayload, "multitaskStrategy" | "onCompletion">

Returns

AsyncGenerator\<object, any, unknown>

# data

data: any

# event

event: StreamEvent

Defined in

client.ts:692

stream(threadId, assistantId, payload)

stream(threadId, assistantId, payload?): AsyncGenerator\<object, any, unknown>

Create a run and stream the results.

Parameters

threadId: string

assistantId: string

payload?: RunsStreamPayload

Returns

AsyncGenerator\<object, any, unknown>

# data

data: any

# event

event: StreamEvent

Defined in

client.ts:701


wait()

Create a run and wait for it to complete.

Param

The ID of the thread.

Param

Assistant ID to use for this run.

Param

Payload for creating a run.

wait(threadId, assistantId, payload)

wait(threadId, assistantId, payload?): Promise\<DefaultValues>

Create a run and wait for it to complete.

Parameters

threadId: null

assistantId: string

payload?: Omit\<RunsWaitPayload, "multitaskStrategy" | "onCompletion">

Returns

Promise\<DefaultValues>

Defined in

client.ts:858

wait(threadId, assistantId, payload)

wait(threadId, assistantId, payload?): Promise\<DefaultValues>

Create a run and wait for it to complete.

Parameters

threadId: string

assistantId: string

payload?: RunsWaitPayload

Returns

Promise\<DefaultValues>

Defined in

client.ts:864

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / StoreClient

Class: StoreClient

Extends

  • BaseClient

Constructors

new StoreClient()

new StoreClient(config?): StoreClient

Parameters

config?: ClientConfig

Returns

StoreClient

Inherited from

BaseClient.constructor

Defined in

client.ts:83

Methods

deleteItem()

deleteItem(namespace, key): Promise\<void>

Delete an item.

Parameters

namespace: string[]

A list of strings representing the namespace path.

key: string

The unique identifier for the item.

Returns

Promise\<void>

Promise

Defined in

client.ts:1170


getItem()

getItem(namespace, key): Promise\<null | Item>

Retrieve a single item.

Parameters

namespace: string[]

A list of strings representing the namespace path.

key: string

The unique identifier for the item.

Returns

Promise\<null | Item>

Promise

Defined in

client.ts:1141


listNamespaces()

listNamespaces(options?): Promise\<ListNamespaceResponse>

List namespaces with optional match conditions.

Parameters

options?

options.limit?: number

Maximum number of namespaces to return (default is 100).

options.maxDepth?: number

Optional integer specifying the maximum depth of namespaces to return.

options.offset?: number

Number of namespaces to skip before returning results (default is 0).

options.prefix?: string[]

Optional list of strings representing the prefix to filter namespaces.

options.suffix?: string[]

Optional list of strings representing the suffix to filter namespaces.

Returns

Promise\<ListNamespaceResponse>

Promise

Defined in

client.ts:1235


putItem()

putItem(namespace, key, value): Promise\<void>

Store or update an item.

Parameters

namespace: string[]

A list of strings representing the namespace path.

key: string

The unique identifier for the item within the namespace.

value: Record\<string, any>

A dictionary containing the item's data.

Returns

Promise\<void>

Promise

Defined in

client.ts:1109


searchItems()

searchItems(namespacePrefix, options?): Promise\<SearchItemsResponse>

Search for items within a namespace prefix.

Parameters

namespacePrefix: string[]

List of strings representing the namespace prefix.

options?

options.filter?: Record\<string, any>

Optional dictionary of key-value pairs to filter results.

options.limit?: number

Maximum number of items to return (default is 10).

options.offset?: number

Number of items to skip before returning results (default is 0).

Returns

Promise\<SearchItemsResponse>

Promise

Defined in

client.ts:1194

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / ThreadsClient

Class: ThreadsClient

Extends

  • BaseClient

Constructors

new ThreadsClient()

new ThreadsClient(config?): ThreadsClient

Parameters

config?: ClientConfig

Returns

ThreadsClient

Inherited from

BaseClient.constructor

Defined in

client.ts:83

Methods

copy()

copy(threadId): Promise\<Thread\<DefaultValues>>

Copy an existing thread

Parameters

threadId: string

ID of the thread to be copied

Returns

Promise\<Thread\<DefaultValues>>

Newly copied thread

Defined in

client.ts:492


create()

create(payload?): Promise\<Thread\<DefaultValues>>

Create a new thread.

Parameters

payload?

Payload for creating a thread.

payload.ifExists?: OnConflictBehavior

payload.metadata?: Metadata

Metadata for the thread.

payload.threadId?: string

Returns

Promise\<Thread\<DefaultValues>>

The created thread.

Defined in

client.ts:469


delete()

delete(threadId): Promise\<void>

Delete a thread.

Parameters

threadId: string

ID of the thread.

Returns

Promise\<void>

Defined in

client.ts:525


get()

get(threadId): Promise\<Thread\<DefaultValues>>

Get a thread by ID.

Parameters

threadId: string

ID of the thread.

Returns

Promise\<Thread\<DefaultValues>>

The thread.

Defined in

client.ts:459


getHistory()

getHistory\<ValuesType>(threadId, options?): Promise\<ThreadState\<ValuesType>[]>

Get all past states for a thread.

Type Parameters

ValuesType = DefaultValues

Parameters

threadId: string

ID of the thread.

options?

Additional options.

options.before?: Config

options.checkpoint?: Partial\<Omit\<Checkpoint, "thread_id">>

options.limit?: number

options.metadata?: Metadata

Returns

Promise\<ThreadState\<ValuesType>[]>

List of thread states.

Defined in

client.ts:667


getState()

getState\<ValuesType>(threadId, checkpoint?, options?): Promise\<ThreadState\<ValuesType>>

Get state for a thread.

Type Parameters

ValuesType = DefaultValues

Parameters

threadId: string

ID of the thread.

checkpoint?: string | Checkpoint

options?

options.subgraphs?: boolean

Returns

Promise\<ThreadState\<ValuesType>>

Thread state.

Defined in

client.ts:574


patchState()

patchState(threadIdOrConfig, metadata): Promise\<void>

Patch the metadata of a thread.

Parameters

threadIdOrConfig: string | Config

Thread ID or config to patch the state of.

metadata: Metadata

Metadata to patch the state with.

Returns

Promise\<void>

Defined in

client.ts:637


search()

search(query?): Promise\<Thread\<DefaultValues>[]>

List threads

Parameters

query?

Query options

query.limit?: number

Maximum number of threads to return. Defaults to 10

query.metadata?: Metadata

Metadata to filter threads by.

query.offset?: number

Offset to start from.

query.status?: ThreadStatus

Thread status to filter on. Must be one of 'idle', 'busy', 'interrupted' or 'error'.

Returns

Promise\<Thread\<DefaultValues>[]>

List of threads

Defined in

client.ts:537


update()

update(threadId, payload?): Promise\<Thread\<DefaultValues>>

Update a thread.

Parameters

threadId: string

ID of the thread.

payload?

Payload for updating the thread.

payload.metadata?: Metadata

Metadata for the thread.

Returns

Promise\<Thread\<DefaultValues>>

The updated thread.

Defined in

client.ts:505


updateState()

updateState\<ValuesType>(threadId, options): Promise\<Pick\<Config, "configurable">>

Add state to a thread.

Type Parameters

ValuesType = DefaultValues

Parameters

threadId: string

The ID of the thread.

options

options.asNode?: string

options.checkpoint?: Checkpoint

options.checkpointId?: string

options.values: ValuesType

Returns

Promise\<Pick\<Config, "configurable">>

Defined in

client.ts:608

@langchain/langgraph-sdkDocs


@langchain/langgraph-sdk / getApiKey

Function: getApiKey()

getApiKey(apiKey?): string | undefined

Get the API key from the environment. Precedence: 1. explicit argument 2. LANGGRAPH_API_KEY 3. LANGSMITH_API_KEY 4. LANGCHAIN_API_KEY

Parameters

apiKey?: string

Optional API key provided as an argument

Returns

string | undefined

The API key if found, otherwise undefined

Defined in

client.ts:48

Comments