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

Retrieve an agent session

AgentSession beta().agents().sessions().retrieve(params = SessionRetrieveParams.none(), requestOptions = RequestOptions.none())
GET
/agents/sessions/{session_id}

Retrieves the current state of a managed agent session. See managing sessions.

Retrieve an agent session

package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.agents.AgentSession;
import com.openai.models.beta.agents.sessions.SessionRetrieveParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        AgentSession agentSession = client.beta().agents().sessions().retrieve("session_id");
    }
}
200 — Example
{
  "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": {
        "arguments": {},
        "message": "message",
        "name": "name",
        "server_label": "server_label",
        "type": "mcp_tool_call"
      },
      "request_id": "request_id",
      "turn_id": "turn_id",
      "type": "mcp_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"
}
Parameters
SessionRetrieveParams params
Optional<String> sessionId
minLength0
maxLength1048576
Returns
class AgentSession:

A Managed Agents session.

String id

The ID of the session.

minLength0
Agent agent

The agent running in the session.

long createdAt

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

formatint64
Environment environment

The execution environment for the session.

Optional<String> error

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

minLength0
long lastActiveAt

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

formatint64
Metadata metadata

Custom string key-value pairs attached to the session.

JsonValue; object_
constant
constant

The object type. Always agent.session.

List<RequiredAction> requiredActions

Actions that must be completed before the session can continue.

minItems0
maxItems2000
Status status

The current status of the session.

Optional<TokenUsage> usage

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

List<String> vaultIds

The IDs of vaults made available to the session.

minItems0
maxItems2000
Optional<PromptCacheOptions> promptCacheOptions

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

Optional<Review> review

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

Returns Examples
200 — Example
{
  "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": {
        "arguments": {},
        "message": "message",
        "name": "name",
        "server_label": "server_label",
        "type": "mcp_tool_call"
      },
      "request_id": "request_id",
      "turn_id": "turn_id",
      "type": "mcp_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"
}