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

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:



242
243
244
245
246
247
# File 'lib/anthropic/resources/beta/sessions.rb', line 242

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)



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

def events
  @events
end

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



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

def resources
  @resources
end

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



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

def threads
  @threads
end

Instance Method Details

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

Archive Session

Parameters:

Returns:

See Also:



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

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"),
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

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

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

Create Session

Parameters:

Returns:

See Also:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/anthropic/resources/beta/sessions.rb', line 42

def create(params)
  parsed, options = Anthropic::Beta::SessionCreateParams.dump_request(params)
  header_params = {betas: "anthropic-beta"}
  @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, request_options: {}) ⇒ Anthropic::Models::Beta::BetaManagedAgentsDeletedSession

Delete Session

Parameters:

Returns:

See Also:



204
205
206
207
208
209
210
211
212
213
# File 'lib/anthropic/resources/beta/sessions.rb', line 204

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"),
    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, request_options: {}) ⇒ Anthropic::Internal::PageCursor<Anthropic::Models::Beta::BetaManagedAgentsSession>

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

List Sessions

Parameters:

  • agent_id (String)

    Query param: Filter sessions created with this agent ID.

  • agent_version (Integer)

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

  • created_at_gt (Time)

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

  • created_at_gte (Time)

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

  • created_at_lt (Time)

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

  • created_at_lte (Time)

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

  • deployment_id (String)

    Query param: Filter sessions created by this deployment ID.

  • include_archived (Boolean)

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

  • limit (Integer)

    Query param: Maximum number of results to return.

  • memory_store_id (String)

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

  • order (Symbol, Anthropic::Models::Beta::SessionListParams::Order)

    Query param: Sort direction for results, ordered by created_at. Defaults to desc

  • page (String)

    Query param: Opaque pagination cursor from a previous response.

  • statuses (Array<Symbol, Anthropic::Models::Beta::SessionListParams::Status>)

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

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

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

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/anthropic/resources/beta/sessions.rb', line 156

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"),
    page: Anthropic::Internal::PageCursor,
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

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

Get Session

Parameters:

Returns:

See Also:



68
69
70
71
72
73
74
75
76
77
# File 'lib/anthropic/resources/beta/sessions.rb', line 68

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"),
    model: Anthropic::Beta::BetaManagedAgentsSession,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

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

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

Update Session

Parameters:

  • session_id (String)

    Path param: Path parameter session_id

  • agent (Anthropic::Models::Beta::BetaManagedAgentsSessionAgentUpdate)

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

  • metadata (Hash{Symbol=>String, nil}, nil)

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

  • title (String, nil)

    Body param: Human-readable session title.

  • vault_ids (Array<String>)

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

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

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

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/anthropic/resources/beta/sessions.rb', line 103

def update(session_id, params = {})
  parsed, options = Anthropic::Beta::SessionUpdateParams.dump_request(params)
  header_params = {betas: "anthropic-beta"}
  @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