Class RunsClient<TStateType, TUpdateType, TCustomEventType>

Type Parameters

Hierarchy

  • BaseClient
    • RunsClient

Constructors

Properties

apiUrl: string
asyncCaller: AsyncCaller
defaultHeaders: Record<string, HeaderValue>
onRequest?: RequestHook
timeoutMs: undefined | number

Methods

  • Cancel a run.

    Parameters

    • threadId: string

      The ID of the thread.

    • runId: string

      The ID of the run.

    • Optional wait: boolean

      Whether to block when canceling

    • Optional action: CancelAction

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

    Returns Promise<void>

  • Create a run.

    Parameters

    • threadId: string

      The ID of the thread.

    • assistantId: string

      Assistant ID to use for this run.

    • Optional payload: RunsCreatePayload

      Payload for creating a run.

    Returns Promise<Run>

    The created run.

  • Create a batch of stateless background runs.

    Parameters

    • payloads: (RunsCreatePayload & {
          assistantId: string;
      })[]

      An array of payloads for creating runs.

    Returns Promise<Run[]>

    An array of created runs.

  • Delete a run.

    Parameters

    • threadId: string

      The ID of the thread.

    • runId: string

      The ID of the run.

    Returns Promise<void>

  • Type Parameters

    • T

    Parameters

    • path: string
    • options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          signal?: AbortSignal;
          timeoutMs?: null | number;
          withResponse: true;
      }

    Returns Promise<[T, Response]>

  • Type Parameters

    • T

    Parameters

    • path: string
    • Optional options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          signal?: AbortSignal;
          timeoutMs?: null | number;
          withResponse?: false;
      }

    Returns Promise<T>

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

  • Block until a run is done.

    Parameters

    • threadId: string

      The ID of the thread.

    • runId: string

      The ID of the run.

    • Optional options: {
          signal?: AbortSignal;
      }
      • Optional signal?: AbortSignal

    Returns Promise<void>

  • Stream output from a run in real-time, until the run is done.

    Parameters

    • threadId: undefined | null | string

      The ID of the thread. Can be set to null | undefined for stateless runs.

    • runId: string

      The ID of the run.

    • Optional options: AbortSignal | {
          cancelOnDisconnect?: boolean;
          lastEventId?: string;
          signal?: AbortSignal;
          streamMode?: StreamMode | StreamMode[];
      }

      Additional options for controlling the stream behavior:

      • signal: An AbortSignal that can be used to cancel the stream request
      • lastEventId: The ID of the last event received. Can be used to reconnect to a stream without losing events.
      • cancelOnDisconnect: When true, automatically cancels the run if the client disconnects from the stream
      • streamMode: Controls what types of events to receive from the stream (can be a single mode or array of modes) Must be a subset of the stream modes passed when creating the run. Background runs default to having the union of all stream modes enabled.

    Returns AsyncGenerator<{
        data: any;
        event: StreamEvent;
        id?: string;
    }, any, any>

    An async generator yielding stream parts.

  • List all runs for a thread.

    Parameters

    • threadId: string

      The ID of the thread.

    • Optional options: {
          limit?: number;
          offset?: number;
          status?: RunStatus;
      }

      Filtering and pagination options.

      • Optional limit?: number

        Maximum number of runs to return. Defaults to 10

      • Optional offset?: number

        Offset to start from. Defaults to 0.

      • Optional status?: RunStatus

        Status of the run to filter by.

    Returns Promise<Run[]>

    List of runs.

  • Parameters

    • path: string
    • Optional options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          timeoutMs?: null | number;
          withResponse?: boolean;
      }

    Returns [url: URL, init: RequestInit]

  • Parameters

    • threadId: null
    • assistantId: string
    • Optional payload: Omit<RunsWaitPayload, "multitaskStrategy" | "onCompletion">

    Returns Promise<DefaultValues>

  • Parameters

    • threadId: string
    • assistantId: string
    • Optional payload: RunsWaitPayload

    Returns Promise<DefaultValues>