Retrieve Session

Updated at:

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

GET/sessions/{session_id}

Path parameters

session_idstringRequired

Session ID, format sesn_<ULID>

Response fields

The response is a Session object with the following fields:

idstring

Session ID, format sesn_<ULID>

typestring

Fixed as session

statusstring

Session status: idle / running / terminated

stop_reasonobject / null

The 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

typestring

end_turn / requires_action / retries_exhausted

pending_batch_idstring

Pending tool approval batch ID

pending_call_idsarray<string>

Tool call IDs awaiting a decision

agentobject

Full agent configuration snapshot, including id/version/name/model/system/tools, etc.; session-level overrides (if any) are merged into the snapshot

agent properties

idstring

Agent ID, format agent_xxx

versioninteger

Version to pin; latest if omitted

environment_idstring

The bound environment ID

sandboxobject

Sandbox snapshot persistence configuration and current snapshot state. Omitted when not configured

enable_snapshotboolean

Whether snapshot persistence is enabled for the current session

snapshot_persistent_secondsinteger

Retention period of the configured snapshot in seconds; omitted when not configured

is_persistingboolean

Whether the current session is retaining an available snapshot; may be omitted before statistics are available

predict_release_timestring / null

Expected release time of the current snapshot in ISO 8601 UTC; null when there is no current snapshot

usage.sandboxobject

Sandbox 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 / null

Cumulative retained hours of historical snapshots; null when no statistics are available

latest_snapshot_persisted_hoursinteger / null

Retained hours of the latest snapshot; null when there is no current snapshot

titlestring

Session title

metadataobject

Custom business key-value pairs

archived_atstring / null

Archive time; null when not archived

created_atstring

Creation time (ISO 8601)

updated_atstring

Last update time (ISO 8601)

environment_variablesobject

Environment variables injected into the session runtime as string key-value pairs; sandbox code can read them directly by name

vault_idsarray of string

Bound vault ID list

mcp_configsarray of object

Session-level MCP request headers; each item contains mcp_server_name and headers. Empty array when not configured

mcp_configs properties

providerstring

default or agentstudio_memory

entity_idstring

Entity ID for the Bailian memory binding

project_idsarray<string>

Bailian memory project IDs; defaults apply when omitted or empty

profile_schemastring

User profile schema ID

memory_store_idstring

Memory store ID

accessstring

Memory store access mode

instructionsstring

Memory 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
    }
  }
}