| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Any, List, Optional, cast |
| 4 |
from itertools import chain |
| 5 |
from typing_extensions import Literal |
| 6 |
|
| 7 |
import httpx2 |
| 8 |
|
| 9 |
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 10 |
from ...._utils import is_given, path_template, strip_not_given |
| 11 |
from ...._compat import cached_property |
| 12 |
from ...._resource import SyncAPIResource, AsyncAPIResource |
| 13 |
from ...._response import ( |
| 14 |
to_raw_response_wrapper, |
| 15 |
to_streamed_response_wrapper, |
| 16 |
async_to_raw_response_wrapper, |
| 17 |
async_to_streamed_response_wrapper, |
| 18 |
) |
| 19 |
from ....pagination import SyncPageCursor, AsyncPageCursor |
| 20 |
from ...._base_client import AsyncPaginator, make_request_options |
| 21 |
from ....types.anthropic_beta_param import AnthropicBetaParam |
| 22 |
from ....types.beta.sessions.resource_update_response import ResourceUpdateResponse |
| 23 |
from ....types.beta.sessions.resource_retrieve_response import ResourceRetrieveResponse |
| 24 |
from ....types.beta.sessions.beta_managed_agents_file_resource import BetaManagedAgentsFileResource |
| 25 |
from ....types.beta.sessions.beta_managed_agents_session_resource import BetaManagedAgentsSessionResource |
| 26 |
from ....types.beta.sessions.beta_managed_agents_delete_session_resource import BetaManagedAgentsDeleteSessionResource |
| 27 |
|
| 28 |
__all__ = ["Resources", "AsyncResources"] |
| 29 |
|
| 30 |
|
| 31 |
class Resources(SyncAPIResource): |
| 32 |
@cached_property |
| 33 |
def with_raw_response(self) -> ResourcesWithRawResponse: |
| 34 |
""" |
| 35 |
This property can be used as a prefix for any HTTP method call to return |
| 36 |
the raw response object instead of the parsed content. |
| 37 |
|
| 38 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 39 |
""" |
| 40 |
return ResourcesWithRawResponse(self) |
| 41 |
|
| 42 |
@cached_property |
| 43 |
def with_streaming_response(self) -> ResourcesWithStreamingResponse: |
| 44 |
""" |
| 45 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 46 |
|
| 47 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 48 |
""" |
| 49 |
return ResourcesWithStreamingResponse(self) |
| 50 |
|
| 51 |
def retrieve( |
| 52 |
self, |
| 53 |
resource_id: str, |
| 54 |
*, |
| 55 |
session_id: str, |
| 56 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 57 |
workspace_id: str | Omit = omit, |
| 58 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 59 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 60 |
extra_headers: Headers | None = None, |
| 61 |
extra_query: Query | None = None, |
| 62 |
extra_body: Body | None = None, |
| 63 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 64 |
) -> ResourceRetrieveResponse: |
| 65 |
""" |
| 66 |
Get Session Resource |
| 67 |
|
| 68 |
Args: |
| 69 |
betas: Optional header to specify the beta version(s) you want to use. |
| 70 |
|
| 71 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 72 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 73 |
|
| 74 |
Only needed for credentials that can act on more than one Workspace. A |
| 75 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 76 |
match that Workspace. |
| 77 |
|
| 78 |
extra_headers: Send extra headers |
| 79 |
|
| 80 |
extra_query: Add additional query parameters to the request |
| 81 |
|
| 82 |
extra_body: Add additional JSON properties to the request |
| 83 |
|
| 84 |
timeout: Override the client-level default timeout for this request, in seconds |
| 85 |
""" |
| 86 |
if not session_id: |
| 87 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 88 |
if not resource_id: |
| 89 |
raise ValueError(f"Expected a non-empty value for `resource_id` but received {resource_id!r}") |
| 90 |
extra_headers = { |
| 91 |
**strip_not_given( |
| 92 |
{ |
| 93 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 94 |
if is_given(betas) |
| 95 |
else not_given, |
| 96 |
"anthropic-workspace-id": workspace_id, |
| 97 |
} |
| 98 |
), |
| 99 |
**(extra_headers or {}), |
| 100 |
} |
| 101 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 102 |
return cast( |
| 103 |
ResourceRetrieveResponse, |
| 104 |
self._get( |
| 105 |
path_template( |
| 106 |
"/v1/sessions/{session_id}/resources/{resource_id}?beta=true", |
| 107 |
session_id=session_id, |
| 108 |
resource_id=resource_id, |
| 109 |
), |
| 110 |
options=make_request_options( |
| 111 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 112 |
), |
| 113 |
cast_to=cast( |
| 114 |
Any, ResourceRetrieveResponse |
| 115 |
), # Union types cannot be passed in as arguments in the type system |
| 116 |
), |
| 117 |
) |
| 118 |
|
| 119 |
def update( |
| 120 |
self, |
| 121 |
resource_id: str, |
| 122 |
*, |
| 123 |
session_id: str, |
| 124 |
authorization_token: str, |
| 125 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 126 |
workspace_id: str | Omit = omit, |
| 127 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 128 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 129 |
extra_headers: Headers | None = None, |
| 130 |
extra_query: Query | None = None, |
| 131 |
extra_body: Body | None = None, |
| 132 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 133 |
) -> ResourceUpdateResponse: |
| 134 |
""" |
| 135 |
Update Session Resource |
| 136 |
|
| 137 |
Args: |
| 138 |
authorization_token: New authorization token for the resource. Currently only `github_repository` |
| 139 |
resources support token rotation. |
| 140 |
|
| 141 |
betas: Optional header to specify the beta version(s) you want to use. |
| 142 |
|
| 143 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 144 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 145 |
|
| 146 |
Only needed for credentials that can act on more than one Workspace. A |
| 147 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 148 |
match that Workspace. |
| 149 |
|
| 150 |
extra_headers: Send extra headers |
| 151 |
|
| 152 |
extra_query: Add additional query parameters to the request |
| 153 |
|
| 154 |
extra_body: Add additional JSON properties to the request |
| 155 |
|
| 156 |
timeout: Override the client-level default timeout for this request, in seconds |
| 157 |
""" |
| 158 |
if not session_id: |
| 159 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 160 |
if not resource_id: |
| 161 |
raise ValueError(f"Expected a non-empty value for `resource_id` but received {resource_id!r}") |
| 162 |
extra_headers = { |
| 163 |
**strip_not_given( |
| 164 |
{ |
| 165 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 166 |
if is_given(betas) |
| 167 |
else not_given, |
| 168 |
"anthropic-workspace-id": workspace_id, |
| 169 |
} |
| 170 |
), |
| 171 |
**(extra_headers or {}), |
| 172 |
} |
| 173 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 174 |
return cast( |
| 175 |
ResourceUpdateResponse, |
| 176 |
self._post( |
| 177 |
path_template( |
| 178 |
"/v1/sessions/{session_id}/resources/{resource_id}?beta=true", |
| 179 |
session_id=session_id, |
| 180 |
resource_id=resource_id, |
| 181 |
), |
| 182 |
body={"authorization_token": authorization_token}, |
| 183 |
options=make_request_options( |
| 184 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 185 |
), |
| 186 |
cast_to=cast( |
| 187 |
Any, ResourceUpdateResponse |
| 188 |
), # Union types cannot be passed in as arguments in the type system |
| 189 |
), |
| 190 |
) |
| 191 |
|
| 192 |
def list( |
| 193 |
self, |
| 194 |
session_id: str, |
| 195 |
*, |
| 196 |
limit: int | Omit = omit, |
| 197 |
page: str | Omit = omit, |
| 198 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 199 |
workspace_id: str | Omit = omit, |
| 200 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 201 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 202 |
extra_headers: Headers | None = None, |
| 203 |
extra_query: Query | None = None, |
| 204 |
extra_body: Body | None = None, |
| 205 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 206 |
) -> SyncPageCursor[BetaManagedAgentsSessionResource]: |
| 207 |
""" |
| 208 |
List Session Resources |
| 209 |
|
| 210 |
Args: |
| 211 |
limit: Maximum number of resources to return per page (max 1000). If omitted, returns |
| 212 |
all resources. |
| 213 |
|
| 214 |
page: Opaque cursor from a previous response's `next_page` field. |
| 215 |
|
| 216 |
betas: Optional header to specify the beta version(s) you want to use. |
| 217 |
|
| 218 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 219 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 220 |
|
| 221 |
Only needed for credentials that can act on more than one Workspace. A |
| 222 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 223 |
match that Workspace. |
| 224 |
|
| 225 |
extra_headers: Send extra headers |
| 226 |
|
| 227 |
extra_query: Add additional query parameters to the request |
| 228 |
|
| 229 |
extra_body: Add additional JSON properties to the request |
| 230 |
|
| 231 |
timeout: Override the client-level default timeout for this request, in seconds |
| 232 |
""" |
| 233 |
if not session_id: |
| 234 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 235 |
extra_headers = { |
| 236 |
**strip_not_given( |
| 237 |
{ |
| 238 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 239 |
if is_given(betas) |
| 240 |
else not_given, |
| 241 |
"anthropic-workspace-id": workspace_id, |
| 242 |
} |
| 243 |
), |
| 244 |
**(extra_headers or {}), |
| 245 |
} |
| 246 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 247 |
return self._get_api_list( |
| 248 |
path_template("/v1/sessions/{session_id}/resources?beta=true", session_id=session_id), |
| 249 |
page=SyncPageCursor[BetaManagedAgentsSessionResource], |
| 250 |
options=make_request_options( |
| 251 |
extra_headers=extra_headers, |
| 252 |
extra_query=extra_query, |
| 253 |
extra_body=extra_body, |
| 254 |
timeout=timeout, |
| 255 |
query={ |
| 256 |
"limit": limit, |
| 257 |
"page": page, |
| 258 |
}, |
| 259 |
), |
| 260 |
model=cast( |
| 261 |
Any, BetaManagedAgentsSessionResource |
| 262 |
), # Union types cannot be passed in as arguments in the type system |
| 263 |
) |
| 264 |
|
| 265 |
def delete( |
| 266 |
self, |
| 267 |
resource_id: str, |
| 268 |
*, |
| 269 |
session_id: str, |
| 270 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 271 |
workspace_id: str | Omit = omit, |
| 272 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 273 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 274 |
extra_headers: Headers | None = None, |
| 275 |
extra_query: Query | None = None, |
| 276 |
extra_body: Body | None = None, |
| 277 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 278 |
) -> BetaManagedAgentsDeleteSessionResource: |
| 279 |
""" |
| 280 |
Delete Session Resource |
| 281 |
|
| 282 |
Args: |
| 283 |
betas: Optional header to specify the beta version(s) you want to use. |
| 284 |
|
| 285 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 286 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 287 |
|
| 288 |
Only needed for credentials that can act on more than one Workspace. A |
| 289 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 290 |
match that Workspace. |
| 291 |
|
| 292 |
extra_headers: Send extra headers |
| 293 |
|
| 294 |
extra_query: Add additional query parameters to the request |
| 295 |
|
| 296 |
extra_body: Add additional JSON properties to the request |
| 297 |
|
| 298 |
timeout: Override the client-level default timeout for this request, in seconds |
| 299 |
""" |
| 300 |
if not session_id: |
| 301 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 302 |
if not resource_id: |
| 303 |
raise ValueError(f"Expected a non-empty value for `resource_id` but received {resource_id!r}") |
| 304 |
extra_headers = { |
| 305 |
**strip_not_given( |
| 306 |
{ |
| 307 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 308 |
if is_given(betas) |
| 309 |
else not_given, |
| 310 |
"anthropic-workspace-id": workspace_id, |
| 311 |
} |
| 312 |
), |
| 313 |
**(extra_headers or {}), |
| 314 |
} |
| 315 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 316 |
return self._delete( |
| 317 |
path_template( |
| 318 |
"/v1/sessions/{session_id}/resources/{resource_id}?beta=true", |
| 319 |
session_id=session_id, |
| 320 |
resource_id=resource_id, |
| 321 |
), |
| 322 |
options=make_request_options( |
| 323 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 324 |
), |
| 325 |
cast_to=BetaManagedAgentsDeleteSessionResource, |
| 326 |
) |
| 327 |
|
| 328 |
def add( |
| 329 |
self, |
| 330 |
session_id: str, |
| 331 |
*, |
| 332 |
file_id: str, |
| 333 |
type: Literal["file"], |
| 334 |
mount_path: Optional[str] | Omit = omit, |
| 335 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 336 |
workspace_id: str | Omit = omit, |
| 337 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 338 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 339 |
extra_headers: Headers | None = None, |
| 340 |
extra_query: Query | None = None, |
| 341 |
extra_body: Body | None = None, |
| 342 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 343 |
) -> BetaManagedAgentsFileResource: |
| 344 |
""" |
| 345 |
Add Session Resource |
| 346 |
|
| 347 |
Args: |
| 348 |
file_id: ID of a previously uploaded file. |
| 349 |
|
| 350 |
mount_path: Mount path in the container. Defaults to `/mnt/session/uploads/<file_id>`. |
| 351 |
|
| 352 |
betas: Optional header to specify the beta version(s) you want to use. |
| 353 |
|
| 354 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 355 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 356 |
|
| 357 |
Only needed for credentials that can act on more than one Workspace. A |
| 358 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 359 |
match that Workspace. |
| 360 |
|
| 361 |
extra_headers: Send extra headers |
| 362 |
|
| 363 |
extra_query: Add additional query parameters to the request |
| 364 |
|
| 365 |
extra_body: Add additional JSON properties to the request |
| 366 |
|
| 367 |
timeout: Override the client-level default timeout for this request, in seconds |
| 368 |
""" |
| 369 |
if not session_id: |
| 370 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 371 |
extra_headers = { |
| 372 |
**strip_not_given( |
| 373 |
{ |
| 374 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 375 |
if is_given(betas) |
| 376 |
else not_given, |
| 377 |
"anthropic-workspace-id": workspace_id, |
| 378 |
} |
| 379 |
), |
| 380 |
**(extra_headers or {}), |
| 381 |
} |
| 382 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 383 |
return self._post( |
| 384 |
path_template("/v1/sessions/{session_id}/resources?beta=true", session_id=session_id), |
| 385 |
body={ |
| 386 |
"file_id": file_id, |
| 387 |
"type": type, |
| 388 |
"mount_path": mount_path, |
| 389 |
}, |
| 390 |
options=make_request_options( |
| 391 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 392 |
), |
| 393 |
cast_to=BetaManagedAgentsFileResource, |
| 394 |
) |
| 395 |
|
| 396 |
|
| 397 |
class AsyncResources(AsyncAPIResource): |
| 398 |
@cached_property |
| 399 |
def with_raw_response(self) -> AsyncResourcesWithRawResponse: |
| 400 |
""" |
| 401 |
This property can be used as a prefix for any HTTP method call to return |
| 402 |
the raw response object instead of the parsed content. |
| 403 |
|
| 404 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 405 |
""" |
| 406 |
return AsyncResourcesWithRawResponse(self) |
| 407 |
|
| 408 |
@cached_property |
| 409 |
def with_streaming_response(self) -> AsyncResourcesWithStreamingResponse: |
| 410 |
""" |
| 411 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 412 |
|
| 413 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 414 |
""" |
| 415 |
return AsyncResourcesWithStreamingResponse(self) |
| 416 |
|
| 417 |
async def retrieve( |
| 418 |
self, |
| 419 |
resource_id: str, |
| 420 |
*, |
| 421 |
session_id: str, |
| 422 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 423 |
workspace_id: str | Omit = omit, |
| 424 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 425 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 426 |
extra_headers: Headers | None = None, |
| 427 |
extra_query: Query | None = None, |
| 428 |
extra_body: Body | None = None, |
| 429 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 430 |
) -> ResourceRetrieveResponse: |
| 431 |
""" |
| 432 |
Get Session Resource |
| 433 |
|
| 434 |
Args: |
| 435 |
betas: Optional header to specify the beta version(s) you want to use. |
| 436 |
|
| 437 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 438 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 439 |
|
| 440 |
Only needed for credentials that can act on more than one Workspace. A |
| 441 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 442 |
match that Workspace. |
| 443 |
|
| 444 |
extra_headers: Send extra headers |
| 445 |
|
| 446 |
extra_query: Add additional query parameters to the request |
| 447 |
|
| 448 |
extra_body: Add additional JSON properties to the request |
| 449 |
|
| 450 |
timeout: Override the client-level default timeout for this request, in seconds |
| 451 |
""" |
| 452 |
if not session_id: |
| 453 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 454 |
if not resource_id: |
| 455 |
raise ValueError(f"Expected a non-empty value for `resource_id` but received {resource_id!r}") |
| 456 |
extra_headers = { |
| 457 |
**strip_not_given( |
| 458 |
{ |
| 459 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 460 |
if is_given(betas) |
| 461 |
else not_given, |
| 462 |
"anthropic-workspace-id": workspace_id, |
| 463 |
} |
| 464 |
), |
| 465 |
**(extra_headers or {}), |
| 466 |
} |
| 467 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 468 |
return cast( |
| 469 |
ResourceRetrieveResponse, |
| 470 |
await self._get( |
| 471 |
path_template( |
| 472 |
"/v1/sessions/{session_id}/resources/{resource_id}?beta=true", |
| 473 |
session_id=session_id, |
| 474 |
resource_id=resource_id, |
| 475 |
), |
| 476 |
options=make_request_options( |
| 477 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 478 |
), |
| 479 |
cast_to=cast( |
| 480 |
Any, ResourceRetrieveResponse |
| 481 |
), # Union types cannot be passed in as arguments in the type system |
| 482 |
), |
| 483 |
) |
| 484 |
|
| 485 |
async def update( |
| 486 |
self, |
| 487 |
resource_id: str, |
| 488 |
*, |
| 489 |
session_id: str, |
| 490 |
authorization_token: str, |
| 491 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 492 |
workspace_id: str | Omit = omit, |
| 493 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 494 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 495 |
extra_headers: Headers | None = None, |
| 496 |
extra_query: Query | None = None, |
| 497 |
extra_body: Body | None = None, |
| 498 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 499 |
) -> ResourceUpdateResponse: |
| 500 |
""" |
| 501 |
Update Session Resource |
| 502 |
|
| 503 |
Args: |
| 504 |
authorization_token: New authorization token for the resource. Currently only `github_repository` |
| 505 |
resources support token rotation. |
| 506 |
|
| 507 |
betas: Optional header to specify the beta version(s) you want to use. |
| 508 |
|
| 509 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 510 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 511 |
|
| 512 |
Only needed for credentials that can act on more than one Workspace. A |
| 513 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 514 |
match that Workspace. |
| 515 |
|
| 516 |
extra_headers: Send extra headers |
| 517 |
|
| 518 |
extra_query: Add additional query parameters to the request |
| 519 |
|
| 520 |
extra_body: Add additional JSON properties to the request |
| 521 |
|
| 522 |
timeout: Override the client-level default timeout for this request, in seconds |
| 523 |
""" |
| 524 |
if not session_id: |
| 525 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 526 |
if not resource_id: |
| 527 |
raise ValueError(f"Expected a non-empty value for `resource_id` but received {resource_id!r}") |
| 528 |
extra_headers = { |
| 529 |
**strip_not_given( |
| 530 |
{ |
| 531 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 532 |
if is_given(betas) |
| 533 |
else not_given, |
| 534 |
"anthropic-workspace-id": workspace_id, |
| 535 |
} |
| 536 |
), |
| 537 |
**(extra_headers or {}), |
| 538 |
} |
| 539 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 540 |
return cast( |
| 541 |
ResourceUpdateResponse, |
| 542 |
await self._post( |
| 543 |
path_template( |
| 544 |
"/v1/sessions/{session_id}/resources/{resource_id}?beta=true", |
| 545 |
session_id=session_id, |
| 546 |
resource_id=resource_id, |
| 547 |
), |
| 548 |
body={"authorization_token": authorization_token}, |
| 549 |
options=make_request_options( |
| 550 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 551 |
), |
| 552 |
cast_to=cast( |
| 553 |
Any, ResourceUpdateResponse |
| 554 |
), # Union types cannot be passed in as arguments in the type system |
| 555 |
), |
| 556 |
) |
| 557 |
|
| 558 |
def list( |
| 559 |
self, |
| 560 |
session_id: str, |
| 561 |
*, |
| 562 |
limit: int | Omit = omit, |
| 563 |
page: str | Omit = omit, |
| 564 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 565 |
workspace_id: str | Omit = omit, |
| 566 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 567 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 568 |
extra_headers: Headers | None = None, |
| 569 |
extra_query: Query | None = None, |
| 570 |
extra_body: Body | None = None, |
| 571 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 572 |
) -> AsyncPaginator[BetaManagedAgentsSessionResource, AsyncPageCursor[BetaManagedAgentsSessionResource]]: |
| 573 |
""" |
| 574 |
List Session Resources |
| 575 |
|
| 576 |
Args: |
| 577 |
limit: Maximum number of resources to return per page (max 1000). If omitted, returns |
| 578 |
all resources. |
| 579 |
|
| 580 |
page: Opaque cursor from a previous response's `next_page` field. |
| 581 |
|
| 582 |
betas: Optional header to specify the beta version(s) you want to use. |
| 583 |
|
| 584 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 585 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 586 |
|
| 587 |
Only needed for credentials that can act on more than one Workspace. A |
| 588 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 589 |
match that Workspace. |
| 590 |
|
| 591 |
extra_headers: Send extra headers |
| 592 |
|
| 593 |
extra_query: Add additional query parameters to the request |
| 594 |
|
| 595 |
extra_body: Add additional JSON properties to the request |
| 596 |
|
| 597 |
timeout: Override the client-level default timeout for this request, in seconds |
| 598 |
""" |
| 599 |
if not session_id: |
| 600 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 601 |
extra_headers = { |
| 602 |
**strip_not_given( |
| 603 |
{ |
| 604 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 605 |
if is_given(betas) |
| 606 |
else not_given, |
| 607 |
"anthropic-workspace-id": workspace_id, |
| 608 |
} |
| 609 |
), |
| 610 |
**(extra_headers or {}), |
| 611 |
} |
| 612 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 613 |
return self._get_api_list( |
| 614 |
path_template("/v1/sessions/{session_id}/resources?beta=true", session_id=session_id), |
| 615 |
page=AsyncPageCursor[BetaManagedAgentsSessionResource], |
| 616 |
options=make_request_options( |
| 617 |
extra_headers=extra_headers, |
| 618 |
extra_query=extra_query, |
| 619 |
extra_body=extra_body, |
| 620 |
timeout=timeout, |
| 621 |
query={ |
| 622 |
"limit": limit, |
| 623 |
"page": page, |
| 624 |
}, |
| 625 |
), |
| 626 |
model=cast( |
| 627 |
Any, BetaManagedAgentsSessionResource |
| 628 |
), # Union types cannot be passed in as arguments in the type system |
| 629 |
) |
| 630 |
|
| 631 |
async def delete( |
| 632 |
self, |
| 633 |
resource_id: str, |
| 634 |
*, |
| 635 |
session_id: str, |
| 636 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 637 |
workspace_id: str | Omit = omit, |
| 638 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 639 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 640 |
extra_headers: Headers | None = None, |
| 641 |
extra_query: Query | None = None, |
| 642 |
extra_body: Body | None = None, |
| 643 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 644 |
) -> BetaManagedAgentsDeleteSessionResource: |
| 645 |
""" |
| 646 |
Delete Session Resource |
| 647 |
|
| 648 |
Args: |
| 649 |
betas: Optional header to specify the beta version(s) you want to use. |
| 650 |
|
| 651 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 652 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 653 |
|
| 654 |
Only needed for credentials that can act on more than one Workspace. A |
| 655 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 656 |
match that Workspace. |
| 657 |
|
| 658 |
extra_headers: Send extra headers |
| 659 |
|
| 660 |
extra_query: Add additional query parameters to the request |
| 661 |
|
| 662 |
extra_body: Add additional JSON properties to the request |
| 663 |
|
| 664 |
timeout: Override the client-level default timeout for this request, in seconds |
| 665 |
""" |
| 666 |
if not session_id: |
| 667 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 668 |
if not resource_id: |
| 669 |
raise ValueError(f"Expected a non-empty value for `resource_id` but received {resource_id!r}") |
| 670 |
extra_headers = { |
| 671 |
**strip_not_given( |
| 672 |
{ |
| 673 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 674 |
if is_given(betas) |
| 675 |
else not_given, |
| 676 |
"anthropic-workspace-id": workspace_id, |
| 677 |
} |
| 678 |
), |
| 679 |
**(extra_headers or {}), |
| 680 |
} |
| 681 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 682 |
return await self._delete( |
| 683 |
path_template( |
| 684 |
"/v1/sessions/{session_id}/resources/{resource_id}?beta=true", |
| 685 |
session_id=session_id, |
| 686 |
resource_id=resource_id, |
| 687 |
), |
| 688 |
options=make_request_options( |
| 689 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 690 |
), |
| 691 |
cast_to=BetaManagedAgentsDeleteSessionResource, |
| 692 |
) |
| 693 |
|
| 694 |
async def add( |
| 695 |
self, |
| 696 |
session_id: str, |
| 697 |
*, |
| 698 |
file_id: str, |
| 699 |
type: Literal["file"], |
| 700 |
mount_path: Optional[str] | Omit = omit, |
| 701 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 702 |
workspace_id: str | Omit = omit, |
| 703 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 704 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 705 |
extra_headers: Headers | None = None, |
| 706 |
extra_query: Query | None = None, |
| 707 |
extra_body: Body | None = None, |
| 708 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 709 |
) -> BetaManagedAgentsFileResource: |
| 710 |
""" |
| 711 |
Add Session Resource |
| 712 |
|
| 713 |
Args: |
| 714 |
file_id: ID of a previously uploaded file. |
| 715 |
|
| 716 |
mount_path: Mount path in the container. Defaults to `/mnt/session/uploads/<file_id>`. |
| 717 |
|
| 718 |
betas: Optional header to specify the beta version(s) you want to use. |
| 719 |
|
| 720 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 721 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 722 |
|
| 723 |
Only needed for credentials that can act on more than one Workspace. A |
| 724 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 725 |
match that Workspace. |
| 726 |
|
| 727 |
extra_headers: Send extra headers |
| 728 |
|
| 729 |
extra_query: Add additional query parameters to the request |
| 730 |
|
| 731 |
extra_body: Add additional JSON properties to the request |
| 732 |
|
| 733 |
timeout: Override the client-level default timeout for this request, in seconds |
| 734 |
""" |
| 735 |
if not session_id: |
| 736 |
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}") |
| 737 |
extra_headers = { |
| 738 |
**strip_not_given( |
| 739 |
{ |
| 740 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 741 |
if is_given(betas) |
| 742 |
else not_given, |
| 743 |
"anthropic-workspace-id": workspace_id, |
| 744 |
} |
| 745 |
), |
| 746 |
**(extra_headers or {}), |
| 747 |
} |
| 748 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 749 |
return await self._post( |
| 750 |
path_template("/v1/sessions/{session_id}/resources?beta=true", session_id=session_id), |
| 751 |
body={ |
| 752 |
"file_id": file_id, |
| 753 |
"type": type, |
| 754 |
"mount_path": mount_path, |
| 755 |
}, |
| 756 |
options=make_request_options( |
| 757 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 758 |
), |
| 759 |
cast_to=BetaManagedAgentsFileResource, |
| 760 |
) |
| 761 |
|
| 762 |
|
| 763 |
class ResourcesWithRawResponse: |
| 764 |
def __init__(self, resources: Resources) -> None: |
| 765 |
self._resources = resources |
| 766 |
|
| 767 |
self.retrieve = to_raw_response_wrapper( |
| 768 |
resources.retrieve, |
| 769 |
) |
| 770 |
self.update = to_raw_response_wrapper( |
| 771 |
resources.update, |
| 772 |
) |
| 773 |
self.list = to_raw_response_wrapper( |
| 774 |
resources.list, |
| 775 |
) |
| 776 |
self.delete = to_raw_response_wrapper( |
| 777 |
resources.delete, |
| 778 |
) |
| 779 |
self.add = to_raw_response_wrapper( |
| 780 |
resources.add, |
| 781 |
) |
| 782 |
|
| 783 |
|
| 784 |
class AsyncResourcesWithRawResponse: |
| 785 |
def __init__(self, resources: AsyncResources) -> None: |
| 786 |
self._resources = resources |
| 787 |
|
| 788 |
self.retrieve = async_to_raw_response_wrapper( |
| 789 |
resources.retrieve, |
| 790 |
) |
| 791 |
self.update = async_to_raw_response_wrapper( |
| 792 |
resources.update, |
| 793 |
) |
| 794 |
self.list = async_to_raw_response_wrapper( |
| 795 |
resources.list, |
| 796 |
) |
| 797 |
self.delete = async_to_raw_response_wrapper( |
| 798 |
resources.delete, |
| 799 |
) |
| 800 |
self.add = async_to_raw_response_wrapper( |
| 801 |
resources.add, |
| 802 |
) |
| 803 |
|
| 804 |
|
| 805 |
class ResourcesWithStreamingResponse: |
| 806 |
def __init__(self, resources: Resources) -> None: |
| 807 |
self._resources = resources |
| 808 |
|
| 809 |
self.retrieve = to_streamed_response_wrapper( |
| 810 |
resources.retrieve, |
| 811 |
) |
| 812 |
self.update = to_streamed_response_wrapper( |
| 813 |
resources.update, |
| 814 |
) |
| 815 |
self.list = to_streamed_response_wrapper( |
| 816 |
resources.list, |
| 817 |
) |
| 818 |
self.delete = to_streamed_response_wrapper( |
| 819 |
resources.delete, |
| 820 |
) |
| 821 |
self.add = to_streamed_response_wrapper( |
| 822 |
resources.add, |
| 823 |
) |
| 824 |
|
| 825 |
|
| 826 |
class AsyncResourcesWithStreamingResponse: |
| 827 |
def __init__(self, resources: AsyncResources) -> None: |
| 828 |
self._resources = resources |
| 829 |
|
| 830 |
self.retrieve = async_to_streamed_response_wrapper( |
| 831 |
resources.retrieve, |
| 832 |
) |
| 833 |
self.update = async_to_streamed_response_wrapper( |
| 834 |
resources.update, |
| 835 |
) |
| 836 |
self.list = async_to_streamed_response_wrapper( |
| 837 |
resources.list, |
| 838 |
) |
| 839 |
self.delete = async_to_streamed_response_wrapper( |
| 840 |
resources.delete, |
| 841 |
) |
| 842 |
self.add = async_to_streamed_response_wrapper( |
| 843 |
resources.add, |
| 844 |
) |