Class: Anthropic::Resources::Beta::Sessions

Inherits:
Object
  • Object
show all
Defined in:
lib/anthropic/resources/beta/sessions.rb,
lib/anthropic/resources/beta/sessions/events.rb,
lib/anthropic/resources/beta/sessions/threads.rb,
lib/anthropic/resources/beta/sessions/resources.rb,
lib/anthropic/resources/beta/sessions/threads/events.rb,
sig/anthropic/resources/beta/sessions.rbs,
sig/anthropic/resources/beta/sessions/events.rbs,
sig/anthropic/resources/beta/sessions/threads.rbs,
sig/anthropic/resources/beta/sessions/resources.rbs,
sig/anthropic/resources/beta/sessions/threads/events.rbs

Defined Under Namespace

Classes: Events, Resources, Threads

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Sessions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Sessions.

Parameters:

API:

  • private



272
273
274
275
276
277
# File 'lib/anthropic/resources/beta/sessions.rb', line 272

def initialize(client:)
  @client = client
  @events = Anthropic::Resources::Beta::Sessions::Events.new(client: client)
  @resources = Anthropic::Resources::Beta::Sessions::Resources.new(client: client)
  @threads = Anthropic::Resources::Beta::Sessions::Threads.new(client: client)
end

Instance Attribute Details

#eventsAnthropic::Resources::Beta::Sessions::Events (readonly)

Returns:



8
9
10
# File 'lib/anthropic/resources/beta/sessions.rb', line 8

def events
  @events
end

#resourcesAnthropic::Resources::Beta::Sessions::Resources (readonly)

Returns:



11
12
13
# File 'lib/anthropic/resources/beta/sessions.rb', line 11

def resources
  @resources
end

#threadsAnthropic::Resources::Beta::Sessions::Threads (readonly)

Returns:



14
15
16
# File 'lib/anthropic/resources/beta/sessions.rb', line 14

def threads
  @threads
end

Instance Method Details

#archive(session_id, betas: nil, workspace_id: nil, request_options: {}) ⇒ Anthropic::Models::Beta::BetaManagedAgentsSession

Archive Session

Some parameter documentations has been truncated, see Models::Beta::SessionArchiveParams for more details.

Parameters:

  • Path parameter session_id

  • Optional header to specify the beta version(s) you want to use.

  • Optional header to select the Workspace for this request. The value is a Workspa

Returns:

See Also:



258
259
260
261
262
263
264
265
266
267
# File 'lib/anthropic/resources/beta/sessions.rb', line 258

def archive(session_id, params = {})
  parsed, options = Anthropic::Beta::SessionArchiveParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/sessions/%1$s/archive?beta=true", session_id],
    headers: parsed.transform_keys(betas: "anthropic-beta", workspace_id: "anthropic-workspace-id"),
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#create(agent:, environment_id:, budget: nil, initial_events: nil, metadata: nil, resources: nil, title: nil, vault_ids: nil, betas: nil, workspace_id: nil, request_options: {}) ⇒ Anthropic::Models::Beta::BetaManagedAgentsSession

Create Session

Some parameter documentations has been truncated, see Models::Beta::SessionCreateParams for more details.

Parameters:

  • Body param: Agent identifier. Accepts the agent ID string, which pins the late

  • Body param: ID of the environment defining the container configuration for thi

  • Body param: A hard spend ceiling. The session stops issuing new model requests o

  • Body param: Initial events to send to the session at creation, processed in or

  • Body param: Arbitrary key-value metadata attached to the session. Maximum 16 pai

  • Body param: Resources (e.g. repositories, files) to mount into the session's con

  • Body param: Human-readable session title.

  • Body param: Vault IDs for stored credentials the agent can use during the sessio

  • Header param: Optional header to specify the beta version(s) you want to use.

  • Header param: Optional header to select the Workspace for this request. The valu

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/anthropic/resources/beta/sessions.rb', line 48

def create(params)
  parsed, options = Anthropic::Beta::SessionCreateParams.dump_request(params)
  header_params = {betas: "anthropic-beta", workspace_id: "anthropic-workspace-id"}
  @client.request(
    method: :post,
    path: "v1/sessions?beta=true",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#delete(session_id, betas: nil, workspace_id: nil, request_options: {}) ⇒ Anthropic::Models::Beta::BetaManagedAgentsDeletedSession

Delete Session

Some parameter documentations has been truncated, see Models::Beta::SessionDeleteParams for more details.

Parameters:

  • Path parameter session_id

  • Optional header to specify the beta version(s) you want to use.

  • Optional header to select the Workspace for this request. The value is a Workspa

Returns:

See Also:



229
230
231
232
233
234
235
236
237
238
# File 'lib/anthropic/resources/beta/sessions.rb', line 229

def delete(session_id, params = {})
  parsed, options = Anthropic::Beta::SessionDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["v1/sessions/%1$s?beta=true", session_id],
    headers: parsed.transform_keys(betas: "anthropic-beta", workspace_id: "anthropic-workspace-id"),
    model: Anthropic::Beta::BetaManagedAgentsDeletedSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#list(agent_id: nil, agent_version: nil, created_at_gt: nil, created_at_gte: nil, created_at_lt: nil, created_at_lte: nil, deployment_id: nil, include_archived: nil, limit: nil, memory_store_id: nil, order: nil, page: nil, statuses: nil, betas: nil, workspace_id: nil, request_options: {}) ⇒ Anthropic::Internal::BidirectionalPageCursor<Anthropic::Models::Beta::BetaManagedAgentsSession>

List Sessions

Some parameter documentations has been truncated, see Models::Beta::SessionListParams for more details.

Parameters:

  • Query param: Filter sessions created with this agent ID.

  • Query param: Filter by agent version. Only applies when agent_id is also set.

  • Query param: Return sessions created after this time (exclusive).

  • Query param: Return sessions created at or after this time (inclusive).

  • Query param: Return sessions created before this time (exclusive).

  • Query param: Return sessions created at or before this time (inclusive).

  • Query param: Filter sessions created by this deployment ID.

  • Query param: When true, includes archived sessions. Default: false (exclude arch

  • Query param: Maximum number of results to return.

  • Query param: Filter sessions whose resources contain a memory_store with this

  • Query param: Sort direction for results, ordered by created_at. Defaults to `d

  • Query param: Opaque pagination cursor from a previous response.

  • Query param: Filter by session status. Repeat the parameter to match any of mult

  • Header param: Optional header to specify the beta version(s) you want to use.

  • Header param: Optional header to select the Workspace for this request. The valu

Returns:

See Also:



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/anthropic/resources/beta/sessions.rb', line 173

def list(params = {})
  query_params =
    [
      :agent_id,
      :agent_version,
      :created_at_gt,
      :created_at_gte,
      :created_at_lt,
      :created_at_lte,
      :deployment_id,
      :include_archived,
      :limit,
      :memory_store_id,
      :order,
      :page,
      :statuses
    ]
  parsed, options = Anthropic::Beta::SessionListParams.dump_request(params)
  query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: "v1/sessions?beta=true",
    query: query.transform_keys(
      created_at_gt: "created_at[gt]",
      created_at_gte: "created_at[gte]",
      created_at_lt: "created_at[lt]",
      created_at_lte: "created_at[lte]"
    ),
    headers: parsed.except(*query_params).transform_keys(
      betas: "anthropic-beta",
      workspace_id: "anthropic-workspace-id"
    ),
    page: Anthropic::Internal::BidirectionalPageCursor,
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#retrieve(session_id, betas: nil, workspace_id: nil, request_options: {}) ⇒ Anthropic::Models::Beta::BetaManagedAgentsSession

Get Session

Some parameter documentations has been truncated, see Models::Beta::SessionRetrieveParams for more details.

Parameters:

  • Path parameter session_id

  • Optional header to specify the beta version(s) you want to use.

  • Optional header to select the Workspace for this request. The value is a Workspa

Returns:

See Also:



79
80
81
82
83
84
85
86
87
88
# File 'lib/anthropic/resources/beta/sessions.rb', line 79

def retrieve(session_id, params = {})
  parsed, options = Anthropic::Beta::SessionRetrieveParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v1/sessions/%1$s?beta=true", session_id],
    headers: parsed.transform_keys(betas: "anthropic-beta", workspace_id: "anthropic-workspace-id"),
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#update(session_id, agent: nil, budget: nil, metadata: nil, title: nil, vault_ids: nil, betas: nil, workspace_id: nil, request_options: {}) ⇒ Anthropic::Models::Beta::BetaManagedAgentsSession

Update Session

Some parameter documentations has been truncated, see Models::Beta::SessionUpdateParams for more details.

Parameters:

  • Path param: Path parameter session_id

  • Body param: Mid-session agent configuration update. Only tools and `mcp_server

  • Body param: A hard spend ceiling. The session stops issuing new model requests o

  • Body param: Metadata patch. Set a key to a string to upsert it, or to null to de

  • Body param: Human-readable session title.

  • Body param: Vault IDs (vlt_*) to attach to the session. Not yet supported; req

  • Header param: Optional header to specify the beta version(s) you want to use.

  • Header param: Optional header to select the Workspace for this request. The valu

Returns:

See Also:



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/anthropic/resources/beta/sessions.rb', line 118

def update(session_id, params = {})
  parsed, options = Anthropic::Beta::SessionUpdateParams.dump_request(params)
  header_params = {betas: "anthropic-beta", workspace_id: "anthropic-workspace-id"}
  @client.request(
    method: :post,
    path: ["v1/sessions/%1$s?beta=true", session_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end