## Retrieve an agent session

`AgentSession beta().agents().sessions().retrieve(SessionRetrieveParamsparams = SessionRetrieveParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**get** `/agents/sessions/{session_id}`

Retrieves the current state of a managed agent session. See [managing sessions](/api/docs/guides/agents-api/sessions/manage).

### Parameters

- `SessionRetrieveParams params`

  - `Optional<String> sessionId`

    `minLength: 0`, `maxLength: 1048576`

### Returns

- `class AgentSession:`

  A Managed Agents session.

  - `String id`

    The ID of the session.

    `minLength: 0`

  - `Agent agent`

    The agent running in the session.

    - `String id`

      The ID of the agent.

      `minLength: 0`

    - `Optional<String> instructions`

      Custom instructions appended to the agent's default base instructions.

      `minLength: 0`

    - `String model`

      The model used by the agent.

      `minLength: 0`

    - `MultiAgentConfig multiAgent`

      Configuration for creating and coordinating subagents.

      - `boolean enabled`

        Whether subagent tools are enabled. Defaults to false.

      - `Optional<Long> maxConcurrentSubagents`

        Maximum number of subagents that may run concurrently, or null when disabled. Defaults to 6 when enabled.

        `format: int64`, `minimum: 1`, `maximum: 4294967295`

    - `Optional<String> name`

      The reusable agent's name when the session was created, or null if no name was saved. Later changes to the agent's name do not affect this value.

      `minLength: 0`

    - `AgentReasoning reasoning`

      The agent's reasoning configuration.

      - `Optional<Effort> effort`

        The requested reasoning effort, or `null` when the model selects its own default.

        - `NONE("none")`

        - `MINIMAL("minimal")`

        - `LOW("low")`

        - `MEDIUM("medium")`

        - `HIGH("high")`

        - `XHIGH("xhigh")`

        - `MAX("max")`

      - `Optional<Summary> summary`

        The requested reasoning summary format, or `null` when summaries are disabled.

        - `CONCISE("concise")`

          Returns a concise reasoning summary when supported.

        - `DETAILED("detailed")`

          Returns a detailed reasoning summary when supported.

        - `AUTO("auto")`

          Automatically selects the most detailed summary supported by the model.

    - `ServiceTier serviceTier`

      The effective service-tier policy for model requests. Defaults to `auto`.

      - `AUTO("auto")`

      - `DEFAULT("default")`

      - `FLEX("flex")`

      - `PRIORITY("priority")`

      - `FAST("fast")`

      - `ULTRAFAST("ultrafast")`

    - `AgentText text`

      Configuration for text generated by the agent.

      - `TextFormat format`

        The effective output format. Defaults to ordinary text.

        - `JsonValue;`

          - `JsonValue; type "text"constant`

            The type of the object. Always `text`.

            - `TEXT("text")`

        - `JsonSchema`

          - `Schema schema`

            The JSON Schema that generated text must match.

          - `JsonValue; type "json_schema"constant`

            The type of the object. Always `json_schema`.

            - `JSON_SCHEMA("json_schema")`

      - `Verbosity verbosity`

        The amount of text produced by the agent. Defaults to `medium`.

        - `LOW("low")`

        - `MEDIUM("medium")`

        - `HIGH("high")`

    - `List<AgentTool> tools`

      Tools available to the agent.

      `minItems: 0`, `maxItems: 2000`

      - `Function`

        - `boolean deferLoading`

          Whether the function is deferred and discovered through tool search.

        - `String description`

          A description of what the function does.

          `minLength: 0`

        - `String name`

          The name of the function.

          `minLength: 0`

        - `Parameters parameters`

          A JSON Schema object describing the function's arguments.

        - `JsonValue; type "function"constant`

          The type of the object. Always `function`.

          - `FUNCTION("function")`

        - `Optional<Boolean> async`

          Whether the agent continues without waiting for the function result.

      - `ProgrammaticToolCalling`

        - `boolean enabled`

          Whether tools can be called from model-generated code.

        - `JsonValue; type "programmatic_tool_calling"constant`

          The type of the object. Always `programmatic_tool_calling`.

          - `PROGRAMMATIC_TOOL_CALLING("programmatic_tool_calling")`

      - `Mcp`

        - `Optional<List<String>> allowedTools`

          The MCP tools the agent may call.

          `minItems: 0`, `maxItems: 2000`

        - `ConnectionOrigin connectionOrigin`

          Where outbound MCP HTTP connections originate.

          - `SERVICE("service")`

          - `ENVIRONMENT("environment")`

        - `Optional<String> credentialId`

          The attached vault credential selected for this MCP server, if any. Optional when exactly one attached credential matches the server URL.

          `minLength: 0`

        - `RequestMetadata requestMetadata`

          Metadata included with requests to this MCP server.

        - `boolean required`

          Whether this MCP server must initialize before the first turn.

        - `String serverLabel`

          A label used to identify the MCP server in tool calls.

          `minLength: 0`

        - `McpTransport transport`

          The transport used to connect to the MCP server.

          - `Http`

            - `String serverUrl`

              The URL of the MCP server.

              `minLength: 0`

            - `JsonValue; type "http"constant`

              The type of the object. Always `http`.

              - `HTTP("http")`

          - `Stdio`

            - `List<String> args`

              Arguments passed to the MCP server command.

              `minItems: 0`, `maxItems: 2000`

            - `String command`

              The command used to start the MCP server.

              `minLength: 0`

            - `String cwd`

              The working directory used to start the MCP server.

              `minLength: 0`

            - `List<String> envVars`

              Environment variable names inherited from the execution environment.

              `minItems: 0`, `maxItems: 2000`

            - `JsonValue; type "stdio"constant`

              The type of the object. Always `stdio`.

              - `STDIO("stdio")`

        - `JsonValue; type "mcp"constant`

          The type of the object. Always `mcp`.

          - `MCP("mcp")`

      - `WebSearch`

        - `Optional<List<String>> allowedDomains`

          Allowed search domains, or `null` when the search is unrestricted.

          `minItems: 0`, `maxItems: 2000`

        - `ContextSize contextSize`

          The amount of search context made available to the model. Defaults to `medium`.

          - `LOW("low")`

          - `MEDIUM("medium")`

          - `HIGH("high")`

        - `Optional<Location> location`

          Approximate location used to localize search results, if provided.

          - `Optional<String> city`

            The city name.

            `minLength: 0`

          - `Optional<String> country`

            The two-letter ISO country code, such as `US`.

            `minLength: 0`

          - `Optional<String> region`

            The region or state name.

            `minLength: 0`

          - `Optional<String> timezone`

            The IANA timezone, such as `America/Los_Angeles`.

            `minLength: 0`

        - `Mode mode`

          The source used for web search results.

          - `DISABLED("disabled")`

          - `CACHED("cached")`

          - `LIVE("live")`

        - `JsonValue; type "web_search"constant`

          The type of the object. Always `web_search`.

          - `WEB_SEARCH("web_search")`

      - `ComputerUse`

        - `boolean includeScreenshots`

          Whether computer tool outputs include screenshots.

        - `JsonValue; type "computer_use"constant`

          The type of the object. Always `computer_use`.

          - `COMPUTER_USE("computer_use")`

      - `JsonValue;`

        - `JsonValue; type "automations"constant`

          The type of the object. Always `automations`.

          - `AUTOMATIONS("automations")`

    - `Optional<Compaction> compaction`

      The effective context compaction settings.

      - `boolean async`

        Whether context is compacted in the background. Defaults to true.

    - `Optional<Experimental> experimental`

      The effective experimental settings for the agent.

      - `boolean timeAwareness`

        Whether the model receives periodic current-time reminders.

  - `long createdAt`

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

    `format: int64`

  - `Environment environment`

    The execution environment for the session.

    - `JsonValue;`

      - `JsonValue; type "none"constant`

        The type of the object. Always `none`.

        - `NONE("none")`

    - `OpenAIHosted`

      - `String id`

        The public ID of the environment.

        `minLength: 0`

      - `List<String> capabilityDirectories`

        Directories that contain capabilities exposed to the agent.

        `minItems: 0`, `maxItems: 2000`

      - `List<HostedEnvironmentFile> files`

        Files available in the environment, excluding their contents.

        `minItems: 0`, `maxItems: 50`

        - `class HostedEnvironmentFileId:`

          A file copied from the OpenAI Files API.

          - `String id`

            The session-scoped ID of the file in the execution environment.

            `minLength: 0`

          - `String fileId`

            The ID of the uploaded file.

            `minLength: 0`

          - `String path`

            The file's absolute path inside the environment.

            `minLength: 0`

          - `long sizeBytes`

            The decoded file size in bytes.

            `format: int64`, `minimum: 0`

          - `JsonValue; type "file_id"constant`

            The type of the object. Always `file_id`.

            - `FILE_ID("file_id")`

        - `Inline`

          - `String id`

            The session-scoped ID of the file in the execution environment.

            `minLength: 0`

          - `String path`

            The file's absolute path inside the environment.

            `minLength: 0`

          - `long sizeBytes`

            The decoded file size in bytes.

            `format: int64`, `minimum: 0`

          - `JsonValue; type "inline"constant`

            The type of the object. Always `inline`.

            - `INLINE("inline")`

      - `Network network`

        The effective network access policy for the environment.

        - `Access access`

          The environment's network access mode.

          - `ENABLED("enabled")`

            Allows unrestricted network access.

          - `DISABLED("disabled")`

            Disables network access.

          - `RESTRICTED("restricted")`

            Applies the configured domain restrictions.

        - `List<String> allowedDomains`

          Domains the environment may access when network access is restricted.

          `minItems: 0`, `maxItems: 2000`

      - `Packages packages`

        Packages installed in the environment.

        - `List<String> npm`

          npm packages installed globally in the environment.

          `minItems: 0`, `maxItems: 16384`

        - `List<String> python`

          Python packages installed in the environment.

          `minItems: 0`, `maxItems: 16384`

        - `List<String> system`

          System packages installed in the environment.

          `minItems: 0`, `maxItems: 16384`

      - `List<HostedPlugin> plugins`

        Plugins installed in the environment, excluding their archive contents.

        `minItems: 0`, `maxItems: 2000`

        - `String description`

          The installed plugin description.

          `minLength: 0`

        - `String name`

          The installed plugin name.

          `minLength: 0`

        - `JsonValue; type "inline"constant`

          The type of the object. Always `inline`.

          - `INLINE("inline")`

      - `List<HostedSkill> skills`

        Skills installed in the environment, excluding their archive contents.

        `minItems: 0`, `maxItems: 2000`

        - `class HostedSkillReference:`

          A skill installed from the Skills API.

          - `String description`

            The installed skill description.

            `minLength: 0`

          - `String name`

            The installed skill name.

            `minLength: 0`

          - `String skillId`

            The referenced skill ID.

            `minLength: 0`

          - `JsonValue; type "skill_reference"constant`

            The type of the object. Always `skill_reference`.

            - `SKILL_REFERENCE("skill_reference")`

          - `String version`

            The concrete skill version installed for this session.

            `minLength: 0`

        - `Inline`

          - `String description`

            The installed skill description.

            `minLength: 0`

          - `String name`

            The installed skill name.

            `minLength: 0`

          - `JsonValue; type "inline"constant`

            The type of the object. Always `inline`.

            - `INLINE("inline")`

      - `JsonValue; type "openai_hosted"constant`

        The type of the object. Always `openai_hosted`.

        - `OPENAI_HOSTED("openai_hosted")`

      - `Optional<ContainerSize> containerSize`

        The effective CPU and memory tier, or null when unknown or outside the public tiers.

        - `SMALL("small")`

        - `MEDIUM("medium")`

        - `LARGE("large")`

      - `Optional<Desktop> desktop`

        The effective desktop configuration.

        - `boolean enabled`

          Whether the environment provisions a desktop and browser proxy.

    - `SelfHosted`

      - `String id`

        The public ID of the environment.

        `minLength: 0`

      - `List<String> capabilityDirectories`

        Directories that contain capabilities exposed to the agent.

        `minItems: 0`, `maxItems: 2000`

      - `String remoteUrl`

        Pass this URL unchanged to `codex exec-server --remote` when connecting this environment.

        `minLength: 0`

      - `JsonValue; type "self_hosted"constant`

        The type of the object. Always `self_hosted`.

        - `SELF_HOSTED("self_hosted")`

      - `String workspaceDirectory`

        The absolute project directory inside the environment. Defaults to `/workspace`.

        `minLength: 0`

  - `Optional<String> error`

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

    `minLength: 0`

  - `long lastActiveAt`

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

    `format: int64`

  - `Metadata metadata`

    Custom string key-value pairs attached to the session.

  - `JsonValue; object_ "agent.session"constant`

    The object type. Always `agent.session`.

    - `AGENT_SESSION("agent.session")`

  - `List<RequiredAction> requiredActions`

    Actions that must be completed before the session can continue.

    `minItems: 0`, `maxItems: 2000`

    - `class ComputerUseApprovalRequest:`

      Respond to a computer-use request.

      - `Request request`

        The information needed to render the request.

        - `class BrowserAuthentication:`

          A registered form awaiting the application's response.

          - `Optional<String> credentialOrigin`

            The registered form or frame origin where values will be entered.

            `minLength: 0`

          - `List<Field> fields`

            Controls to render. All submitted values are sensitive.

            `minItems: 0`, `maxItems: 2000`

            - `String id`

              The field ID to submit as field_id in a fields entry.

              `minLength: 0`

            - `String label`

              The label to display beside the control.

              `minLength: 0`

            - `boolean required`

              Whether this control requires a nonempty value.

            - `String type`

              The rendering type, such as email, password, or text.

              `minLength: 0`

          - `List<Option> options`

            Sign-in methods. Empty for a plain form.

            `minItems: 0`, `maxItems: 2000`

            - `String id`

              The option ID to submit as selected_option.

              `minLength: 0`

            - `List<String> fieldIds`

              IDs from the registered fields that this method accepts.

              `minItems: 0`, `maxItems: 2000`

            - `String label`

              The method label to display.

              `minLength: 0`

          - `Optional<String> reason`

            Why the agent needs the user to sign in.

            `minLength: 0`

          - `JsonValue; type "browser_authentication"constant`

            The type of the object. Always `browser_authentication`.

            - `BROWSER_AUTHENTICATION("browser_authentication")`

        - `class BrowserOriginAccess:`

          A browser origin awaiting the application's approval decision.

          - `String origin`

            The origin the browser needs permission to access.

            `minLength: 0`

          - `Optional<String> reason`

            The browser's explanation for this request, or null when unavailable.

            `minLength: 0`

          - `JsonValue; type "browser_origin_access"constant`

            The type of the object. Always `browser_origin_access`.

            - `BROWSER_ORIGIN_ACCESS("browser_origin_access")`

      - `String requestId`

        The registered request ID to echo when responding.

        `minLength: 0`

      - `String turnId`

        The turn that requested approval.

        `minLength: 0`

      - `JsonValue; type "computer_use_approval_request"constant`

        The type of the object. Always `computer_use_approval_request`.

        - `COMPUTER_USE_APPROVAL_REQUEST("computer_use_approval_request")`

    - `class FunctionCall:`

      Run a function tool and submit its result.

      - `JsonValue arguments`

        The arguments supplied by the model.

      - `String callId`

        The ID to include when submitting the function result.

        `minLength: 0`

      - `String name`

        The function name.

        `minLength: 0`

      - `String turnId`

        The ID of the turn that requested the function call.

        `minLength: 0`

      - `JsonValue; type "function_call"constant`

        The type of the object. Always `function_call`.

        - `FUNCTION_CALL("function_call")`

    - `class EnvironmentConnection:`

      Reconnect a session environment.

      - `String environmentId`

        The ID of the environment to reconnect.

        `minLength: 0`

      - `JsonValue; type "environment_connection"constant`

        The type of the object. Always `environment_connection`.

        - `ENVIRONMENT_CONNECTION("environment_connection")`

  - `Status status`

    The current status of the session.

    - `IDLE("idle")`

      The session has no turn in progress and is ready for input. A hosted environment may still be provisioning.

    - `IN_PROGRESS("in_progress")`

      The session is processing a turn.

    - `REQUIRES_ACTION("requires_action")`

      The session is waiting for one or more required actions.

    - `FAILED("failed")`

      The session failed.

  - `Optional<TokenUsage> usage`

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

    - `long inputTokens`

      The number of input tokens used by the agent.

      `format: int64`

    - `InputTokensDetails inputTokensDetails`

      A breakdown of the agent's input token usage.

      - `long cachedTokens`

        The number of input tokens retrieved from the prompt cache.

        `format: int64`

    - `long outputTokens`

      The number of output tokens generated by the agent.

      `format: int64`

    - `OutputTokensDetails outputTokensDetails`

      A breakdown of the agent's output token usage.

      - `long reasoningTokens`

        The number of output tokens used for reasoning.

        `format: int64`

    - `long totalTokens`

      The total number of input and output tokens used by the agent.

      `format: int64`

  - `List<String> vaultIds`

    The IDs of vaults made available to the session.

    `minItems: 0`, `maxItems: 2000`

  - `Optional<PromptCacheOptions> promptCacheOptions`

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

    - `Ttl ttl`

      - `_30M("30m")`

      - `_12H("12h")`

  - `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.

    - `NONE("none")`

    - `AUTO_REVIEW("auto_review")`

  - `Optional<SpendControl> spendControl`

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

    - `Optional<Long> consumed`

      Best-effort recorded spend floored to whole USD cents, or null when unavailable.

      `minimum: 0`

    - `long limit`

      The configured positive limit in USD cents.

      `format: int64`, `minimum: 1`, `maximum: 4503599627370495`

### Example

```java
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

```json
{
  "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
  }
}
```
