Skip to main content

List turns

List root agent turns and verify execution status and token usage.

Endpoint

GET /agents/sessions/{session_id}/turns Returns the root agent's turn list. Returns 200 on success. The query does not start a model, resume execution, or create resources.

Path parameters

FieldRequiredTypeDescription
session_idYesstringSession ID, for example sess_xxx

Request parameters

FieldRequiredTypeDescription
limitNointegerPage size, range 1–100, default 20
orderNostringSort direction, asc or desc, default desc
afterNostringThe last_id from the previous page; the cursor item is excluded
before is ignored and is not used for reverse pagination. Use order and after to page.

Request example

curl --get "$BASE_URL/agents/sessions/sess_xxx/turns" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --data-urlencode "limit=20" \
  --data-urlencode "order=asc"

Response example

{
  "object": "list",
  "data": [
    {
      "id": "turn_xxx",
      "object": "agent.session.turn",
      "session_id": "sess_xxx",
      "agent_id": "agent_xxx",
      "subagent_id": null,
      "status": "completed",
      "created_at": 1794118835,
      "started_at": 1794118836,
      "completed_at": 1794118840,
      "error": null,
      "usage": {
        "input_tokens": 1024,
        "input_tokens_details": {"cached_tokens": 0},
        "output_tokens": 256,
        "output_tokens_details": {"reasoning_tokens": 64},
        "total_tokens": 1280
      }
    }
  ],
  "first_id": "turn_xxx",
  "last_id": "turn_xxx",
  "has_more": false
}
{
  "object": "list",
  "data": [],
  "first_id": null,
  "last_id": null,
  "has_more": false
}

Response fields

List envelope: usage contains input_tokens, input_tokens_details.cached_tokens, output_tokens, output_tokens_details.reasoning_tokens, and total_tokens. If the related counts are incomplete, the entire usage is null.
FieldTypeDescription
objectstringList object type, fixed as list
dataarray<Turn>Turns on this page; [] when empty
first_idstring / nullFirst turn ID on this page; null for an empty page
last_idstring / nullLast turn ID on this page; null for an empty page; use it as after
has_morebooleanWhether the current scan direction has another page
idstringPublic turn ID
objectstringTurn object type, fixed as agent.session.turn
session_idstringOwning session
agent_idstringExecuting agent
subagent_idstring / nullSubagent ID, null for a root turn
statusstringTurn status: in_progress, waiting, completed, failed, or cancelled
created_atintegerCreation time, Unix seconds
started_at / completed_atinteger / nullStart and completion time, Unix seconds. null before the boundary
errorobject / nullTurn-level error.
error.codestringError code
error.messagestringError description
usageobject / nullToken usage.
usage.input_tokensintegerNumber of input tokens
usage.input_tokens_detailsobjectInput token details.
usage.input_tokens_details.cached_tokensintegerNumber of input tokens that hit the cache
usage.output_tokensintegerNumber of output tokens
usage.output_tokens_detailsobjectOutput token details.
usage.output_tokens_details.reasoning_tokensintegerNumber of reasoning tokens
usage.total_tokensintegerTotal number of tokens
Turn fields: waiting is not a successful terminal state. completed, failed, and cancelled are terminal. The SSE turn.created event can show queued; persisted turns start at in_progress.

Error codes

HTTP statusError type / codeSolution
400invalid_request_error / invalid_request_errorFix limit and order as described in the query parameters
404not_found_error / not_found_errorUse a valid session ID; use the last_id returned by the previous page as after
502server_error / agents_api_upstream_unavailableRetry later. If it keeps failing, submit a ticket with the x-request-id from the response headers