Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai node Beta Threads Runs

From Leeroopedia
Revision as of 13:35, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_node_Beta_Threads_Runs.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK, Assistants, Threads, Beta
Last Updated 2026-02-15 12:00 GMT

Overview

The Beta Threads Runs resource class provides deprecated methods to create, retrieve, update, list, cancel, poll, stream, and submit tool outputs for assistant runs within threads.

Description

The Runs class extends APIResource and is marked @deprecated in favor of the Responses API. It provides an extensive set of methods for managing the lifecycle of runs on threads. The core CRUD methods (create, retrieve, update, list, cancel) map to the /threads/{threadID}/runs REST endpoints. The create method supports both streaming and non-streaming variants via overloads, returning either a Run object or a Stream<AssistantStreamEvent>.

The class also provides several higher-level helper methods. createAndPoll creates a run and repeatedly polls until it reaches a terminal state. poll implements the polling loop with configurable intervals and respects the openai-poll-after-ms response header. stream and createAndStream create streaming runs using AssistantStream. submitToolOutputs handles the submission of tool call outputs when a run enters the requires_action state, with both streaming and non-streaming variants. submitToolOutputsAndPoll and submitToolOutputsStream combine tool output submission with polling or streaming.

The Run interface represents an execution run on a thread with properties including status (a union of queued, in_progress, requires_action, cancelling, cancelled, failed, completed, incomplete, expired), required_action (containing tool calls), usage statistics, truncation_strategy, and all the standard configuration fields. The class manages the Steps sub-resource via this.steps.

Usage

Use this resource to execute and manage assistant runs on threads. Access it via client.beta.threads.runs. The sub-resource client.beta.threads.runs.steps provides access to run steps. This API is deprecated in favor of the Responses API.

Code Reference

Source Location

Signature

/** @deprecated The Assistants API is deprecated in favor of the Responses API */
export class Runs extends APIResource {
  steps: StepsAPI.Steps;

  create(threadID: string, params: RunCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Run>;
  create(threadID: string, params: RunCreateParamsStreaming, options?: RequestOptions): APIPromise<Stream<AssistantStreamEvent>>;

  retrieve(runID: string, params: RunRetrieveParams, options?: RequestOptions): APIPromise<Run>;

  update(runID: string, params: RunUpdateParams, options?: RequestOptions): APIPromise<Run>;

  list(threadID: string, query?: RunListParams, options?: RequestOptions): PagePromise<RunsPage, Run>;

  cancel(runID: string, params: RunCancelParams, options?: RequestOptions): APIPromise<Run>;

  createAndPoll(threadId: string, body: RunCreateParamsNonStreaming, options?: RequestOptions): Promise<Run>;

  poll(runId: string, params: RunRetrieveParams, options?: RequestOptions): Promise<Run>;

  stream(threadId: string, body: RunCreateParamsBaseStream, options?: RequestOptions): AssistantStream;

  submitToolOutputs(runID: string, params: RunSubmitToolOutputsParams, options?: RequestOptions): APIPromise<Run | Stream<AssistantStreamEvent>>;

  submitToolOutputsAndPoll(runId: string, params: RunSubmitToolOutputsParamsNonStreaming, options?: RequestOptions): Promise<Run>;

  submitToolOutputsStream(runId: string, params: RunSubmitToolOutputsParamsStream, options?: RequestOptions): AssistantStream;
}

Import

import OpenAI from 'openai';
// Access via client.beta.threads.runs
// Sub-resource: client.beta.threads.runs.steps

I/O Contract

Inputs

Name Type Required Description
threadID string Yes The thread ID to run the assistant on
assistant_id string Yes (create) The assistant ID to execute
model ChatModel | null No Override the assistant's model for this run
instructions null No Override instructions for this run
additional_instructions null No Append to the assistant's instructions
additional_messages null No Messages to add before creating the run
tools null No Override tools for this run
stream null No Enable streaming via server-sent events
temperature null No Sampling temperature (0 to 2)
top_p null No Nucleus sampling parameter
max_completion_tokens null No Maximum completion tokens for the run
max_prompt_tokens null No Maximum prompt tokens for the run
tool_choice null No How the model selects tools
response_format null No Output format constraint
truncation_strategy null No Thread truncation strategy (auto or last_messages)
parallel_tool_calls boolean No Enable parallel function calling
reasoning_effort null No Reasoning effort for reasoning models

Outputs

Name Type Description
Run Run Execution run with id, status, assistant_id, thread_id, tools, usage, and metadata
RunsPage CursorPage<Run> Paginated list of run objects
Stream Stream<AssistantStreamEvent> Server-sent event stream for streaming runs
AssistantStream AssistantStream Higher-level stream wrapper with event helpers

Usage Examples

Basic Usage

import OpenAI from 'openai';

const client = new OpenAI();

// Create a run and poll until completion
const run = await client.beta.threads.runs.createAndPoll('thread_abc123', {
  assistant_id: 'asst_abc123',
});
console.log(run.status); // 'completed'

// Create a streaming run
const stream = client.beta.threads.runs.stream('thread_abc123', {
  assistant_id: 'asst_abc123',
});

// Submit tool outputs when required
if (run.status === 'requires_action') {
  const toolOutputRun = await client.beta.threads.runs.submitToolOutputsAndPoll(
    run.id,
    {
      thread_id: 'thread_abc123',
      tool_outputs: [
        { tool_call_id: 'call_abc123', output: '70 degrees' },
      ],
    },
  );
}

// List runs for a thread
const runs = await client.beta.threads.runs.list('thread_abc123');

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment