Retrieve Session
Returns session metadata, the embedded agent snapshot, and resource list. Event history and message content are retrieved through the Event API.
Prerequisites
Endpoint and authentication configuration must be completed. For details, see Overview and authentication.
Endpoint
/sessions/{session_id}Path parameters
session_idstringRequiredSession ID, format sesn_<ULID>
Response fields
The response is a Session object with the following fields:
idstringSession ID, format sesn_<ULID>
typestringFixed as session
statusstringSession status: idle / running / terminated
stop_reasonobject / nullThe reason the session returned to idle. A discriminated union: null (running, or idle and just created with no end reason yet) / {"type": "end_turn"} (model ended on its own) / {"type": "retries_exhausted"} (retries exhausted) / {"type": "requires_action", "pending_batch_id": "...", "pending_call_ids": [...]} (waiting for tool approval). Only meaningful when status is idle; null when running. terminated is a terminal state and the server may retain the previous value — clients should not rely on or interpret it. The requires_action branch carries a non-empty pending_batch_id and pending_call_ids; use them to locate the pending approval calls and fetch the corresponding tool_approval_request events via the Event API
stop_reason properties
typestringend_turn / requires_action / retries_exhausted
pending_batch_idstringPending tool approval batch ID
pending_call_idsarray<string>Tool call IDs awaiting a decision
agentobjectFull agent configuration snapshot, including id/version/name/model/system/tools, etc.; session-level overrides (if any) are merged into the snapshot
agent properties
idstringAgent ID, format agent_xxx
versionintegerVersion to pin; latest if omitted
environment_idstringThe bound environment ID
sandboxobjectSandbox snapshot persistence configuration and current snapshot state. Omitted when not configured
enable_snapshotbooleanWhether snapshot persistence is enabled for the current session
snapshot_persistent_secondsintegerRetention period of the configured snapshot in seconds; omitted when not configured
is_persistingbooleanWhether the current session is retaining an available snapshot; may be omitted before statistics are available
predict_release_timestring / nullExpected release time of the current snapshot in ISO 8601 UTC; null when there is no current snapshot
usage.sandboxobjectSandbox snapshot duration statistics. May be omitted in the Create response; when persistence is enabled but no snapshot has been created yet, the duration fields are null.
session_total_persisted_hoursinteger / nullCumulative retained hours of historical snapshots; null when no statistics are available
latest_snapshot_persisted_hoursinteger / nullRetained hours of the latest snapshot; null when there is no current snapshot
titlestringSession title
metadataobjectCustom business key-value pairs
archived_atstring / nullArchive time; null when not archived
created_atstringCreation time (ISO 8601)
updated_atstringLast update time (ISO 8601)
environment_variablesobjectEnvironment variables injected into the session runtime as string key-value pairs; sandbox code can read them directly by name
vault_idsarray of stringBound vault ID list
mcp_configsarray of objectSession-level MCP request headers; each item contains mcp_server_name and headers. Empty array when not configured
mcp_configs properties
providerstringdefault or agentstudio_memory
entity_idstringEntity ID for the Bailian memory binding
project_idsarray<string>Bailian memory project IDs; defaults apply when omitted or empty
profile_schemastringUser profile schema ID
memory_store_idstringMemory store ID
accessstringMemory store access mode
instructionsstringMemory usage instructions
Request example
curl "$AGENTSTUDIO_URL/sessions/sesn_xxx" \
-H "Authorization: Bearer $DASHSCOPE_API_KEY"
session = client.sessions.retrieve("sesn_xxx")
print(session.id, session.status, session.title)
Session session = client.sessions().retrieve("sesn_xxx");
System.out.println(session.getId() + " " + session.getStatus() + " " + session.getTitle());
Response example
{
"id": "sesn_xxx",
"type": "session",
"status": "idle",
"stop_reason": {
"type": "requires_action",
"pending_batch_id": "response_xxx:9f2c...",
"pending_call_ids": ["call_xxx"]
},
"agent": {
"id": "agent_xxx",
"type": "agent",
"version": 1,
"name": "data-analyst",
"description": null,
"model": {"id": "qwen3.7-max"},
"system": "You are a data analysis expert who uses pandas to process CSV files.",
"tools": []
},
"environment_id": "env_xxx",
"title": "Q3 sales data analysis",
"metadata": {"biz_ticket_id": "1234"},
"archived_at": null,
"created_at": "2026-05-28T08:23:11Z",
"updated_at": "2026-05-28T08:23:25Z",
"request_id": "xxx",
"environment_variables": {"API_BASE_URL": "https://api.example.com", "LOG_LEVEL": "info"},
"vault_ids": ["vlt_xxx"],
"mcp_configs": [{"mcp_server_name": "crm", "headers": {"X-Tenant-Id": "tenant-demo"}}]
}
Sandbox snapshot response examples
When an available snapshot exists:
{
"sandbox": {
"enable_snapshot": true,
"snapshot_persistent_seconds": 172800,
"is_persisting": true,
"predict_release_time": "2026-11-17T06:09:50Z"
},
"usage": {
"sandbox": {
"session_total_persisted_hours": 3,
"latest_snapshot_persisted_hours": 1
}
}
}
When persistence is enabled but no snapshot has been created yet:
{
"sandbox": {
"enable_snapshot": true,
"snapshot_persistent_seconds": 172800,
"is_persisting": false,
"predict_release_time": null
},
"usage": {
"sandbox": {
"session_total_persisted_hours": null,
"latest_snapshot_persisted_hours": null
}
}
}