Skip to content
Primary navigation

Retrieve run step

Deprecated
beta.threads.runs.steps.retrieve(step_id, **kwargs) -> RunStep { id, assistant_id, cancelled_at, 13 more }
GET/threads/{thread_id}/runs/{run_id}/steps/{step_id}

Retrieves a run step.

ParametersExpand Collapse
thread_id: String
run_id: String
step_id: String
include: Array[RunStepInclude]

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
class 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: Integer

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

completed_at: Integer

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

created_at: Integer

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

expired_at: Integer

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

failed_at: Integer

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

last_error: { code, message}

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

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:
class MessageCreationStepDetails { message_creation, type }

Details of the message creation by the run step.

message_creation: { message_id}
message_id: String

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

type: :message_creation

Always message_creation.

class 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:
class 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: { input, outputs}

The Code Interpreter tool call definition.

input: String

The input to the Code Interpreter tool call.

outputs: Array[{ logs, type} | { 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:
class 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.

class Image { image, type }
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.

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

class FunctionToolCall { id, function, type }
id: String

The ID of the tool call object.

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

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: { completion_tokens, prompt_tokens, total_tokens}

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

completion_tokens: Integer

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

prompt_tokens: Integer

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

total_tokens: Integer

Total number of tokens used (prompt + completion).

Retrieve run step

require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

run_step = openai.beta.threads.runs.steps.retrieve("step_id", thread_id: "thread_id", run_id: "run_id")

puts(run_step)
{
  "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
  }
}