List sessions
List sessions in the current workspace with pagination, optionally filtered by agent.
Endpoint
Returns 200 and a list envelope. data is an array of Session objects.
/agents/sessionsQuery parameters
limitintegerOptionalNumber of items per page, default 20, range 1..100; an empty string or a value outside the range returns 400
orderstringOptionalSort direction, asc or desc, default desc; an invalid value returns 400
afterstringOptionalResource ID cursor, up to 256 bytes and not blank; the cursor item is excluded
agent_idstringOptionalAgent ID filter, filter by saved or inline agent ID, an explicit empty value is invalid, and duplicates return 400
For the first page, omit after. For later pages, pass the last_id from the previous response. The list is sorted by (created_at, resource ID). Other unknown query parameters such as before are ignored; use order and after for reverse pagination.
A newly created session may not appear in the list immediately. To confirm the latest state, use Retrieve Session. The list does not provide a global snapshot or immediate visibility guarantee.
Request example
curl -sS "$BASE_URL/agents/sessions?limit=20&order=desc&agent_id=agent_xxx" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "OpenAI-Beta: agents=v1"
page = client.beta.agents.sessions.list(
limit=20,
order="desc",
agent_id="agent_xxx",
)
for session in page.data:
print(session.id, session.status)
Response fields
objectstringList object type, fixed as list
dataarraySession objects on this page; [] when empty
first_idstring / nullID of the first item; null for an empty page
last_idstring / nullID of the last item; null for an empty page; use it for the next after
has_morebooleanWhether the current scan direction has another page
Session fields
idstringSession ID; reuse it for follow-up turns
objectstringSession object type, fixed as agent.session
created_atintegerCreation time in Unix seconds
last_active_atintegerLast activity time in Unix seconds; not a version number or lock
statusstringSession status: idle, in_progress, requires_action, or failed
agentobjectEffective agent snapshot.
Properties
idstringAgent ID; inline configurations return a session snapshot ID, not a reusable saved agent, and it cannot be retrieved through Agent GET
modelstringModel ID
instructionsstring / nullCustom instructions
namestring / nullDisplay name
reasoningobject / nullReasoning configuration, contains effort and summary
textobject / nullText output configuration; contains format and verbosity
toolsarrayTool configuration
multi_agentobject / nullSubagent configuration; contains enabled and max_concurrent_subagents
environmentobjectSafe environment summary; only type for none.
Properties
typestringEnvironment type; none or openai_hosted
idstringEnvironment ID, omitted when there is no authoritative value
statusstringEnvironment status: omitted when there is no authoritative value
environment_template_idstringEnvironment template ID, omitted when there is no authoritative value
workspace_directorystringWorkspace directory, omitted when there is no authoritative value
errorstring / nullEnvironment error description, omitted when there is no authoritative value
desktopobject / nullDesktop settings; contains enabled
capability_directoriesarray<string> / nullCapability discovery directories
networkobject / nullNetwork policy; contains access and allowed_domains
packagesobject / nullPackage lists; contains npm, python, and system
filesarraySafe environment file metadata
skillsarraySafe skill metadata
pluginsarrayPlugin information; [] for managed environments
metadataobjectSession metadata; an empty value is {}
vault_idsarray<string>Vault IDs recorded at creation; this does not mean mounting is complete
required_actionsarrayFunction calls that need client handling; [] when empty.
Properties
typestringItem type, fixed as function_call
turn_idstringPublic turn ID
call_idstringFunction call ID
namestringFunction name
argumentsobjectParsed call arguments
errorstring / nullSession-level error message, different from a turn's structured error
usageobject / nullToken usage.
Properties
input_tokensintegerNumber of input tokens
input_tokens_detailsobjectInput token details.
Properties
cached_tokensintegerNumber of input tokens that hit the cache
output_tokensintegerNumber of output tokens
output_tokens_detailsobjectOutput token details.
Properties
reasoning_tokensintegerNumber of reasoning tokens
total_tokensintegerTotal number of tokens
spend_controlobjectSpend control; returned only when a historical record has a value; creation and update do not accept writes.
Properties
limitintegerSpending limit in cents
consumedinteger / nullConsumed amount in cents
null when the fields are incomplete.
Response example
{
"object": "list",
"data": [],
"first_id": null,
"last_id": null,
"has_more": false
}
Error codes
Business errors return an error object with type, code, message, and param. Common errors:
| HTTP status | Error type / code | Solution |
|---|---|---|
400 | invalid_request_error / invalid_request_error | Fix limit, order, and agent_id as described, and remove duplicate parameters |
401 | authentication_error / invalid_api_key | Send a valid Authorization: Bearer $DASHSCOPE_API_KEY header |
404 | not_found_error / not_found_error | Confirm that the parent resource exists in the current workspace; use the last_id from the previous page as after |
502 | server_error / agents_api_upstream_unavailable | Retry later. If it keeps failing, submit a ticket with the x-request-id from the response headers |