| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Dict, List, Optional |
| 4 |
from itertools import chain |
| 5 |
from typing_extensions import Literal |
| 6 |
|
| 7 |
import httpx2 |
| 8 |
|
| 9 |
from .work import ( |
| 10 |
Work, |
| 11 |
AsyncWork, |
| 12 |
WorkWithRawResponse, |
| 13 |
AsyncWorkWithRawResponse, |
| 14 |
WorkWithStreamingResponse, |
| 15 |
AsyncWorkWithStreamingResponse, |
| 16 |
) |
| 17 |
from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 18 |
from ...._utils import is_given, path_template, strip_not_given |
| 19 |
from ...._compat import cached_property |
| 20 |
from ...._resource import SyncAPIResource, AsyncAPIResource |
| 21 |
from ...._response import ( |
| 22 |
to_raw_response_wrapper, |
| 23 |
to_streamed_response_wrapper, |
| 24 |
async_to_raw_response_wrapper, |
| 25 |
async_to_streamed_response_wrapper, |
| 26 |
) |
| 27 |
from ....pagination import SyncPageCursor, AsyncPageCursor |
| 28 |
from ....types.beta import environment_create_params, environment_update_params |
| 29 |
from ...._base_client import AsyncPaginator, make_request_options |
| 30 |
from ....types.anthropic_beta_param import AnthropicBetaParam |
| 31 |
from ....types.beta.beta_environment import BetaEnvironment |
| 32 |
from ....types.beta.beta_environment_delete_response import BetaEnvironmentDeleteResponse |
| 33 |
|
| 34 |
__all__ = ["Environments", "AsyncEnvironments"] |
| 35 |
|
| 36 |
|
| 37 |
class Environments(SyncAPIResource): |
| 38 |
@cached_property |
| 39 |
def work(self) -> Work: |
| 40 |
return Work(self._client) |
| 41 |
|
| 42 |
@cached_property |
| 43 |
def with_raw_response(self) -> EnvironmentsWithRawResponse: |
| 44 |
""" |
| 45 |
This property can be used as a prefix for any HTTP method call to return |
| 46 |
the raw response object instead of the parsed content. |
| 47 |
|
| 48 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 49 |
""" |
| 50 |
return EnvironmentsWithRawResponse(self) |
| 51 |
|
| 52 |
@cached_property |
| 53 |
def with_streaming_response(self) -> EnvironmentsWithStreamingResponse: |
| 54 |
""" |
| 55 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 56 |
|
| 57 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 58 |
""" |
| 59 |
return EnvironmentsWithStreamingResponse(self) |
| 60 |
|
| 61 |
def create( |
| 62 |
self, |
| 63 |
*, |
| 64 |
name: str, |
| 65 |
config: Optional[environment_create_params.Config] | Omit = omit, |
| 66 |
description: Optional[str] | Omit = omit, |
| 67 |
metadata: Dict[str, str] | Omit = omit, |
| 68 |
scope: Optional[Literal["organization", "account"]] | Omit = omit, |
| 69 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 70 |
workspace_id: str | Omit = omit, |
| 71 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 72 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 73 |
extra_headers: Headers | None = None, |
| 74 |
extra_query: Query | None = None, |
| 75 |
extra_body: Body | None = None, |
| 76 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 77 |
) -> BetaEnvironment: |
| 78 |
""" |
| 79 |
Create a new environment with the specified configuration. |
| 80 |
|
| 81 |
Args: |
| 82 |
name: Human-readable name for the environment |
| 83 |
|
| 84 |
config: Environment configuration |
| 85 |
|
| 86 |
description: Optional description of the environment |
| 87 |
|
| 88 |
metadata: User-provided metadata key-value pairs |
| 89 |
|
| 90 |
scope: The visibility scope for this environment. 'organization' makes the environment |
| 91 |
visible to all accounts. 'account' restricts visibility to the owning account |
| 92 |
only. API organizations support only 'organization'; 'account' is rejected. If |
| 93 |
not specified, defaults based on organization type. |
| 94 |
|
| 95 |
betas: Optional header to specify the beta version(s) you want to use. |
| 96 |
|
| 97 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 98 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 99 |
|
| 100 |
Only needed for credentials that can act on more than one Workspace. A |
| 101 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 102 |
match that Workspace. |
| 103 |
|
| 104 |
extra_headers: Send extra headers |
| 105 |
|
| 106 |
extra_query: Add additional query parameters to the request |
| 107 |
|
| 108 |
extra_body: Add additional JSON properties to the request |
| 109 |
|
| 110 |
timeout: Override the client-level default timeout for this request, in seconds |
| 111 |
""" |
| 112 |
extra_headers = { |
| 113 |
**strip_not_given( |
| 114 |
{ |
| 115 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 116 |
if is_given(betas) |
| 117 |
else not_given, |
| 118 |
"anthropic-workspace-id": workspace_id, |
| 119 |
} |
| 120 |
), |
| 121 |
**(extra_headers or {}), |
| 122 |
} |
| 123 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 124 |
return self._post( |
| 125 |
"/v1/environments?beta=true", |
| 126 |
body={ |
| 127 |
"name": name, |
| 128 |
"config": config, |
| 129 |
"description": description, |
| 130 |
"metadata": metadata, |
| 131 |
"scope": scope, |
| 132 |
}, |
| 133 |
options=make_request_options( |
| 134 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 135 |
), |
| 136 |
cast_to=BetaEnvironment, |
| 137 |
) |
| 138 |
|
| 139 |
def retrieve( |
| 140 |
self, |
| 141 |
environment_id: str, |
| 142 |
*, |
| 143 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 144 |
workspace_id: str | Omit = omit, |
| 145 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 146 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 147 |
extra_headers: Headers | None = None, |
| 148 |
extra_query: Query | None = None, |
| 149 |
extra_body: Body | None = None, |
| 150 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 151 |
) -> BetaEnvironment: |
| 152 |
""" |
| 153 |
Retrieve a specific environment by ID. |
| 154 |
|
| 155 |
Args: |
| 156 |
betas: Optional header to specify the beta version(s) you want to use. |
| 157 |
|
| 158 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 159 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 160 |
|
| 161 |
Only needed for credentials that can act on more than one Workspace. A |
| 162 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 163 |
match that Workspace. |
| 164 |
|
| 165 |
extra_headers: Send extra headers |
| 166 |
|
| 167 |
extra_query: Add additional query parameters to the request |
| 168 |
|
| 169 |
extra_body: Add additional JSON properties to the request |
| 170 |
|
| 171 |
timeout: Override the client-level default timeout for this request, in seconds |
| 172 |
""" |
| 173 |
if not environment_id: |
| 174 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 175 |
extra_headers = { |
| 176 |
**strip_not_given( |
| 177 |
{ |
| 178 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 179 |
if is_given(betas) |
| 180 |
else not_given, |
| 181 |
"anthropic-workspace-id": workspace_id, |
| 182 |
} |
| 183 |
), |
| 184 |
**(extra_headers or {}), |
| 185 |
} |
| 186 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 187 |
return self._get( |
| 188 |
path_template("/v1/environments/{environment_id}?beta=true", environment_id=environment_id), |
| 189 |
options=make_request_options( |
| 190 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 191 |
), |
| 192 |
cast_to=BetaEnvironment, |
| 193 |
) |
| 194 |
|
| 195 |
def update( |
| 196 |
self, |
| 197 |
environment_id: str, |
| 198 |
*, |
| 199 |
config: Optional[environment_update_params.Config] | Omit = omit, |
| 200 |
description: Optional[str] | Omit = omit, |
| 201 |
metadata: Dict[str, Optional[str]] | Omit = omit, |
| 202 |
name: Optional[str] | Omit = omit, |
| 203 |
scope: Optional[Literal["organization", "account"]] | Omit = omit, |
| 204 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 205 |
workspace_id: str | Omit = omit, |
| 206 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 207 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 208 |
extra_headers: Headers | None = None, |
| 209 |
extra_query: Query | None = None, |
| 210 |
extra_body: Body | None = None, |
| 211 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 212 |
) -> BetaEnvironment: |
| 213 |
""" |
| 214 |
Update an existing environment's configuration. |
| 215 |
|
| 216 |
Args: |
| 217 |
config: Updated environment configuration |
| 218 |
|
| 219 |
description: Updated description of the environment. Omit to preserve; null clears to null; |
| 220 |
an empty string is stored as an empty string. |
| 221 |
|
| 222 |
metadata: User-provided metadata key-value pairs. Set a value to null or empty string to |
| 223 |
delete the key. |
| 224 |
|
| 225 |
name: Updated name for the environment |
| 226 |
|
| 227 |
scope: The visibility scope for this environment. 'organization' makes the environment |
| 228 |
visible to all accounts. 'account' restricts visibility to the owning account |
| 229 |
only. |
| 230 |
|
| 231 |
betas: Optional header to specify the beta version(s) you want to use. |
| 232 |
|
| 233 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 234 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 235 |
|
| 236 |
Only needed for credentials that can act on more than one Workspace. A |
| 237 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 238 |
match that Workspace. |
| 239 |
|
| 240 |
extra_headers: Send extra headers |
| 241 |
|
| 242 |
extra_query: Add additional query parameters to the request |
| 243 |
|
| 244 |
extra_body: Add additional JSON properties to the request |
| 245 |
|
| 246 |
timeout: Override the client-level default timeout for this request, in seconds |
| 247 |
""" |
| 248 |
if not environment_id: |
| 249 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 250 |
extra_headers = { |
| 251 |
**strip_not_given( |
| 252 |
{ |
| 253 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 254 |
if is_given(betas) |
| 255 |
else not_given, |
| 256 |
"anthropic-workspace-id": workspace_id, |
| 257 |
} |
| 258 |
), |
| 259 |
**(extra_headers or {}), |
| 260 |
} |
| 261 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 262 |
return self._post( |
| 263 |
path_template("/v1/environments/{environment_id}?beta=true", environment_id=environment_id), |
| 264 |
body={ |
| 265 |
"config": config, |
| 266 |
"description": description, |
| 267 |
"metadata": metadata, |
| 268 |
"name": name, |
| 269 |
"scope": scope, |
| 270 |
}, |
| 271 |
options=make_request_options( |
| 272 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 273 |
), |
| 274 |
cast_to=BetaEnvironment, |
| 275 |
) |
| 276 |
|
| 277 |
def list( |
| 278 |
self, |
| 279 |
*, |
| 280 |
include_archived: bool | Omit = omit, |
| 281 |
limit: int | Omit = omit, |
| 282 |
page: Optional[str] | Omit = omit, |
| 283 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 284 |
workspace_id: str | Omit = omit, |
| 285 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 286 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 287 |
extra_headers: Headers | None = None, |
| 288 |
extra_query: Query | None = None, |
| 289 |
extra_body: Body | None = None, |
| 290 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 291 |
) -> SyncPageCursor[BetaEnvironment]: |
| 292 |
""" |
| 293 |
List environments with pagination support. |
| 294 |
|
| 295 |
Args: |
| 296 |
include_archived: Include archived environments in the response |
| 297 |
|
| 298 |
limit: Maximum number of environments to return |
| 299 |
|
| 300 |
page: Opaque cursor from previous response for pagination. Pass the `next_page` value |
| 301 |
from the previous response. |
| 302 |
|
| 303 |
betas: Optional header to specify the beta version(s) you want to use. |
| 304 |
|
| 305 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 306 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 307 |
|
| 308 |
Only needed for credentials that can act on more than one Workspace. A |
| 309 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 310 |
match that Workspace. |
| 311 |
|
| 312 |
extra_headers: Send extra headers |
| 313 |
|
| 314 |
extra_query: Add additional query parameters to the request |
| 315 |
|
| 316 |
extra_body: Add additional JSON properties to the request |
| 317 |
|
| 318 |
timeout: Override the client-level default timeout for this request, in seconds |
| 319 |
""" |
| 320 |
extra_headers = { |
| 321 |
**strip_not_given( |
| 322 |
{ |
| 323 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 324 |
if is_given(betas) |
| 325 |
else not_given, |
| 326 |
"anthropic-workspace-id": workspace_id, |
| 327 |
} |
| 328 |
), |
| 329 |
**(extra_headers or {}), |
| 330 |
} |
| 331 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 332 |
return self._get_api_list( |
| 333 |
"/v1/environments?beta=true", |
| 334 |
page=SyncPageCursor[BetaEnvironment], |
| 335 |
options=make_request_options( |
| 336 |
extra_headers=extra_headers, |
| 337 |
extra_query=extra_query, |
| 338 |
extra_body=extra_body, |
| 339 |
timeout=timeout, |
| 340 |
query={ |
| 341 |
"include_archived": include_archived, |
| 342 |
"limit": limit, |
| 343 |
"page": page, |
| 344 |
}, |
| 345 |
), |
| 346 |
model=BetaEnvironment, |
| 347 |
) |
| 348 |
|
| 349 |
def delete( |
| 350 |
self, |
| 351 |
environment_id: str, |
| 352 |
*, |
| 353 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 354 |
workspace_id: str | Omit = omit, |
| 355 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 356 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 357 |
extra_headers: Headers | None = None, |
| 358 |
extra_query: Query | None = None, |
| 359 |
extra_body: Body | None = None, |
| 360 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 361 |
) -> BetaEnvironmentDeleteResponse: |
| 362 |
"""Delete an environment by ID. |
| 363 |
|
| 364 |
Returns a confirmation of the deletion. |
| 365 |
|
| 366 |
Args: |
| 367 |
betas: Optional header to specify the beta version(s) you want to use. |
| 368 |
|
| 369 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 370 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 371 |
|
| 372 |
Only needed for credentials that can act on more than one Workspace. A |
| 373 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 374 |
match that Workspace. |
| 375 |
|
| 376 |
extra_headers: Send extra headers |
| 377 |
|
| 378 |
extra_query: Add additional query parameters to the request |
| 379 |
|
| 380 |
extra_body: Add additional JSON properties to the request |
| 381 |
|
| 382 |
timeout: Override the client-level default timeout for this request, in seconds |
| 383 |
""" |
| 384 |
if not environment_id: |
| 385 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 386 |
extra_headers = { |
| 387 |
**strip_not_given( |
| 388 |
{ |
| 389 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 390 |
if is_given(betas) |
| 391 |
else not_given, |
| 392 |
"anthropic-workspace-id": workspace_id, |
| 393 |
} |
| 394 |
), |
| 395 |
**(extra_headers or {}), |
| 396 |
} |
| 397 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 398 |
return self._delete( |
| 399 |
path_template("/v1/environments/{environment_id}?beta=true", environment_id=environment_id), |
| 400 |
options=make_request_options( |
| 401 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 402 |
), |
| 403 |
cast_to=BetaEnvironmentDeleteResponse, |
| 404 |
) |
| 405 |
|
| 406 |
def archive( |
| 407 |
self, |
| 408 |
environment_id: str, |
| 409 |
*, |
| 410 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 411 |
workspace_id: str | Omit = omit, |
| 412 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 413 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 414 |
extra_headers: Headers | None = None, |
| 415 |
extra_query: Query | None = None, |
| 416 |
extra_body: Body | None = None, |
| 417 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 418 |
) -> BetaEnvironment: |
| 419 |
"""Archive an environment by ID. |
| 420 |
|
| 421 |
Archived environments cannot be used to create new |
| 422 |
sessions. |
| 423 |
|
| 424 |
Args: |
| 425 |
betas: Optional header to specify the beta version(s) you want to use. |
| 426 |
|
| 427 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 428 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 429 |
|
| 430 |
Only needed for credentials that can act on more than one Workspace. A |
| 431 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 432 |
match that Workspace. |
| 433 |
|
| 434 |
extra_headers: Send extra headers |
| 435 |
|
| 436 |
extra_query: Add additional query parameters to the request |
| 437 |
|
| 438 |
extra_body: Add additional JSON properties to the request |
| 439 |
|
| 440 |
timeout: Override the client-level default timeout for this request, in seconds |
| 441 |
""" |
| 442 |
if not environment_id: |
| 443 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 444 |
extra_headers = { |
| 445 |
**strip_not_given( |
| 446 |
{ |
| 447 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 448 |
if is_given(betas) |
| 449 |
else not_given, |
| 450 |
"anthropic-workspace-id": workspace_id, |
| 451 |
} |
| 452 |
), |
| 453 |
**(extra_headers or {}), |
| 454 |
} |
| 455 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 456 |
return self._post( |
| 457 |
path_template("/v1/environments/{environment_id}/archive?beta=true", environment_id=environment_id), |
| 458 |
options=make_request_options( |
| 459 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 460 |
), |
| 461 |
cast_to=BetaEnvironment, |
| 462 |
) |
| 463 |
|
| 464 |
|
| 465 |
class AsyncEnvironments(AsyncAPIResource): |
| 466 |
@cached_property |
| 467 |
def work(self) -> AsyncWork: |
| 468 |
return AsyncWork(self._client) |
| 469 |
|
| 470 |
@cached_property |
| 471 |
def with_raw_response(self) -> AsyncEnvironmentsWithRawResponse: |
| 472 |
""" |
| 473 |
This property can be used as a prefix for any HTTP method call to return |
| 474 |
the raw response object instead of the parsed content. |
| 475 |
|
| 476 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 477 |
""" |
| 478 |
return AsyncEnvironmentsWithRawResponse(self) |
| 479 |
|
| 480 |
@cached_property |
| 481 |
def with_streaming_response(self) -> AsyncEnvironmentsWithStreamingResponse: |
| 482 |
""" |
| 483 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 484 |
|
| 485 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 486 |
""" |
| 487 |
return AsyncEnvironmentsWithStreamingResponse(self) |
| 488 |
|
| 489 |
async def create( |
| 490 |
self, |
| 491 |
*, |
| 492 |
name: str, |
| 493 |
config: Optional[environment_create_params.Config] | Omit = omit, |
| 494 |
description: Optional[str] | Omit = omit, |
| 495 |
metadata: Dict[str, str] | Omit = omit, |
| 496 |
scope: Optional[Literal["organization", "account"]] | Omit = omit, |
| 497 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 498 |
workspace_id: str | Omit = omit, |
| 499 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 500 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 501 |
extra_headers: Headers | None = None, |
| 502 |
extra_query: Query | None = None, |
| 503 |
extra_body: Body | None = None, |
| 504 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 505 |
) -> BetaEnvironment: |
| 506 |
""" |
| 507 |
Create a new environment with the specified configuration. |
| 508 |
|
| 509 |
Args: |
| 510 |
name: Human-readable name for the environment |
| 511 |
|
| 512 |
config: Environment configuration |
| 513 |
|
| 514 |
description: Optional description of the environment |
| 515 |
|
| 516 |
metadata: User-provided metadata key-value pairs |
| 517 |
|
| 518 |
scope: The visibility scope for this environment. 'organization' makes the environment |
| 519 |
visible to all accounts. 'account' restricts visibility to the owning account |
| 520 |
only. API organizations support only 'organization'; 'account' is rejected. If |
| 521 |
not specified, defaults based on organization type. |
| 522 |
|
| 523 |
betas: Optional header to specify the beta version(s) you want to use. |
| 524 |
|
| 525 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 526 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 527 |
|
| 528 |
Only needed for credentials that can act on more than one Workspace. A |
| 529 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 530 |
match that Workspace. |
| 531 |
|
| 532 |
extra_headers: Send extra headers |
| 533 |
|
| 534 |
extra_query: Add additional query parameters to the request |
| 535 |
|
| 536 |
extra_body: Add additional JSON properties to the request |
| 537 |
|
| 538 |
timeout: Override the client-level default timeout for this request, in seconds |
| 539 |
""" |
| 540 |
extra_headers = { |
| 541 |
**strip_not_given( |
| 542 |
{ |
| 543 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 544 |
if is_given(betas) |
| 545 |
else not_given, |
| 546 |
"anthropic-workspace-id": workspace_id, |
| 547 |
} |
| 548 |
), |
| 549 |
**(extra_headers or {}), |
| 550 |
} |
| 551 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 552 |
return await self._post( |
| 553 |
"/v1/environments?beta=true", |
| 554 |
body={ |
| 555 |
"name": name, |
| 556 |
"config": config, |
| 557 |
"description": description, |
| 558 |
"metadata": metadata, |
| 559 |
"scope": scope, |
| 560 |
}, |
| 561 |
options=make_request_options( |
| 562 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 563 |
), |
| 564 |
cast_to=BetaEnvironment, |
| 565 |
) |
| 566 |
|
| 567 |
async def retrieve( |
| 568 |
self, |
| 569 |
environment_id: str, |
| 570 |
*, |
| 571 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 572 |
workspace_id: str | Omit = omit, |
| 573 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 574 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 575 |
extra_headers: Headers | None = None, |
| 576 |
extra_query: Query | None = None, |
| 577 |
extra_body: Body | None = None, |
| 578 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 579 |
) -> BetaEnvironment: |
| 580 |
""" |
| 581 |
Retrieve a specific environment by ID. |
| 582 |
|
| 583 |
Args: |
| 584 |
betas: Optional header to specify the beta version(s) you want to use. |
| 585 |
|
| 586 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 587 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 588 |
|
| 589 |
Only needed for credentials that can act on more than one Workspace. A |
| 590 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 591 |
match that Workspace. |
| 592 |
|
| 593 |
extra_headers: Send extra headers |
| 594 |
|
| 595 |
extra_query: Add additional query parameters to the request |
| 596 |
|
| 597 |
extra_body: Add additional JSON properties to the request |
| 598 |
|
| 599 |
timeout: Override the client-level default timeout for this request, in seconds |
| 600 |
""" |
| 601 |
if not environment_id: |
| 602 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 603 |
extra_headers = { |
| 604 |
**strip_not_given( |
| 605 |
{ |
| 606 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 607 |
if is_given(betas) |
| 608 |
else not_given, |
| 609 |
"anthropic-workspace-id": workspace_id, |
| 610 |
} |
| 611 |
), |
| 612 |
**(extra_headers or {}), |
| 613 |
} |
| 614 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 615 |
return await self._get( |
| 616 |
path_template("/v1/environments/{environment_id}?beta=true", environment_id=environment_id), |
| 617 |
options=make_request_options( |
| 618 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 619 |
), |
| 620 |
cast_to=BetaEnvironment, |
| 621 |
) |
| 622 |
|
| 623 |
async def update( |
| 624 |
self, |
| 625 |
environment_id: str, |
| 626 |
*, |
| 627 |
config: Optional[environment_update_params.Config] | Omit = omit, |
| 628 |
description: Optional[str] | Omit = omit, |
| 629 |
metadata: Dict[str, Optional[str]] | Omit = omit, |
| 630 |
name: Optional[str] | Omit = omit, |
| 631 |
scope: Optional[Literal["organization", "account"]] | Omit = omit, |
| 632 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 633 |
workspace_id: str | Omit = omit, |
| 634 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 635 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 636 |
extra_headers: Headers | None = None, |
| 637 |
extra_query: Query | None = None, |
| 638 |
extra_body: Body | None = None, |
| 639 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 640 |
) -> BetaEnvironment: |
| 641 |
""" |
| 642 |
Update an existing environment's configuration. |
| 643 |
|
| 644 |
Args: |
| 645 |
config: Updated environment configuration |
| 646 |
|
| 647 |
description: Updated description of the environment. Omit to preserve; null clears to null; |
| 648 |
an empty string is stored as an empty string. |
| 649 |
|
| 650 |
metadata: User-provided metadata key-value pairs. Set a value to null or empty string to |
| 651 |
delete the key. |
| 652 |
|
| 653 |
name: Updated name for the environment |
| 654 |
|
| 655 |
scope: The visibility scope for this environment. 'organization' makes the environment |
| 656 |
visible to all accounts. 'account' restricts visibility to the owning account |
| 657 |
only. |
| 658 |
|
| 659 |
betas: Optional header to specify the beta version(s) you want to use. |
| 660 |
|
| 661 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 662 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 663 |
|
| 664 |
Only needed for credentials that can act on more than one Workspace. A |
| 665 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 666 |
match that Workspace. |
| 667 |
|
| 668 |
extra_headers: Send extra headers |
| 669 |
|
| 670 |
extra_query: Add additional query parameters to the request |
| 671 |
|
| 672 |
extra_body: Add additional JSON properties to the request |
| 673 |
|
| 674 |
timeout: Override the client-level default timeout for this request, in seconds |
| 675 |
""" |
| 676 |
if not environment_id: |
| 677 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 678 |
extra_headers = { |
| 679 |
**strip_not_given( |
| 680 |
{ |
| 681 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 682 |
if is_given(betas) |
| 683 |
else not_given, |
| 684 |
"anthropic-workspace-id": workspace_id, |
| 685 |
} |
| 686 |
), |
| 687 |
**(extra_headers or {}), |
| 688 |
} |
| 689 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 690 |
return await self._post( |
| 691 |
path_template("/v1/environments/{environment_id}?beta=true", environment_id=environment_id), |
| 692 |
body={ |
| 693 |
"config": config, |
| 694 |
"description": description, |
| 695 |
"metadata": metadata, |
| 696 |
"name": name, |
| 697 |
"scope": scope, |
| 698 |
}, |
| 699 |
options=make_request_options( |
| 700 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 701 |
), |
| 702 |
cast_to=BetaEnvironment, |
| 703 |
) |
| 704 |
|
| 705 |
def list( |
| 706 |
self, |
| 707 |
*, |
| 708 |
include_archived: bool | Omit = omit, |
| 709 |
limit: int | Omit = omit, |
| 710 |
page: Optional[str] | Omit = omit, |
| 711 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 712 |
workspace_id: str | Omit = omit, |
| 713 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 714 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 715 |
extra_headers: Headers | None = None, |
| 716 |
extra_query: Query | None = None, |
| 717 |
extra_body: Body | None = None, |
| 718 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 719 |
) -> AsyncPaginator[BetaEnvironment, AsyncPageCursor[BetaEnvironment]]: |
| 720 |
""" |
| 721 |
List environments with pagination support. |
| 722 |
|
| 723 |
Args: |
| 724 |
include_archived: Include archived environments in the response |
| 725 |
|
| 726 |
limit: Maximum number of environments to return |
| 727 |
|
| 728 |
page: Opaque cursor from previous response for pagination. Pass the `next_page` value |
| 729 |
from the previous response. |
| 730 |
|
| 731 |
betas: Optional header to specify the beta version(s) you want to use. |
| 732 |
|
| 733 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 734 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 735 |
|
| 736 |
Only needed for credentials that can act on more than one Workspace. A |
| 737 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 738 |
match that Workspace. |
| 739 |
|
| 740 |
extra_headers: Send extra headers |
| 741 |
|
| 742 |
extra_query: Add additional query parameters to the request |
| 743 |
|
| 744 |
extra_body: Add additional JSON properties to the request |
| 745 |
|
| 746 |
timeout: Override the client-level default timeout for this request, in seconds |
| 747 |
""" |
| 748 |
extra_headers = { |
| 749 |
**strip_not_given( |
| 750 |
{ |
| 751 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 752 |
if is_given(betas) |
| 753 |
else not_given, |
| 754 |
"anthropic-workspace-id": workspace_id, |
| 755 |
} |
| 756 |
), |
| 757 |
**(extra_headers or {}), |
| 758 |
} |
| 759 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 760 |
return self._get_api_list( |
| 761 |
"/v1/environments?beta=true", |
| 762 |
page=AsyncPageCursor[BetaEnvironment], |
| 763 |
options=make_request_options( |
| 764 |
extra_headers=extra_headers, |
| 765 |
extra_query=extra_query, |
| 766 |
extra_body=extra_body, |
| 767 |
timeout=timeout, |
| 768 |
query={ |
| 769 |
"include_archived": include_archived, |
| 770 |
"limit": limit, |
| 771 |
"page": page, |
| 772 |
}, |
| 773 |
), |
| 774 |
model=BetaEnvironment, |
| 775 |
) |
| 776 |
|
| 777 |
async def delete( |
| 778 |
self, |
| 779 |
environment_id: str, |
| 780 |
*, |
| 781 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 782 |
workspace_id: str | Omit = omit, |
| 783 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 784 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 785 |
extra_headers: Headers | None = None, |
| 786 |
extra_query: Query | None = None, |
| 787 |
extra_body: Body | None = None, |
| 788 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 789 |
) -> BetaEnvironmentDeleteResponse: |
| 790 |
"""Delete an environment by ID. |
| 791 |
|
| 792 |
Returns a confirmation of the deletion. |
| 793 |
|
| 794 |
Args: |
| 795 |
betas: Optional header to specify the beta version(s) you want to use. |
| 796 |
|
| 797 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 798 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 799 |
|
| 800 |
Only needed for credentials that can act on more than one Workspace. A |
| 801 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 802 |
match that Workspace. |
| 803 |
|
| 804 |
extra_headers: Send extra headers |
| 805 |
|
| 806 |
extra_query: Add additional query parameters to the request |
| 807 |
|
| 808 |
extra_body: Add additional JSON properties to the request |
| 809 |
|
| 810 |
timeout: Override the client-level default timeout for this request, in seconds |
| 811 |
""" |
| 812 |
if not environment_id: |
| 813 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 814 |
extra_headers = { |
| 815 |
**strip_not_given( |
| 816 |
{ |
| 817 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 818 |
if is_given(betas) |
| 819 |
else not_given, |
| 820 |
"anthropic-workspace-id": workspace_id, |
| 821 |
} |
| 822 |
), |
| 823 |
**(extra_headers or {}), |
| 824 |
} |
| 825 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 826 |
return await self._delete( |
| 827 |
path_template("/v1/environments/{environment_id}?beta=true", environment_id=environment_id), |
| 828 |
options=make_request_options( |
| 829 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 830 |
), |
| 831 |
cast_to=BetaEnvironmentDeleteResponse, |
| 832 |
) |
| 833 |
|
| 834 |
async def archive( |
| 835 |
self, |
| 836 |
environment_id: str, |
| 837 |
*, |
| 838 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 839 |
workspace_id: str | Omit = omit, |
| 840 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 841 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 842 |
extra_headers: Headers | None = None, |
| 843 |
extra_query: Query | None = None, |
| 844 |
extra_body: Body | None = None, |
| 845 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 846 |
) -> BetaEnvironment: |
| 847 |
"""Archive an environment by ID. |
| 848 |
|
| 849 |
Archived environments cannot be used to create new |
| 850 |
sessions. |
| 851 |
|
| 852 |
Args: |
| 853 |
betas: Optional header to specify the beta version(s) you want to use. |
| 854 |
|
| 855 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 856 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 857 |
|
| 858 |
Only needed for credentials that can act on more than one Workspace. A |
| 859 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 860 |
match that Workspace. |
| 861 |
|
| 862 |
extra_headers: Send extra headers |
| 863 |
|
| 864 |
extra_query: Add additional query parameters to the request |
| 865 |
|
| 866 |
extra_body: Add additional JSON properties to the request |
| 867 |
|
| 868 |
timeout: Override the client-level default timeout for this request, in seconds |
| 869 |
""" |
| 870 |
if not environment_id: |
| 871 |
raise ValueError(f"Expected a non-empty value for `environment_id` but received {environment_id!r}") |
| 872 |
extra_headers = { |
| 873 |
**strip_not_given( |
| 874 |
{ |
| 875 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 876 |
if is_given(betas) |
| 877 |
else not_given, |
| 878 |
"anthropic-workspace-id": workspace_id, |
| 879 |
} |
| 880 |
), |
| 881 |
**(extra_headers or {}), |
| 882 |
} |
| 883 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 884 |
return await self._post( |
| 885 |
path_template("/v1/environments/{environment_id}/archive?beta=true", environment_id=environment_id), |
| 886 |
options=make_request_options( |
| 887 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 888 |
), |
| 889 |
cast_to=BetaEnvironment, |
| 890 |
) |
| 891 |
|
| 892 |
|
| 893 |
class EnvironmentsWithRawResponse: |
| 894 |
def __init__(self, environments: Environments) -> None: |
| 895 |
self._environments = environments |
| 896 |
|
| 897 |
self.create = to_raw_response_wrapper( |
| 898 |
environments.create, |
| 899 |
) |
| 900 |
self.retrieve = to_raw_response_wrapper( |
| 901 |
environments.retrieve, |
| 902 |
) |
| 903 |
self.update = to_raw_response_wrapper( |
| 904 |
environments.update, |
| 905 |
) |
| 906 |
self.list = to_raw_response_wrapper( |
| 907 |
environments.list, |
| 908 |
) |
| 909 |
self.delete = to_raw_response_wrapper( |
| 910 |
environments.delete, |
| 911 |
) |
| 912 |
self.archive = to_raw_response_wrapper( |
| 913 |
environments.archive, |
| 914 |
) |
| 915 |
|
| 916 |
@cached_property |
| 917 |
def work(self) -> WorkWithRawResponse: |
| 918 |
return WorkWithRawResponse(self._environments.work) |
| 919 |
|
| 920 |
|
| 921 |
class AsyncEnvironmentsWithRawResponse: |
| 922 |
def __init__(self, environments: AsyncEnvironments) -> None: |
| 923 |
self._environments = environments |
| 924 |
|
| 925 |
self.create = async_to_raw_response_wrapper( |
| 926 |
environments.create, |
| 927 |
) |
| 928 |
self.retrieve = async_to_raw_response_wrapper( |
| 929 |
environments.retrieve, |
| 930 |
) |
| 931 |
self.update = async_to_raw_response_wrapper( |
| 932 |
environments.update, |
| 933 |
) |
| 934 |
self.list = async_to_raw_response_wrapper( |
| 935 |
environments.list, |
| 936 |
) |
| 937 |
self.delete = async_to_raw_response_wrapper( |
| 938 |
environments.delete, |
| 939 |
) |
| 940 |
self.archive = async_to_raw_response_wrapper( |
| 941 |
environments.archive, |
| 942 |
) |
| 943 |
|
| 944 |
@cached_property |
| 945 |
def work(self) -> AsyncWorkWithRawResponse: |
| 946 |
return AsyncWorkWithRawResponse(self._environments.work) |
| 947 |
|
| 948 |
|
| 949 |
class EnvironmentsWithStreamingResponse: |
| 950 |
def __init__(self, environments: Environments) -> None: |
| 951 |
self._environments = environments |
| 952 |
|
| 953 |
self.create = to_streamed_response_wrapper( |
| 954 |
environments.create, |
| 955 |
) |
| 956 |
self.retrieve = to_streamed_response_wrapper( |
| 957 |
environments.retrieve, |
| 958 |
) |
| 959 |
self.update = to_streamed_response_wrapper( |
| 960 |
environments.update, |
| 961 |
) |
| 962 |
self.list = to_streamed_response_wrapper( |
| 963 |
environments.list, |
| 964 |
) |
| 965 |
self.delete = to_streamed_response_wrapper( |
| 966 |
environments.delete, |
| 967 |
) |
| 968 |
self.archive = to_streamed_response_wrapper( |
| 969 |
environments.archive, |
| 970 |
) |
| 971 |
|
| 972 |
@cached_property |
| 973 |
def work(self) -> WorkWithStreamingResponse: |
| 974 |
return WorkWithStreamingResponse(self._environments.work) |
| 975 |
|
| 976 |
|
| 977 |
class AsyncEnvironmentsWithStreamingResponse: |
| 978 |
def __init__(self, environments: AsyncEnvironments) -> None: |
| 979 |
self._environments = environments |
| 980 |
|
| 981 |
self.create = async_to_streamed_response_wrapper( |
| 982 |
environments.create, |
| 983 |
) |
| 984 |
self.retrieve = async_to_streamed_response_wrapper( |
| 985 |
environments.retrieve, |
| 986 |
) |
| 987 |
self.update = async_to_streamed_response_wrapper( |
| 988 |
environments.update, |
| 989 |
) |
| 990 |
self.list = async_to_streamed_response_wrapper( |
| 991 |
environments.list, |
| 992 |
) |
| 993 |
self.delete = async_to_streamed_response_wrapper( |
| 994 |
environments.delete, |
| 995 |
) |
| 996 |
self.archive = async_to_streamed_response_wrapper( |
| 997 |
environments.archive, |
| 998 |
) |
| 999 |
|
| 1000 |
@cached_property |
| 1001 |
def work(self) -> AsyncWorkWithStreamingResponse: |
| 1002 |
return AsyncWorkWithStreamingResponse(self._environments.work) |