Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation
Theme

List agent sessions

beta.agents.sessions.list(**kwargs) -> SyncCursorPage[AgentSession]
GET
/agents/sessions

Lists managed agent sessions using ID-based pagination and the requested sort order. See managing sessions.

Parameters
after: Optional[str]

Return resources after this resource ID in the selected order.

minLength0
maxLength1048576
agent_id: Optional[str]

Only return sessions whose root agent has this ID. Omit to return sessions for all agents.

minLength0
maxLength1048576
limit: Optional[int]

The maximum number of resources to return, between 1 and 100. Defaults to 20.

formatint64
minimum1
maximum100
metadata: Optional[Dict[str, str]]

Exact string matches supplied as metadata[key]=value. All supplied pairs must match. Up to 16 pairs, with keys from 1 to 64 characters and values up to 512 characters. New sessions and metadata updates may take time to appear in filtered results.

order: Optional[Literal["asc", "desc"]]

The order in which resources are returned. Defaults to desc.

Returns
class AgentSession: …

A Managed Agents session.

id: str

The ID of the session.

minLength0
agent: Agent

The agent running in the session.

created_at: int

The Unix timestamp, in seconds, when the session was created.

formatint64
environment: Environment

The execution environment for the session.

error: Optional[str]

The error that caused the session to fail, if any.

minLength0
last_active_at: int

The Unix timestamp, in seconds, when the session was last active.

formatint64
metadata: Dict[str, str]

Custom string key-value pairs attached to the session.

object: Literal["agent.session"]

The object type. Always agent.session.

required_actions: List[RequiredAction]

Actions that must be completed before the session can continue.

minItems0
maxItems2000
status: Literal["idle", "in_progress", "requires_action", "failed"]

The current status of the session.

usage: Optional[TokenUsage]

Best-effort token usage for the session, or null if unknown. Recorded usage may change.

vault_ids: List[str]

The IDs of vaults made available to the session.

minItems0
maxItems2000
prompt_cache_options: Optional[PromptCacheOptions]

Default prompt cache lifetime for turns in this session, when configured.

review: Optional[Literal["none", "auto_review"]]

Review applied to eligible actions in this session. Omitted when review is none and automatic review is not enabled. Omission means none.

spend_control: Optional[SpendControl]

Configured spending limit and best-effort consumption, in USD cents. Unlimited sessions omit this object.

List agent sessions

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
page = client.beta.agents.sessions.list()
page = page.data[0]
print(page.id)
200 — Example
{
  "data": [
    {
      "id": "id",
      "agent": {
        "id": "id",
        "instructions": "instructions",
        "model": "model",
        "multi_agent": {
          "enabled": true,
          "max_concurrent_subagents": 1
        },
        "name": "name",
        "reasoning": {
          "effort": "none",
          "summary": "concise"
        },
        "service_tier": "auto",
        "text": {
          "format": {
            "type": "text"
          },
          "verbosity": "low"
        },
        "tools": [
          {
            "defer_loading": true,
            "description": "description",
            "name": "name",
            "parameters": {
              "foo": "bar"
            },
            "type": "function",
            "async": true
          }
        ],
        "compaction": {
          "async": true
        },
        "experimental": {
          "time_awareness": true
        }
      },
      "created_at": 0,
      "environment": {
        "type": "none"
      },
      "error": "error",
      "last_active_at": 0,
      "metadata": {
        "foo": "string"
      },
      "object": "agent.session",
      "required_actions": [
        {
          "request": {
            "credential_origin": "credential_origin",
            "fields": [
              {
                "id": "id",
                "label": "label",
                "required": true,
                "type": "type"
              }
            ],
            "options": [
              {
                "id": "id",
                "field_ids": [
                  "string"
                ],
                "label": "label"
              }
            ],
            "reason": "reason",
            "type": "browser_authentication"
          },
          "request_id": "request_id",
          "turn_id": "turn_id",
          "type": "computer_use_approval_request"
        }
      ],
      "status": "idle",
      "usage": {
        "input_tokens": 0,
        "input_tokens_details": {
          "cached_tokens": 0
        },
        "output_tokens": 0,
        "output_tokens_details": {
          "reasoning_tokens": 0
        },
        "total_tokens": 0
      },
      "vault_ids": [
        "string"
      ],
      "prompt_cache_options": {
        "ttl": "30m"
      },
      "review": "none",
      "spend_control": {
        "consumed": 0,
        "limit": 1
      }
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id",
  "object": "list"
}
Returns Examples
200 — Example
{
  "data": [
    {
      "id": "id",
      "agent": {
        "id": "id",
        "instructions": "instructions",
        "model": "model",
        "multi_agent": {
          "enabled": true,
          "max_concurrent_subagents": 1
        },
        "name": "name",
        "reasoning": {
          "effort": "none",
          "summary": "concise"
        },
        "service_tier": "auto",
        "text": {
          "format": {
            "type": "text"
          },
          "verbosity": "low"
        },
        "tools": [
          {
            "defer_loading": true,
            "description": "description",
            "name": "name",
            "parameters": {
              "foo": "bar"
            },
            "type": "function",
            "async": true
          }
        ],
        "compaction": {
          "async": true
        },
        "experimental": {
          "time_awareness": true
        }
      },
      "created_at": 0,
      "environment": {
        "type": "none"
      },
      "error": "error",
      "last_active_at": 0,
      "metadata": {
        "foo": "string"
      },
      "object": "agent.session",
      "required_actions": [
        {
          "request": {
            "credential_origin": "credential_origin",
            "fields": [
              {
                "id": "id",
                "label": "label",
                "required": true,
                "type": "type"
              }
            ],
            "options": [
              {
                "id": "id",
                "field_ids": [
                  "string"
                ],
                "label": "label"
              }
            ],
            "reason": "reason",
            "type": "browser_authentication"
          },
          "request_id": "request_id",
          "turn_id": "turn_id",
          "type": "computer_use_approval_request"
        }
      ],
      "status": "idle",
      "usage": {
        "input_tokens": 0,
        "input_tokens_details": {
          "cached_tokens": 0
        },
        "output_tokens": 0,
        "output_tokens_details": {
          "reasoning_tokens": 0
        },
        "total_tokens": 0
      },
      "vault_ids": [
        "string"
      ],
      "prompt_cache_options": {
        "ttl": "30m"
      },
      "review": "none",
      "spend_control": {
        "consumed": 0,
        "limit": 1
      }
    }
  ],
  "first_id": "first_id",
  "has_more": true,
  "last_id": "last_id",
  "object": "list"
}