Skip to content

Run steps (Deprecated)

Run steps describe the actions that an agent takes during a run, including model and tool calls. Important

The Assistant API is being deprecated. Migrate to the Responses API as an alternative. The Responses API includes multiple built-in tools and supports multi-turn context management.

List run steps

Returns a list of all steps for a run task.

Sample request

HTTP

HELPCODEESCAPE-curl
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396/steps?limit=20&order=asc' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

SDK

Python

HELPCODEESCAPE-python
import dashscope
from dashscope import Steps
import os

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
steps = Steps.list(
    'run_id',
    # We recommend setting the API key as an environment variable. If not, replace `api_key=os.getenv(...)` with `api_key="your_api_key"`.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    thread_id='thread_id',
    limit=20
)

Java

HELPCODEESCAPE-java
import com.alibaba.dashscope.common.GeneralListParam;
import com.alibaba.dashscope.common.ListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.RunStep;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    static {
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
    }
    public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
        Runs runs = new Runs();
        // We recommend setting the API key as an environment variable. If not, replace `apiKey(System.getenv(...))` with `apiKey("your_api_key")`.
        GeneralListParam listSteps = GeneralListParam.builder()
                .apiKey(System.getenv("DASHSCOPE_API_KEY"))
                .build();
        ListResult<RunStep> run = runs.listSteps("threadId", "runId", listSteps);
    }
}

Request body

Parameter NameTypeRequiredDefaultDescription
run_idstringYesThe ID of the Run for which you want to list the steps.
thread_idstringYesThe ID of the Thread.
limitintegerNoNoneThe number of running steps to retrieve. The default is None. A value of None uses the server-side default value.
orderstringNoNoneThe order in which to sort the results based on the created_at field. You can set this parameter to asc (ascending) or desc (descending). The default value is None, which indicates that the server-side default sorting method is used.
afterstringNoNoneID of the run step to use as a cursor for pagination. When provided, returns the page of results immediately after this step.
beforestringNoNoneID of the run step to use as a cursor for pagination. When provided, returns the page of results immediately before this step.
workspacestringYesNoneThe Workspace ID for Alibaba Cloud Model Studio is required only if the `api_key` is an API key for a sub-workspace.
api_keystringYesNoneThe API Key of Model Studio. We recommend that you configure the API Key as an environment variable.

Sample response

HELPCODEESCAPE-json
{
    "object": "list",
    "data": [
        {
            "id": "[REDACTED]",
            "object": "thread.run.step",
            "created_at": 1711517599333,
            "assistant_id": "[REDACTED]",
            "thread_id": "[REDACTED]",
            "run_id": "[REDACTED]",
            "type": "message_creation",
            "status": "completed",
            "step_details": {
                "type": "message_creation",
                "message_creation": {
                    "message_id": "[REDACTED]"
                }
            },
            "last_error": {
                "code": "",
                "message": ""
            },
            "expired_at": 0,
            "cancelled_at": -1,
            "failed_at": -1,
            "completed_at": -1,
            "metadata": {},
            "usage": {}
        }
    ],
    "first_id": "[REDACTED]",
    "last_id": "[REDACTED]",
    "has_more": false,
    "request_id": "[REDACTED]"
}

Response body

A list of run step objects

Retrieve a run step

Sample request

HTTP

Sample code

HELPCODEESCAPE-curl
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396/steps/step_4db180b5-d44a-4b12-9390-4307c6cb87a5' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

SDK

Sample code Python

HELPCODEESCAPE-python
import dashscope
from dashscope import Steps
import os

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'

step = Steps.retrieve(
    'step_id',
    # We recommend setting the API key as an environment variable. If not, replace `api_key=os.getenv(...)` with `api_key="your_api_key"`.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    thread_id='thread_id',
    run_id='run_id'
)

Java

HELPCODEESCAPE-java
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.RunStep;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;

public class Main {
    static {
        Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
    }
    public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
        Runs runs = new Runs();
        // We recommend setting the API key as an environment variable. If not, replace `apiKey=System.getenv(...)` with `apiKey="your_api_key"`.
        String apiKey = System.getenv("DASHSCOPE_API_KEY");
        RunStep run = runs.retrieveStep("threadId", "runId", "stepId", apiKey);
    }
}

Request body

Parameter nameTypeRequiredDefaultDescription
step_idstringYesThe ID of the RunStep to retrieve.
thread_idstringYesThe ID of the Thread.
run_idstringYesThe ID of the Run.
workspacestringYesNoneThe Workspace ID for Alibaba Cloud Model Studio is required only if you are using a sub-workspace API Key.
api_keystringYesNoneThe API Key of Model Studio. We recommend that you configure the API Key as an environment variable.

Sample response

HELPCODEESCAPE-json
{
    "assistant_id": "[REDACTED]",
    "cancelled_at": null,
    "completed_at": 1735025124000,
    "created_at": 1735025123150,
    "expired_at": null,
    "failed_at": null,
    "id": "[REDACTED]",
    "last_error": null,
    "metadata": {},
    "object": "thread.run.step",
    "request_id": "[REDACTED]",
    "run_id": "[REDACTED]",
    "status": "completed",
    "step_details": {
        "message_creation": {
            "message_id": "[REDACTED]"
        },
        "type": "message_creation"
    },
    "thread_id": "[REDACTED]",
    "type": "message_creation",
    "usage": null
}

Response body

The run step object that matches the specified ID.

Run step object

Represents a step in the execution process of a run.

Object example

HELPCODEESCAPE-json
{
  "id": "[REDACTED]",
  "assistant_id": "[REDACTED]",
  "cancelled_at": null,
  "completed_at": 1678886400,
  "created_at": 1678886300,
  "expired_at": null,
  "failed_at": null,
  "last_error": null,
  "metadata": {
    "user_id": "[REDACTED]",
    "context": "order_processing"
  },
  "object": "thread.run.step",
  "run_id": "[REDACTED]",
  "status": "completed",
  "step_details": {
    "type": "message_creation",
    "message_creation": {
      "message_id": "[REDACTED]"
    }
  },
  "thread_id": "[REDACTED]",
  "type": "message_creation",
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 20,
    "total_tokens": 30
  }
}

Object attributes

Parameter NameTypeDescription
idstringThe unique identifier of the run step, which can be referenced in API endpoints.
assistant_idstringThe ID of the assistant associated with this run step.
cancelled_atintegerThe 13-digit UNIX timestamp (in milliseconds) when the run step was canceled.
completed_atintegerThe 13-digit UNIX timestamp (in milliseconds) when the run step was completed.
created_atintegerThe 13-digit UNIX timestamp (in milliseconds) when the run step was created.
expired_atintegerThe 13-digit UNIX timestamp (in milliseconds) when the run step expired. If the parent run has expired, the step is also considered expired.
failed_atintegerThe 13-digit UNIX timestamp (in milliseconds) when the run step failed.
last_errorobjectThe last error associated with this run step. This parameter is null if no error occurred.
metadatamapA set of up to 16 key-value pairs that can be attached to the object. This is used to store additional information about the object in a structured format. The maximum length of a key is 64 characters and the maximum length of a value is 512 characters.
objectstringThe object type, which is always thread.run.step.
run_idstringThe ID of the run to which this run step belongs.
statusstringThe status of the run step. Valid values: in_progress, cancelled, failed, completed, or expired.
step_detailsobjectThe details of the run step.
thread_idstringThe ID of the running thread.
typestringThe type of the run step. Valid values: message_creation or tool_calls.
usageobjectResource usage statistics.
status_codeintegerThe HTTP status code. Note: This parameter is used for internal processing. In most cases, you do not need to concern yourself with this parameter.

Error codes

If a call fails and returned an error message, see Error messages for troubleshooting.

Mirror of Alibaba Cloud Model Studio docs for reference and RAG. Not affiliated with Alibaba Cloud.