## Create an agent session

`beta.agents.sessions.create(SessionCreateParams**kwargs)  -> AgentSession`

**post** `/agents/sessions`

Creates a managed agent session, optionally submits initial input, and returns the session or streams its events when stream is true. See [running sessions](/api/docs/guides/agents-api/sessions).

### Parameters

- `environment: EnvironmentParam`

  An inline execution environment or a reference to an environment template.

  - `class EnvironmentParamNone: …`

    Runs the agent without an execution environment.

    - `type: Literal["none"]`

      The type of the object. Always `none`.

      - `"none"`

  - `class EnvironmentParamOpenAIHosted: …`

    An existing OpenAI-hosted environment or new inline/template-based hosted configuration.

    - `type: Literal["openai_hosted"]`

      The type of the object. Always `openai_hosted`.

      - `"openai_hosted"`

    - `capability_directories: Optional[List[str]]`

      Directories that contain capabilities exposed to the agent. Defaults to an empty list.

      `minItems: 0`, `maxItems: 16384`

    - `container_size: Optional[Literal["small", "medium", "large"]]`

      The hosted container size. Omission selects the medium tier.

      - `"small"`

      - `"medium"`

      - `"large"`

    - `desktop: Optional[EnvironmentParamOpenAIHostedDesktop]`

      Desktop provisioning. Omission or null inherits the template setting, or defaults to disabled.

      - `enabled: bool`

        Whether to provision the desktop and its browser proxy.

    - `env: Optional[Dict[str, str]]`

      Environment variables made available to the agent.

    - `environment_id: Optional[str]`

      An existing prewarmed environment. Cannot be combined with a template or inline configuration.

      `minLength: 9`, `maxLength: 256`

    - `environment_template_id: Optional[str]`

      A reusable hosted template applied before inline session configuration. Omitted fields inherit the template; network overrides cannot broaden its policy.

      `minLength: 0`, `maxLength: 64`

    - `files: Optional[List[HostedEnvironmentFileParam]]`

      Files available before the agent starts. Defaults to an empty list.

      `minItems: 0`, `maxItems: 50`

      - `class HostedEnvironmentFileParamFileID: …`

        A file previously uploaded through the OpenAI Files API.

        - `file_id: str`

          The ID of the uploaded file.

          `minLength: 1`, `maxLength: 256`

        - `path: str`

          The absolute destination path inside `/workspace`.

          `minLength: 1`, `maxLength: 4096`

        - `type: Literal["file_id"]`

          The type of the object. Always `file_id`.

          - `"file_id"`

      - `class HostedEnvironmentFileParamInline: …`

        A file supplied directly as standard-base64 data.

        - `data: str`

          The standard-base64-encoded file contents.

          `minLength: 0`, `maxLength: 6990508`

        - `path: str`

          The absolute destination path inside `/workspace`.

          `minLength: 1`, `maxLength: 4096`

        - `type: Literal["inline"]`

          The type of the object. Always `inline`.

          - `"inline"`

    - `network: Optional[EnvironmentParamOpenAIHostedNetwork]`

      Network access policy for the environment. If omitted, the API version determines whether network access is enabled or disabled.

      - `access: Literal["enabled", "disabled", "restricted"]`

        The environment's network access mode.

        - `"enabled"`

          Allows unrestricted network access.

        - `"disabled"`

          Disables network access.

        - `"restricted"`

          Applies the configured domain restrictions.

      - `allowed_domains: Optional[List[str]]`

        Domains the environment may access when network access is restricted.

        `minItems: 0`, `maxItems: 16384`

      - `blocked_domains: Optional[List[str]]`

        Domains blocked for both executor and browser when access is restricted. A nonempty list requires `access: restricted` and cannot be combined with nonempty `allowed_domains`. Wildcard domains are not supported.

        `minItems: 0`, `maxItems: 100`

    - `packages: Optional[EnvironmentParamOpenAIHostedPackages]`

      Packages to install in the environment. Defaults to empty package lists.

      - `npm: Optional[List[str]]`

        npm packages to install globally. Defaults to an empty list.

        `minItems: 0`, `maxItems: 16384`

      - `python: Optional[List[str]]`

        Python packages to install. Defaults to an empty list.

        `minItems: 0`, `maxItems: 16384`

      - `system: Optional[List[str]]`

        System packages to install. Defaults to an empty list.

        `minItems: 0`, `maxItems: 16384`

    - `plugins: Optional[List[HostedPluginParam]]`

      Plugins provided as inline ZIP archives. Defaults to an empty list.

      `minItems: 0`, `maxItems: 32`

      - `description: str`

        The plugin description declared in `.codex-plugin/plugin.json`.

        `minLength: 0`, `maxLength: 1048576`

      - `name: str`

        The plugin name declared in `.codex-plugin/plugin.json`.

        `minLength: 1`, `maxLength: 64`

      - `source: InlineCapabilitySourceParam`

        Provides ZIP bytes encoded with standard base64.

        - `data: str`

          Standard-base64 encoded ZIP archive bytes.

          `minLength: 1`, `maxLength: 70254592`

        - `media_type: Literal["application/zip"]`

          The archive media type, always `application/zip`.

          - `"application/zip"`

        - `type: Literal["base64"]`

          The type of the object. Always `base64`.

          - `"base64"`

      - `type: Literal["inline"]`

        The type of the object. Always `inline`.

        - `"inline"`

    - `setup_commands: Optional[List[SetupCommandParam]]`

      Ordered, confidential setup commands. Command bodies are never returned.

      `minItems: 0`, `maxItems: 16`

      - `command: str`

        The shell command to execute.

        `minLength: 0`, `maxLength: 65536`

      - `cwd: Optional[str]`

        The absolute working directory. Defaults to `/workspace`.

        `minLength: 0`, `maxLength: 4096`

    - `skills: Optional[List[HostedSkillParam]]`

      Skills referenced by ID or provided as inline ZIP archives. Defaults to an empty list.

      `minItems: 0`, `maxItems: 200`

      - `class HostedSkillParamSkillReference: …`

        References a skill uploaded through the Skills API.

        - `skill_id: str`

          The ID of the skill created through `/v1/skills`.

          `minLength: 1`, `maxLength: 64`

        - `type: Literal["skill_reference"]`

          The type of the object. Always `skill_reference`.

          - `"skill_reference"`

        - `version: Optional[str]`

          The skill version, a positive integer or `latest`; omission selects the default.

          `minLength: 0`, `maxLength: 1048576`

      - `class HostedSkillParamInline: …`

        Supplies a skill ZIP directly in the session request.

        - `description: str`

          The skill description declared in `SKILL.md`.

          `minLength: 0`, `maxLength: 1048576`

        - `name: str`

          The skill name declared in `SKILL.md`.

          `minLength: 1`, `maxLength: 64`

        - `source: InlineCapabilitySourceParam`

          Provides ZIP bytes encoded with standard base64.

        - `type: Literal["inline"]`

          The type of the object. Always `inline`.

          - `"inline"`

  - `class EnvironmentParamSelfHosted: …`

    An application-hosted environment configured inline.

    - `type: Literal["self_hosted"]`

      The type of the object. Always `self_hosted`.

      - `"self_hosted"`

    - `workspace_directory: str`

      Absolute project directory inside the self-hosted environment.

      `minLength: 0`, `maxLength: 1048576`

    - `capability_directories: Optional[List[str]]`

      Directories that contain capabilities exposed to the agent. Defaults to an empty list.

      `minItems: 0`, `maxItems: 16384`

- `agent: Optional[Agent]`

  Agent configuration. With `agent_id`, supplied fields override the saved agent for this session. Without `agent_id`, `model` is required.

  - `compaction: Optional[AgentCompaction]`

    Context compaction settings. Omit to keep the current settings. A supplied object replaces the settings; null or an empty object enables background compaction.

    - `async_: Optional[bool]`

      Whether to compact context in the background. Omission or null defaults to true. Set to false to use blocking compaction. Background compaction may increase token usage.

  - `experimental: Optional[AgentExperimental]`

    Experimental settings to merge by key. Omitted settings keep their current values.

    - `time_awareness: Optional[bool]`

      Whether to give the model periodic current-time reminders. Omit to keep the current setting.

  - `instructions: Optional[str]`

    Additional instructions appended to the agent's default base instructions. Omit to leave unchanged.

    `minLength: 0`, `maxLength: 1048576`

  - `model: Optional[str]`

    The model to use for the agent. The requested model name is preserved.

    `minLength: 0`, `maxLength: 1048576`

  - `multi_agent: Optional[MultiAgentConfigParam]`

    Configuration for creating and coordinating subagents.

    - `enabled: bool`

      Whether subagent tools are enabled.

    - `max_concurrent_subagents: Optional[int]`

      Maximum number of subagents that may run concurrently. Defaults to 6.

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

  - `reasoning: Optional[AgentReasoningParam]`

    Configuration for model reasoning. Omit to keep the current settings; pass `null` to reset to the model's default effort.

    - `effort: Optional[Literal["none", "minimal", "low", 4 more]]`

      The amount of reasoning effort the model should use. Omission lets the model select it.

      - `"none"`

      - `"minimal"`

      - `"low"`

      - `"medium"`

      - `"high"`

      - `"xhigh"`

      - `"max"`

    - `summary: Optional[Literal["concise", "detailed", "auto"]]`

      Controls whether the response includes a reasoning summary.

      - `"concise"`

        Returns a concise reasoning summary when supported.

      - `"detailed"`

        Returns a detailed reasoning summary when supported.

      - `"auto"`

        Automatically selects the most detailed summary supported by the model.

  - `service_tier: Optional[Literal["auto", "default", "flex", 3 more]]`

    The service tier used for model requests.

    - `auto` - Selects the service tier automatically.
    - `default` - Uses the default service tier.
    - `flex` - Uses the flex service tier.
    - `priority` - Uses the priority service tier.
    - `fast` - Uses the fast service tier.
    - `ultrafast` - Uses the ultrafast service tier.

    - `"auto"`

      Selects the service tier automatically.

    - `"default"`

      Uses the default service tier.

    - `"flex"`

      Uses the flex service tier.

    - `"priority"`

      Uses the priority service tier.

    - `"fast"`

      Uses the fast service tier.

    - `"ultrafast"`

      Uses the ultrafast service tier.

  - `text: Optional[AgentTextParam]`

    Configuration for text generated by the agent.

    - `format: Optional[TextFormatParam]`

      The output format. Omission uses ordinary text (`{"type": "text"}`).

      - `class TextFormatParamText: …`

        Generates ordinary text without a structured-output constraint.

        - `type: Literal["text"]`

          The type of the object. Always `text`.

          - `"text"`

      - `class TextFormatParamJSONSchema: …`

        Constrains generated text to a JSON Schema.

        - `schema: Dict[str, object]`

          The JSON Schema that generated text must match.

        - `type: Literal["json_schema"]`

          The type of the object. Always `json_schema`.

          - `"json_schema"`

    - `verbosity: Optional[Literal["low", "medium", "high"]]`

      The amount of text the model should produce. Defaults to `medium`, matching Responses.

      - `"low"`

        Produces less text.

      - `"medium"`

        Uses the default amount of text.

      - `"high"`

        Produces more text.

  - `tools: Optional[Iterable[AgentToolParam]]`

    Tools available to the agent. Omit to inherit, or pass null to clear them. The resolved tool list must fit within 3 MiB (3,145,728 bytes) of compact UTF-8 JSON.

    `minItems: 0`, `maxItems: 16384`

    - `class AgentToolConfigParamFunction: …`

      A function defined by the application.

      - `description: str`

        A description of what the function does.

        `minLength: 0`, `maxLength: 1048576`

      - `name: str`

        The name of the function.

        `minLength: 0`, `maxLength: 1048576`

      - `parameters: Dict[str, object]`

        A JSON Schema object describing the function's arguments.

      - `type: Literal["function"]`

        The type of the object. Always `function`.

        - `"function"`

      - `async_: Optional[bool]`

        Whether the agent continues without waiting for the function result. Defaults to `false`.

      - `defer_loading: Optional[bool]`

        Whether this function is deferred and discovered through tool search. Defaults to `false`.

    - `class AgentToolConfigParamToolSearch: …`

      Discovers deferred function tools and loads them into the model context.

      - `type: Literal["tool_search"]`

        The type of the object. Always `tool_search`.

        - `"tool_search"`

    - `class AgentToolConfigParamProgrammaticToolCalling: …`

      Enables calling tools from model-generated code.

      - `type: Literal["programmatic_tool_calling"]`

        The type of the object. Always `programmatic_tool_calling`.

        - `"programmatic_tool_calling"`

      - `enabled: Optional[bool]`

        Whether tools can be called from model-generated code. Defaults to `true`.

    - `class AgentToolConfigParamMcp: …`

      Tools provided by a remote MCP server.

      - `server_label: str`

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

        `minLength: 0`, `maxLength: 1048576`

      - `transport: McpTransportParam`

        The transport used to connect to the MCP server.

        - `class McpTransportConfigParamHTTP: …`

          Connects to an MCP server over HTTP.

          - `server_url: str`

            The URL of the MCP server.

            `minLength: 0`, `maxLength: 1048576`

          - `type: Literal["http"]`

            The type of the object. Always `http`.

            - `"http"`

          - `authorization: Optional[str]`

            The authorization value sent to the MCP server, if any.

            `minLength: 0`, `maxLength: 1048576`

          - `headers: Optional[Dict[str, str]]`

            Additional HTTP headers sent to the MCP server.

        - `class McpTransportConfigParamStdio: …`

          Starts an MCP server as a local process.

          - `command: str`

            The command used to start the MCP server.

            `minLength: 0`, `maxLength: 1048576`

          - `cwd: str`

            The working directory used to start the MCP server.

            `minLength: 0`, `maxLength: 1048576`

          - `type: Literal["stdio"]`

            The type of the object. Always `stdio`.

            - `"stdio"`

          - `args: Optional[List[str]]`

            Arguments passed to the MCP server command.

            `minItems: 0`, `maxItems: 16384`

          - `env: Optional[Dict[str, str]]`

            Environment variables set for the MCP server process.

          - `env_vars: Optional[List[str]]`

            Environment variable names to inherit from the selected execution environment.

            `minItems: 0`, `maxItems: 16384`

      - `type: Literal["mcp"]`

        The type of the object. Always `mcp`.

        - `"mcp"`

      - `allowed_tools: Optional[List[str]]`

        The MCP tools the agent may call. All server tools are allowed when omitted.

        `minItems: 0`, `maxItems: 16384`

      - `connection_origin: Optional[Literal["service", "environment"]]`

        Selects where outbound MCP HTTP connections originate. Omitted or `service` uses the Managed Agents service network; `environment` uses the session's selected environment.

        - `"service"`

          Uses the Managed Agents service network.

        - `"environment"`

          Uses the session's execution environment.

      - `credential_id: Optional[str]`

        The attached vault credential used to authenticate this MCP server. Optional when exactly one attached credential matches the server URL.

        `minLength: 0`, `maxLength: 1048576`

      - `request_metadata: Optional[Dict[str, object]]`

        Metadata included with requests to this MCP server.

      - `required: Optional[bool]`

        Whether this MCP server must initialize before the first turn. Defaults to `false`.

    - `class AgentToolConfigParamWebSearch: …`

      Web search.

      - `type: Literal["web_search"]`

        The type of the object. Always `web_search`.

        - `"web_search"`

      - `allowed_domains: Optional[List[str]]`

        Domains the search may include.

        `minItems: 0`, `maxItems: 16384`

      - `context_size: Optional[Literal["low", "medium", "high"]]`

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

        - `"low"`

        - `"medium"`

        - `"high"`

      - `location: Optional[AgentToolConfigParamWebSearchLocation]`

        Approximate location used to localize search results.

        - `city: Optional[str]`

          The city name.

          `minLength: 0`, `maxLength: 1048576`

        - `country: Optional[str]`

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

          `minLength: 0`, `maxLength: 1048576`

        - `region: Optional[str]`

          The region or state name.

          `minLength: 0`, `maxLength: 1048576`

        - `timezone: Optional[str]`

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

          `minLength: 0`, `maxLength: 1048576`

      - `mode: Optional[Literal["disabled", "cached", "live"]]`

        The source used for web search results. Defaults to `live`.

        - `"disabled"`

          Disables web search.

        - `"cached"`

          Uses cached search results.

        - `"live"`

          Searches the live web.

    - `class AgentToolConfigParamComputerUse: …`

      Browser use in an OpenAI-hosted session.

      - `type: Literal["computer_use"]`

        The type of the object. Always `computer_use`.

        - `"computer_use"`

      - `include_screenshots: Optional[bool]`

        Whether computer tool outputs include screenshots. Defaults to `false`.

    - `class AgentToolConfigParamAutomations: …`

      Lets the agent manage its own scheduled wakeups.

      - `type: Literal["automations"]`

        The type of the object. Always `automations`.

        - `"automations"`

- `agent_id: Optional[str]`

  The ID of a saved reusable agent. Omit `agent` to use its configuration unchanged.

  `minLength: 0`, `maxLength: 64`

- `input: Optional[Union[str, Iterable[AgentSessionInputMessageParam], null]]`

  Initial input to submit when the session is created. A string is shorthand for a single user message. Required when `environment.type` is `none`, or when `stream` is `true` for an environment that is not `self_hosted`; optional for self-hosted and non-streaming execution environments.

  - `str`

  - `Iterable[AgentSessionInputMessageParam]`

    - `content: List[InputContentParam]`

      The content of the message.

      `minItems: 0`, `maxItems: 16384`

      - `class InputContentParamInputText: …`

        Text input to the model.

        - `text: str`

          The text sent to the model.

          `minLength: 0`, `maxLength: 1048576`

        - `type: Literal["input_text"]`

          The type of the object. Always `input_text`.

          - `"input_text"`

      - `class InputContentParamInputImage: …`

        Image input to the model.

        - `image_url: str`

          The URL of the image sent to the model.

          `minLength: 0`, `maxLength: 1048576`

        - `type: Literal["input_image"]`

          The type of the object. Always `input_image`.

          - `"input_image"`

    - `role: Literal["user"]`

      The role of the message author. Always `user`.

      - `"user"`

    - `type: Optional[Literal["message"]]`

      The type of the input item. Always `message`.

      - `"message"`

- `metadata: Optional[Dict[str, str]]`

  Up to 16 string key-value pairs, with keys up to 64 and values up to 512 characters. Omission or null defaults to an empty map.

- `prompt_cache_options: Optional[PromptCacheOptions]`

  Default prompt cache lifetime for turns in this session. Omit to use the model default.

  - `ttl: Optional[Literal["30m", "12h"]]`

    Minimum lifetime for new prompt cache entries. Defaults to 30 minutes.

    - `"30m"`

    - `"12h"`

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

  Action review mode. Omit to use none.

  - `"none"`

    Keep the existing execution behavior without automatic action review.

  - `"auto_review"`

    Review eligible actions automatically. Deny manual approval fallbacks.

- `spend_control: Optional[SpendControl]`

  Optional spending limit in USD cents. Omission or null creates an unlimited session.

  - `limit: Optional[int]`

    Positive USD cents, or null to remove the limit.

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

- `stream: Optional[Literal[false]]`

  Whether to stream session events as server-sent events. Defaults to `false`.

  - `false`

- `stream_options: Optional[StreamOptions]`

  Options for the event stream. Only allowed when `stream` is `true`.

  - `include_obfuscation: Optional[bool]`

    Whether to include obfuscation padding in events on this connection. Defaults to `true`.

- `vault_ids: Optional[Sequence[str]]`

  The IDs of vaults made available to the session.

  `minItems: 0`, `maxItems: 16384`

### Returns

- `class AgentSession: …`

  A Managed Agents session.

  - `id: str`

    The ID of the session.

    `minLength: 0`

  - `agent: Agent`

    The agent running in the session.

    - `id: str`

      The ID of the agent.

      `minLength: 0`

    - `instructions: Optional[str]`

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

      `minLength: 0`

    - `model: str`

      The model used by the agent.

      `minLength: 0`

    - `multi_agent: MultiAgentConfig`

      Configuration for creating and coordinating subagents.

      - `enabled: bool`

        Whether subagent tools are enabled. Defaults to false.

      - `max_concurrent_subagents: Optional[int]`

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

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

    - `name: Optional[str]`

      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`

    - `reasoning: AgentReasoning`

      The agent's reasoning configuration.

      - `effort: Optional[Literal["none", "minimal", "low", 4 more]]`

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

        - `"none"`

        - `"minimal"`

        - `"low"`

        - `"medium"`

        - `"high"`

        - `"xhigh"`

        - `"max"`

      - `summary: Optional[Literal["concise", "detailed", "auto"]]`

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

        - `"concise"`

          Returns a concise reasoning summary when supported.

        - `"detailed"`

          Returns a detailed reasoning summary when supported.

        - `"auto"`

          Automatically selects the most detailed summary supported by the model.

    - `service_tier: Literal["auto", "default", "flex", 3 more]`

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

      - `"auto"`

      - `"default"`

      - `"flex"`

      - `"priority"`

      - `"fast"`

      - `"ultrafast"`

    - `text: AgentText`

      Configuration for text generated by the agent.

      - `format: TextFormat`

        The effective output format. Defaults to ordinary text.

        - `class TextFormatResourceText: …`

          Generates ordinary text without a structured-output constraint.

          - `type: Literal["text"]`

            The type of the object. Always `text`.

            - `"text"`

        - `class TextFormatResourceJSONSchema: …`

          Constrains generated text to a JSON Schema.

          - `schema: Dict[str, object]`

            The JSON Schema that generated text must match.

          - `type: Literal["json_schema"]`

            The type of the object. Always `json_schema`.

            - `"json_schema"`

      - `verbosity: Literal["low", "medium", "high"]`

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

        - `"low"`

        - `"medium"`

        - `"high"`

    - `tools: List[AgentTool]`

      Tools available to the agent.

      `minItems: 0`, `maxItems: 2000`

      - `class AgentToolResourceFunction: …`

        A function defined by the application.

        - `defer_loading: bool`

          Whether the function is deferred and discovered through tool search.

        - `description: str`

          A description of what the function does.

          `minLength: 0`

        - `name: str`

          The name of the function.

          `minLength: 0`

        - `parameters: Dict[str, object]`

          A JSON Schema object describing the function's arguments.

        - `type: Literal["function"]`

          The type of the object. Always `function`.

          - `"function"`

        - `async_: Optional[bool]`

          Whether the agent continues without waiting for the function result.

      - `class AgentToolResourceProgrammaticToolCalling: …`

        Enables calling tools from model-generated code.

        - `enabled: bool`

          Whether tools can be called from model-generated code.

        - `type: Literal["programmatic_tool_calling"]`

          The type of the object. Always `programmatic_tool_calling`.

          - `"programmatic_tool_calling"`

      - `class AgentToolResourceMcp: …`

        Tools provided by a remote MCP server.

        - `allowed_tools: Optional[List[str]]`

          The MCP tools the agent may call.

          `minItems: 0`, `maxItems: 2000`

        - `connection_origin: Literal["service", "environment"]`

          Where outbound MCP HTTP connections originate.

          - `"service"`

          - `"environment"`

        - `credential_id: Optional[str]`

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

          `minLength: 0`

        - `request_metadata: Dict[str, object]`

          Metadata included with requests to this MCP server.

        - `required: bool`

          Whether this MCP server must initialize before the first turn.

        - `server_label: str`

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

          `minLength: 0`

        - `transport: McpTransport`

          The transport used to connect to the MCP server.

          - `class McpTransportResourceHTTP: …`

            Connects to an MCP server over HTTP.

            - `server_url: str`

              The URL of the MCP server.

              `minLength: 0`

            - `type: Literal["http"]`

              The type of the object. Always `http`.

              - `"http"`

          - `class McpTransportResourceStdio: …`

            Starts an MCP server as a local process.

            - `args: List[str]`

              Arguments passed to the MCP server command.

              `minItems: 0`, `maxItems: 2000`

            - `command: str`

              The command used to start the MCP server.

              `minLength: 0`

            - `cwd: str`

              The working directory used to start the MCP server.

              `minLength: 0`

            - `env_vars: List[str]`

              Environment variable names inherited from the execution environment.

              `minItems: 0`, `maxItems: 2000`

            - `type: Literal["stdio"]`

              The type of the object. Always `stdio`.

              - `"stdio"`

        - `type: Literal["mcp"]`

          The type of the object. Always `mcp`.

          - `"mcp"`

      - `class AgentToolResourceWebSearch: …`

        Web search.

        - `allowed_domains: Optional[List[str]]`

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

          `minItems: 0`, `maxItems: 2000`

        - `context_size: Literal["low", "medium", "high"]`

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

          - `"low"`

          - `"medium"`

          - `"high"`

        - `location: Optional[AgentToolResourceWebSearchLocation]`

          Approximate location used to localize search results, if provided.

          - `city: Optional[str]`

            The city name.

            `minLength: 0`

          - `country: Optional[str]`

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

            `minLength: 0`

          - `region: Optional[str]`

            The region or state name.

            `minLength: 0`

          - `timezone: Optional[str]`

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

            `minLength: 0`

        - `mode: Literal["disabled", "cached", "live"]`

          The source used for web search results.

          - `"disabled"`

          - `"cached"`

          - `"live"`

        - `type: Literal["web_search"]`

          The type of the object. Always `web_search`.

          - `"web_search"`

      - `class AgentToolResourceComputerUse: …`

        Browser use in an OpenAI-hosted session.

        - `include_screenshots: bool`

          Whether computer tool outputs include screenshots.

        - `type: Literal["computer_use"]`

          The type of the object. Always `computer_use`.

          - `"computer_use"`

      - `class AgentToolResourceAutomations: …`

        Lets the agent manage its own scheduled wakeups.

        - `type: Literal["automations"]`

          The type of the object. Always `automations`.

          - `"automations"`

    - `compaction: Optional[AgentCompaction]`

      The effective context compaction settings.

      - `async_: bool`

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

    - `experimental: Optional[AgentExperimental]`

      The effective experimental settings for the agent.

      - `time_awareness: bool`

        Whether the model receives periodic current-time reminders.

  - `created_at: int`

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

    `format: int64`

  - `environment: Environment`

    The execution environment for the session.

    - `class EnvironmentResourceNone: …`

      The session talks to CCA without selecting or provisioning an execution environment.

      - `type: Literal["none"]`

        The type of the object. Always `none`.

        - `"none"`

    - `class EnvironmentResourceOpenAIHosted: …`

      An environment hosted by OpenAI.

      - `id: str`

        The public ID of the environment.

        `minLength: 0`

      - `capability_directories: List[str]`

        Directories that contain capabilities exposed to the agent.

        `minItems: 0`, `maxItems: 2000`

      - `files: List[HostedEnvironmentFile]`

        Files available in the environment, excluding their contents.

        `minItems: 0`, `maxItems: 50`

        - `class HostedEnvironmentFileID: …`

          A file copied from the OpenAI Files API.

          - `id: str`

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

            `minLength: 0`

          - `file_id: str`

            The ID of the uploaded file.

            `minLength: 0`

          - `path: str`

            The file's absolute path inside the environment.

            `minLength: 0`

          - `size_bytes: int`

            The decoded file size in bytes.

            `format: int64`, `minimum: 0`

          - `type: Literal["file_id"]`

            The type of the object. Always `file_id`.

            - `"file_id"`

        - `class HostedEnvironmentFileResourceInline: …`

          A file supplied inline when the session was created.

          - `id: str`

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

            `minLength: 0`

          - `path: str`

            The file's absolute path inside the environment.

            `minLength: 0`

          - `size_bytes: int`

            The decoded file size in bytes.

            `format: int64`, `minimum: 0`

          - `type: Literal["inline"]`

            The type of the object. Always `inline`.

            - `"inline"`

      - `network: EnvironmentResourceOpenAIHostedNetwork`

        The effective network access policy for the environment.

        - `access: Literal["enabled", "disabled", "restricted"]`

          The environment's network access mode.

          - `"enabled"`

            Allows unrestricted network access.

          - `"disabled"`

            Disables network access.

          - `"restricted"`

            Applies the configured domain restrictions.

        - `allowed_domains: List[str]`

          Domains the environment may access when network access is restricted.

          `minItems: 0`, `maxItems: 2000`

      - `packages: EnvironmentResourceOpenAIHostedPackages`

        Packages installed in the environment.

        - `npm: List[str]`

          npm packages installed globally in the environment.

          `minItems: 0`, `maxItems: 16384`

        - `python: List[str]`

          Python packages installed in the environment.

          `minItems: 0`, `maxItems: 16384`

        - `system: List[str]`

          System packages installed in the environment.

          `minItems: 0`, `maxItems: 16384`

      - `plugins: List[HostedPlugin]`

        Plugins installed in the environment, excluding their archive contents.

        `minItems: 0`, `maxItems: 2000`

        - `description: str`

          The installed plugin description.

          `minLength: 0`

        - `name: str`

          The installed plugin name.

          `minLength: 0`

        - `type: Literal["inline"]`

          The type of the object. Always `inline`.

          - `"inline"`

      - `skills: List[HostedSkill]`

        Skills installed in the environment, excluding their archive contents.

        `minItems: 0`, `maxItems: 2000`

        - `class HostedSkillReference: …`

          A skill installed from the Skills API.

          - `description: str`

            The installed skill description.

            `minLength: 0`

          - `name: str`

            The installed skill name.

            `minLength: 0`

          - `skill_id: str`

            The referenced skill ID.

            `minLength: 0`

          - `type: Literal["skill_reference"]`

            The type of the object. Always `skill_reference`.

            - `"skill_reference"`

          - `version: str`

            The concrete skill version installed for this session.

            `minLength: 0`

        - `class HostedSkillResourceInline: …`

          A skill installed from an inline ZIP archive.

          - `description: str`

            The installed skill description.

            `minLength: 0`

          - `name: str`

            The installed skill name.

            `minLength: 0`

          - `type: Literal["inline"]`

            The type of the object. Always `inline`.

            - `"inline"`

      - `type: Literal["openai_hosted"]`

        The type of the object. Always `openai_hosted`.

        - `"openai_hosted"`

      - `container_size: Optional[Literal["small", "medium", "large"]]`

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

        - `"small"`

        - `"medium"`

        - `"large"`

      - `desktop: Optional[EnvironmentResourceOpenAIHostedDesktop]`

        The effective desktop configuration.

        - `enabled: bool`

          Whether the environment provisions a desktop and browser proxy.

    - `class EnvironmentResourceSelfHosted: …`

      An environment hosted by the application.

      - `id: str`

        The public ID of the environment.

        `minLength: 0`

      - `capability_directories: List[str]`

        Directories that contain capabilities exposed to the agent.

        `minItems: 0`, `maxItems: 2000`

      - `remote_url: str`

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

        `minLength: 0`

      - `type: Literal["self_hosted"]`

        The type of the object. Always `self_hosted`.

        - `"self_hosted"`

      - `workspace_directory: str`

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

        `minLength: 0`

  - `error: Optional[str]`

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

    `minLength: 0`

  - `last_active_at: int`

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

    `format: int64`

  - `metadata: Dict[str, str]`

    Custom string key-value pairs attached to the session.

  - `object: Literal["agent.session"]`

    The object type. Always `agent.session`.

    - `"agent.session"`

  - `required_actions: List[RequiredAction]`

    Actions that must be completed before the session can continue.

    `minItems: 0`, `maxItems: 2000`

    - `class RequiredActionSessionRequiredActionResourceComputerUseApprovalRequest: …`

      Respond to a computer-use request.

      - `request: RequiredActionSessionRequiredActionResourceComputerUseApprovalRequestRequest`

        The information needed to render the request.

        - `class RequiredActionSessionRequiredActionResourceComputerUseApprovalRequestRequestComputerUseApprovalRequestKindResourceBrowserAuthentication: …`

          A registered form awaiting the application's response.

          - `credential_origin: Optional[str]`

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

            `minLength: 0`

          - `fields: List[RequiredActionSessionRequiredActionResourceComputerUseApprovalRequestRequestComputerUseApprovalRequestKindResourceBrowserAuthenticationField]`

            Controls to render. All submitted values are sensitive.

            `minItems: 0`, `maxItems: 2000`

            - `id: str`

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

              `minLength: 0`

            - `label: str`

              The label to display beside the control.

              `minLength: 0`

            - `required: bool`

              Whether this control requires a nonempty value.

            - `type: str`

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

              `minLength: 0`

          - `options: List[RequiredActionSessionRequiredActionResourceComputerUseApprovalRequestRequestComputerUseApprovalRequestKindResourceBrowserAuthenticationOption]`

            Sign-in methods. Empty for a plain form.

            `minItems: 0`, `maxItems: 2000`

            - `id: str`

              The option ID to submit as selected_option.

              `minLength: 0`

            - `field_ids: List[str]`

              IDs from the registered fields that this method accepts.

              `minItems: 0`, `maxItems: 2000`

            - `label: str`

              The method label to display.

              `minLength: 0`

          - `reason: Optional[str]`

            Why the agent needs the user to sign in.

            `minLength: 0`

          - `type: Literal["browser_authentication"]`

            The type of the object. Always `browser_authentication`.

            - `"browser_authentication"`

        - `class RequiredActionSessionRequiredActionResourceComputerUseApprovalRequestRequestComputerUseApprovalRequestKindResourceBrowserOriginAccess: …`

          A browser origin awaiting the application's approval decision.

          - `origin: str`

            The origin the browser needs permission to access.

            `minLength: 0`

          - `reason: Optional[str]`

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

            `minLength: 0`

          - `type: Literal["browser_origin_access"]`

            The type of the object. Always `browser_origin_access`.

            - `"browser_origin_access"`

      - `request_id: str`

        The registered request ID to echo when responding.

        `minLength: 0`

      - `turn_id: str`

        The turn that requested approval.

        `minLength: 0`

      - `type: Literal["computer_use_approval_request"]`

        The type of the object. Always `computer_use_approval_request`.

        - `"computer_use_approval_request"`

    - `class RequiredActionSessionRequiredActionResourceFunctionCall: …`

      Run a function tool and submit its result.

      - `arguments: object`

        The arguments supplied by the model.

      - `call_id: str`

        The ID to include when submitting the function result.

        `minLength: 0`

      - `name: str`

        The function name.

        `minLength: 0`

      - `turn_id: str`

        The ID of the turn that requested the function call.

        `minLength: 0`

      - `type: Literal["function_call"]`

        The type of the object. Always `function_call`.

        - `"function_call"`

    - `class RequiredActionSessionRequiredActionResourceEnvironmentConnection: …`

      Reconnect a session environment.

      - `environment_id: str`

        The ID of the environment to reconnect.

        `minLength: 0`

      - `type: Literal["environment_connection"]`

        The type of the object. Always `environment_connection`.

        - `"environment_connection"`

  - `status: Literal["idle", "in_progress", "requires_action", "failed"]`

    The current status of the session.

    - `"idle"`

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

    - `"in_progress"`

      The session is processing a turn.

    - `"requires_action"`

      The session is waiting for one or more required actions.

    - `"failed"`

      The session failed.

  - `usage: Optional[TokenUsage]`

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

    - `input_tokens: int`

      The number of input tokens used by the agent.

      `format: int64`

    - `input_tokens_details: InputTokensDetails`

      A breakdown of the agent's input token usage.

      - `cached_tokens: int`

        The number of input tokens retrieved from the prompt cache.

        `format: int64`

    - `output_tokens: int`

      The number of output tokens generated by the agent.

      `format: int64`

    - `output_tokens_details: OutputTokensDetails`

      A breakdown of the agent's output token usage.

      - `reasoning_tokens: int`

        The number of output tokens used for reasoning.

        `format: int64`

    - `total_tokens: int`

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

      `format: int64`

  - `vault_ids: List[str]`

    The IDs of vaults made available to the session.

    `minItems: 0`, `maxItems: 2000`

  - `prompt_cache_options: Optional[PromptCacheOptions]`

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

    - `ttl: Literal["30m", "12h"]`

      - `"30m"`

      - `"12h"`

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

    - `"none"`

    - `"auto_review"`

  - `spend_control: Optional[SpendControl]`

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

    - `consumed: Optional[int]`

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

      `minimum: 0`

    - `limit: int`

      The configured positive limit in USD cents.

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

### Example

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
for session in client.beta.agents.sessions.create(
    environment={
        "type": "none"
    },
):
  print(session)
```

#### 201 — 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
  }
}
```
