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

Update an agent session

beta.agents.sessions.update(session_id, **kwargs) -> AgentSession { id, agent, created_at, 12 more }
POST
/agents/sessions/{session_id}

Updates session tools, metadata, model, reasoning effort, service tier, or the default prompt cache lifetime. Model settings apply to subsequent turns. Omitted fields are unchanged. See managing sessions.

Parameters
session_id: String
minLength0
maxLength1048576
agent: Agent{ model, reasoning, service_tier, tools}

Agent settings to update on this session. Omitted fields stay unchanged.

metadata: Hash[Symbol, String]

Replaces all metadata. Omit to leave unchanged, or pass null or {} to clear it. Up to 16 string key-value pairs, with keys up to 64 and values up to 512 characters.

prompt_cache_options: PromptCacheOptions{ ttl}

Default prompt cache lifetime for future turns. Send null to clear the session default.

review: :none | :auto_review

Default action review for new root turns. Existing turns and their subagents keep their review mode.

spend_control: SpendControl{ limit}

Omit to retain the limit; null or a null limit removes it without resetting spend.

Returns
class AgentSession { id, agent, created_at, 12 more }

A Managed Agents session.

id: String

The ID of the session.

minLength0
agent: Agent{ id, instructions, model, 8 more}

The agent running in the session.

created_at: Integer

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

formatint64
environment: Environment

The execution environment for the session.

error: String

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

minLength0
last_active_at: Integer

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

formatint64
metadata: Hash[Symbol, String]

Custom string key-value pairs attached to the session.

object: :"agent.session"

The object type. Always agent.session.

required_actions: Array[ComputerUseApprovalRequest{ request, request_id, turn_id, type} | FunctionCall{ arguments, call_id, name, 2 more} | EnvironmentConnection{ environment_id, type}]

Actions that must be completed before the session can continue.

minItems0
maxItems2000
status: :idle | :in_progress | :requires_action | :failed

The current status of the session.

usage: TokenUsage { input_tokens, input_tokens_details, output_tokens, 2 more }

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

vault_ids: Array[String]

The IDs of vaults made available to the session.

minItems0
maxItems2000
prompt_cache_options: PromptCacheOptions{ ttl}

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

review: :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: SpendControl{ consumed, limit}

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

Update an agent session

require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

agent_session = openai.beta.agents.sessions.update("session_id")

puts(agent_session)
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": {
        "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
  }
}
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": {
        "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
  }
}