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:85

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:332


delete()

delete(assistantId): Promise\<void>

Delete an assistant.

Parameters

assistantId: string

ID of the assistant.

Returns

Promise\<void>

Defined in

client.ts:384


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:274


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:284


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:298


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:309


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:418


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:395


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:446


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:359

@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:1303

Properties

assistants

assistants: AssistantsClient

The client for interacting with assistants.

Defined in

client.ts:1281


crons

crons: CronsClient

The client for interacting with cron runs.

Defined in

client.ts:1296


runs

runs: RunsClient

The client for interacting with runs.

Defined in

client.ts:1291


store

store: StoreClient

The client for interacting with the KV store.

Defined in

client.ts:1301


threads

threads: ThreadsClient

The client for interacting with threads.

Defined in

client.ts:1286

@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:85

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:212


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:183


delete()

delete(cronId): Promise\<void>

Parameters

cronId: string

Cron ID of Cron job to delete.

Returns

Promise\<void>

Defined in

client.ts:238


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:249

@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:85

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:984


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:810


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:843


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:1099


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:971


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:1006


joinStream()

joinStream(threadId, runId, options?): 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.

options?: AbortSignal | object

Returns

AsyncGenerator\<object, any, unknown>

An async generator yielding stream parts.

data

data: any

event

event: StreamEvent

Defined in

client.ts:1026


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.

options.status?: RunStatus

Status of the run to filter by.

Returns

Promise\<Run[]>

List of runs.

Defined in

client.ts:934


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:694

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:703


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:860

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:866

@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:85

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:1187


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:1158


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:1255


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:1126


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

options.query?: string

Optional search query.

Returns

Promise\<SearchItemsResponse>

Promise

Defined in

client.ts:1212

@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:85

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:494


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:471


delete()

delete(threadId): Promise\<void>

Delete a thread.

Parameters

threadId: string

ID of the thread.

Returns

Promise\<void>

Defined in

client.ts:527


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:461


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:669


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:576


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:639


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:539


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:507


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:610

@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:50

Comments