Skip to content
Primary navigation

Retrieve run step

Deprecated
client.beta.threads.runs.steps.retrieve(stringstepID, StepRetrieveParams { thread_id, run_id, include } params, RequestOptionsoptions?): RunStep { id, assistant_id, cancelled_at, 13 more }
GET/threads/{thread_id}/runs/{run_id}/steps/{step_id}

Retrieves a run step.

ParametersExpand Collapse
stepID: string
params: StepRetrieveParams { thread_id, run_id, include }
thread_id: string

Path param: The ID of the thread to which the run and run step belongs.

run_id: string

Path param: The ID of the run to which the run step belongs.

include?: Array<RunStepInclude { } >

Query param: A list of additional fields to include in the response. Currently the only supported value is step_details.tool_calls[*].file_search.results[*].content to fetch the file search result content.

See the file search tool documentation for more information.

ReturnsExpand Collapse
RunStep { id, assistant_id, cancelled_at, 13 more }

Represents a step in execution of a run.

id: string

The identifier of the run step, which can be referenced in API endpoints.

assistant_id: string

The ID of the assistant associated with the run step.

cancelled_at: number | null

The Unix timestamp (in seconds) for when the run step was cancelled.

completed_at: number | null

The Unix timestamp (in seconds) for when the run step completed.

created_at: number

The Unix timestamp (in seconds) for when the run step was created.

expired_at: number | null

The Unix timestamp (in seconds) for when the run step expired. A step is considered expired if the parent run is expired.

failed_at: number | null

The Unix timestamp (in seconds) for when the run step failed.

last_error: LastError | null

The last error associated with this run step. Will be null if there are no errors.

code: "server_error" | "rate_limit_exceeded"

One of server_error or rate_limit_exceeded.

One of the following:
"server_error"
"rate_limit_exceeded"
message: string

A human-readable description of the error.

metadata: Metadata | null

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

object: "thread.run.step"

The object type, which is always thread.run.step.

run_id: string

The ID of the run that this run step is a part of.

status: "in_progress" | "cancelled" | "failed" | 2 more

The status of the run step, which can be either in_progress, cancelled, failed, completed, or expired.

One of the following:
"in_progress"
"cancelled"
"failed"
"completed"
"expired"
step_details: MessageCreationStepDetails { message_creation, type } | ToolCallsStepDetails { tool_calls, type }

The details of the run step.

One of the following:
MessageCreationStepDetails { message_creation, type }

Details of the message creation by the run step.

message_creation: MessageCreation { message_id }
message_id: string

The ID of the message that was created by this run step.

type: "message_creation"

Always message_creation.

ToolCallsStepDetails { tool_calls, type }

Details of the tool call.

tool_calls: Array<ToolCall>

An array of tool calls the run step was involved in. These can be associated with one of three types of tools: code_interpreter, file_search, or function.

One of the following:
CodeInterpreterToolCall { id, code_interpreter, type }

Details of the Code Interpreter tool call the run step was involved in.

id: string

The ID of the tool call.

code_interpreter: CodeInterpreter { input, outputs }

The Code Interpreter tool call definition.

input: string

The input to the Code Interpreter tool call.

outputs: Array<Logs { logs, type } | Image { image, type } >

The outputs from the Code Interpreter tool call. Code Interpreter can output one or more items, including text (logs) or images (image). Each of these are represented by a different object type.

One of the following:
Logs { logs, type }

Text output from the Code Interpreter tool call as part of a run step.

logs: string

The text output from the Code Interpreter tool call.

type: "logs"

Always logs.

Image { image, type }
image: Image { file_id }
file_id: string

The file ID of the image.

type: "image"

Always image.

type: "code_interpreter"

The type of tool call. This is always going to be code_interpreter for this type of tool call.

FileSearchToolCall { id, file_search, type }
id: string

The ID of the tool call object.

One of the following:
type: "file_search"

The type of tool call. This is always going to be file_search for this type of tool call.

FunctionToolCall { id, function, type }
id: string

The ID of the tool call object.

function: Function { arguments, name, output }

The definition of the function that was called.

arguments: string

The arguments passed to the function.

name: string

The name of the function.

output: string | null

The output of the function. This will be null if the outputs have not been submitted yet.

type: "function"

The type of tool call. This is always going to be function for this type of tool call.

type: "tool_calls"

Always tool_calls.

thread_id: string

The ID of the thread that was run.

type: "message_creation" | "tool_calls"

The type of run step, which can be either message_creation or tool_calls.

One of the following:
"message_creation"
"tool_calls"
usage: Usage | null

Usage statistics related to the run step. This value will be null while the run step's status is in_progress.

completion_tokens: number

Number of completion tokens used over the course of the run step.

prompt_tokens: number

Number of prompt tokens used over the course of the run step.

total_tokens: number

Total number of tokens used (prompt + completion).

Retrieve run step

import OpenAI from "openai";
const openai = new OpenAI();

async function main() {
  const runStep = await openai.beta.threads.runs.steps.retrieve(
    "step_abc123",
    { thread_id: "thread_abc123", run_id: "run_abc123" }
  );
  console.log(runStep);
}

main();
{
  "id": "step_abc123",
  "object": "thread.run.step",
  "created_at": 1699063291,
  "run_id": "run_abc123",
  "assistant_id": "asst_abc123",
  "thread_id": "thread_abc123",
  "type": "message_creation",
  "status": "completed",
  "cancelled_at": null,
  "completed_at": 1699063291,
  "expired_at": null,
  "failed_at": null,
  "last_error": null,
  "step_details": {
    "type": "message_creation",
    "message_creation": {
      "message_id": "msg_abc123"
    }
  },
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 456,
    "total_tokens": 579
  }
}
Returns Examples
{
  "id": "step_abc123",
  "object": "thread.run.step",
  "created_at": 1699063291,
  "run_id": "run_abc123",
  "assistant_id": "asst_abc123",
  "thread_id": "thread_abc123",
  "type": "message_creation",
  "status": "completed",
  "cancelled_at": null,
  "completed_at": 1699063291,
  "expired_at": null,
  "failed_at": null,
  "last_error": null,
  "step_details": {
    "type": "message_creation",
    "message_creation": {
      "message_id": "msg_abc123"
    }
  },
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 456,
    "total_tokens": 579
  }
}