| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import List, Union |
| 4 |
from datetime import datetime |
| 5 |
from itertools import chain |
| 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 ...types.beta import BetaManagedAgentsTriggerType |
| 21 |
from ..._base_client import AsyncPaginator, make_request_options |
| 22 |
from ...types.anthropic_beta_param import AnthropicBetaParam |
| 23 |
from ...types.beta.beta_managed_agents_trigger_type import BetaManagedAgentsTriggerType |
| 24 |
from ...types.beta.beta_managed_agents_deployment_run import BetaManagedAgentsDeploymentRun |
| 25 |
|
| 26 |
__all__ = ["DeploymentRuns", "AsyncDeploymentRuns"] |
| 27 |
|
| 28 |
|
| 29 |
class DeploymentRuns(SyncAPIResource): |
| 30 |
@cached_property |
| 31 |
def with_raw_response(self) -> DeploymentRunsWithRawResponse: |
| 32 |
""" |
| 33 |
This property can be used as a prefix for any HTTP method call to return |
| 34 |
the raw response object instead of the parsed content. |
| 35 |
|
| 36 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 37 |
""" |
| 38 |
return DeploymentRunsWithRawResponse(self) |
| 39 |
|
| 40 |
@cached_property |
| 41 |
def with_streaming_response(self) -> DeploymentRunsWithStreamingResponse: |
| 42 |
""" |
| 43 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 44 |
|
| 45 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 46 |
""" |
| 47 |
return DeploymentRunsWithStreamingResponse(self) |
| 48 |
|
| 49 |
def retrieve( |
| 50 |
self, |
| 51 |
deployment_run_id: str, |
| 52 |
*, |
| 53 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 54 |
workspace_id: str | Omit = omit, |
| 55 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 56 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 57 |
extra_headers: Headers | None = None, |
| 58 |
extra_query: Query | None = None, |
| 59 |
extra_body: Body | None = None, |
| 60 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 61 |
) -> BetaManagedAgentsDeploymentRun: |
| 62 |
""" |
| 63 |
Get Deployment Run |
| 64 |
|
| 65 |
Args: |
| 66 |
deployment_run_id: Unique identifier of the deployment run. |
| 67 |
|
| 68 |
betas: Optional header to specify the beta version(s) you want to use. |
| 69 |
|
| 70 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 71 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 72 |
|
| 73 |
Only needed for credentials that can act on more than one Workspace. A |
| 74 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 75 |
match that Workspace. |
| 76 |
|
| 77 |
extra_headers: Send extra headers |
| 78 |
|
| 79 |
extra_query: Add additional query parameters to the request |
| 80 |
|
| 81 |
extra_body: Add additional JSON properties to the request |
| 82 |
|
| 83 |
timeout: Override the client-level default timeout for this request, in seconds |
| 84 |
""" |
| 85 |
if not deployment_run_id: |
| 86 |
raise ValueError(f"Expected a non-empty value for `deployment_run_id` but received {deployment_run_id!r}") |
| 87 |
extra_headers = { |
| 88 |
**strip_not_given( |
| 89 |
{ |
| 90 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 91 |
if is_given(betas) |
| 92 |
else not_given, |
| 93 |
"anthropic-workspace-id": workspace_id, |
| 94 |
} |
| 95 |
), |
| 96 |
**(extra_headers or {}), |
| 97 |
} |
| 98 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 99 |
return self._get( |
| 100 |
path_template("/v1/deployment_runs/{deployment_run_id}?beta=true", deployment_run_id=deployment_run_id), |
| 101 |
options=make_request_options( |
| 102 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 103 |
), |
| 104 |
cast_to=BetaManagedAgentsDeploymentRun, |
| 105 |
) |
| 106 |
|
| 107 |
def list( |
| 108 |
self, |
| 109 |
*, |
| 110 |
created_at_gt: Union[str, datetime] | Omit = omit, |
| 111 |
created_at_gte: Union[str, datetime] | Omit = omit, |
| 112 |
created_at_lt: Union[str, datetime] | Omit = omit, |
| 113 |
created_at_lte: Union[str, datetime] | Omit = omit, |
| 114 |
deployment_id: str | Omit = omit, |
| 115 |
has_error: bool | Omit = omit, |
| 116 |
limit: int | Omit = omit, |
| 117 |
page: str | Omit = omit, |
| 118 |
trigger_type: BetaManagedAgentsTriggerType | Omit = omit, |
| 119 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 120 |
workspace_id: str | Omit = omit, |
| 121 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 122 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 123 |
extra_headers: Headers | None = None, |
| 124 |
extra_query: Query | None = None, |
| 125 |
extra_body: Body | None = None, |
| 126 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 127 |
) -> SyncPageCursor[BetaManagedAgentsDeploymentRun]: |
| 128 |
""" |
| 129 |
List Deployment Runs |
| 130 |
|
| 131 |
Args: |
| 132 |
created_at_gt: Return runs created strictly after this time (exclusive). |
| 133 |
|
| 134 |
created_at_gte: Return runs created at or after this time (inclusive). |
| 135 |
|
| 136 |
created_at_lt: Return runs created strictly before this time (exclusive). |
| 137 |
|
| 138 |
created_at_lte: Return runs created at or before this time (inclusive). |
| 139 |
|
| 140 |
deployment_id: Filter to a specific deployment. Omit to list across all deployments in the |
| 141 |
workspace. Filtering by a non-existent `deployment_id` returns 200 with empty |
| 142 |
data. |
| 143 |
|
| 144 |
has_error: Filter: true for runs with non-null `error`, false for runs with non-null |
| 145 |
`session_id`. Omit for all. |
| 146 |
|
| 147 |
limit: Maximum results per page. Default 20, maximum 1000. |
| 148 |
|
| 149 |
page: Opaque pagination cursor. Pass `next_page` from the previous response. Invalid |
| 150 |
or expired cursors return 400. |
| 151 |
|
| 152 |
trigger_type: Filter runs by what triggered them. Omit to return all runs. |
| 153 |
|
| 154 |
betas: Optional header to specify the beta version(s) you want to use. |
| 155 |
|
| 156 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 157 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 158 |
|
| 159 |
Only needed for credentials that can act on more than one Workspace. A |
| 160 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 161 |
match that Workspace. |
| 162 |
|
| 163 |
extra_headers: Send extra headers |
| 164 |
|
| 165 |
extra_query: Add additional query parameters to the request |
| 166 |
|
| 167 |
extra_body: Add additional JSON properties to the request |
| 168 |
|
| 169 |
timeout: Override the client-level default timeout for this request, in seconds |
| 170 |
""" |
| 171 |
extra_headers = { |
| 172 |
**strip_not_given( |
| 173 |
{ |
| 174 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 175 |
if is_given(betas) |
| 176 |
else not_given, |
| 177 |
"anthropic-workspace-id": workspace_id, |
| 178 |
} |
| 179 |
), |
| 180 |
**(extra_headers or {}), |
| 181 |
} |
| 182 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 183 |
return self._get_api_list( |
| 184 |
"/v1/deployment_runs?beta=true", |
| 185 |
page=SyncPageCursor[BetaManagedAgentsDeploymentRun], |
| 186 |
options=make_request_options( |
| 187 |
extra_headers=extra_headers, |
| 188 |
extra_query=extra_query, |
| 189 |
extra_body=extra_body, |
| 190 |
timeout=timeout, |
| 191 |
query={ |
| 192 |
"created_at[gt]": created_at_gt, |
| 193 |
"created_at[gte]": created_at_gte, |
| 194 |
"created_at[lt]": created_at_lt, |
| 195 |
"created_at[lte]": created_at_lte, |
| 196 |
"deployment_id": deployment_id, |
| 197 |
"has_error": has_error, |
| 198 |
"limit": limit, |
| 199 |
"page": page, |
| 200 |
"trigger_type": trigger_type, |
| 201 |
}, |
| 202 |
), |
| 203 |
model=BetaManagedAgentsDeploymentRun, |
| 204 |
) |
| 205 |
|
| 206 |
|
| 207 |
class AsyncDeploymentRuns(AsyncAPIResource): |
| 208 |
@cached_property |
| 209 |
def with_raw_response(self) -> AsyncDeploymentRunsWithRawResponse: |
| 210 |
""" |
| 211 |
This property can be used as a prefix for any HTTP method call to return |
| 212 |
the raw response object instead of the parsed content. |
| 213 |
|
| 214 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers |
| 215 |
""" |
| 216 |
return AsyncDeploymentRunsWithRawResponse(self) |
| 217 |
|
| 218 |
@cached_property |
| 219 |
def with_streaming_response(self) -> AsyncDeploymentRunsWithStreamingResponse: |
| 220 |
""" |
| 221 |
An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 222 |
|
| 223 |
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response |
| 224 |
""" |
| 225 |
return AsyncDeploymentRunsWithStreamingResponse(self) |
| 226 |
|
| 227 |
async def retrieve( |
| 228 |
self, |
| 229 |
deployment_run_id: str, |
| 230 |
*, |
| 231 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 232 |
workspace_id: str | Omit = omit, |
| 233 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 234 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 235 |
extra_headers: Headers | None = None, |
| 236 |
extra_query: Query | None = None, |
| 237 |
extra_body: Body | None = None, |
| 238 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 239 |
) -> BetaManagedAgentsDeploymentRun: |
| 240 |
""" |
| 241 |
Get Deployment Run |
| 242 |
|
| 243 |
Args: |
| 244 |
deployment_run_id: Unique identifier of the deployment run. |
| 245 |
|
| 246 |
betas: Optional header to specify the beta version(s) you want to use. |
| 247 |
|
| 248 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 249 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 250 |
|
| 251 |
Only needed for credentials that can act on more than one Workspace. A |
| 252 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 253 |
match that Workspace. |
| 254 |
|
| 255 |
extra_headers: Send extra headers |
| 256 |
|
| 257 |
extra_query: Add additional query parameters to the request |
| 258 |
|
| 259 |
extra_body: Add additional JSON properties to the request |
| 260 |
|
| 261 |
timeout: Override the client-level default timeout for this request, in seconds |
| 262 |
""" |
| 263 |
if not deployment_run_id: |
| 264 |
raise ValueError(f"Expected a non-empty value for `deployment_run_id` but received {deployment_run_id!r}") |
| 265 |
extra_headers = { |
| 266 |
**strip_not_given( |
| 267 |
{ |
| 268 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 269 |
if is_given(betas) |
| 270 |
else not_given, |
| 271 |
"anthropic-workspace-id": workspace_id, |
| 272 |
} |
| 273 |
), |
| 274 |
**(extra_headers or {}), |
| 275 |
} |
| 276 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 277 |
return await self._get( |
| 278 |
path_template("/v1/deployment_runs/{deployment_run_id}?beta=true", deployment_run_id=deployment_run_id), |
| 279 |
options=make_request_options( |
| 280 |
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 281 |
), |
| 282 |
cast_to=BetaManagedAgentsDeploymentRun, |
| 283 |
) |
| 284 |
|
| 285 |
def list( |
| 286 |
self, |
| 287 |
*, |
| 288 |
created_at_gt: Union[str, datetime] | Omit = omit, |
| 289 |
created_at_gte: Union[str, datetime] | Omit = omit, |
| 290 |
created_at_lt: Union[str, datetime] | Omit = omit, |
| 291 |
created_at_lte: Union[str, datetime] | Omit = omit, |
| 292 |
deployment_id: str | Omit = omit, |
| 293 |
has_error: bool | Omit = omit, |
| 294 |
limit: int | Omit = omit, |
| 295 |
page: str | Omit = omit, |
| 296 |
trigger_type: BetaManagedAgentsTriggerType | Omit = omit, |
| 297 |
betas: List[AnthropicBetaParam] | Omit = omit, |
| 298 |
workspace_id: str | Omit = omit, |
| 299 |
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 300 |
# The extra values given here take precedence over values defined on the client or passed to this method. |
| 301 |
extra_headers: Headers | None = None, |
| 302 |
extra_query: Query | None = None, |
| 303 |
extra_body: Body | None = None, |
| 304 |
timeout: float | httpx2.Timeout | None | NotGiven = not_given, |
| 305 |
) -> AsyncPaginator[BetaManagedAgentsDeploymentRun, AsyncPageCursor[BetaManagedAgentsDeploymentRun]]: |
| 306 |
""" |
| 307 |
List Deployment Runs |
| 308 |
|
| 309 |
Args: |
| 310 |
created_at_gt: Return runs created strictly after this time (exclusive). |
| 311 |
|
| 312 |
created_at_gte: Return runs created at or after this time (inclusive). |
| 313 |
|
| 314 |
created_at_lt: Return runs created strictly before this time (exclusive). |
| 315 |
|
| 316 |
created_at_lte: Return runs created at or before this time (inclusive). |
| 317 |
|
| 318 |
deployment_id: Filter to a specific deployment. Omit to list across all deployments in the |
| 319 |
workspace. Filtering by a non-existent `deployment_id` returns 200 with empty |
| 320 |
data. |
| 321 |
|
| 322 |
has_error: Filter: true for runs with non-null `error`, false for runs with non-null |
| 323 |
`session_id`. Omit for all. |
| 324 |
|
| 325 |
limit: Maximum results per page. Default 20, maximum 1000. |
| 326 |
|
| 327 |
page: Opaque pagination cursor. Pass `next_page` from the previous response. Invalid |
| 328 |
or expired cursors return 400. |
| 329 |
|
| 330 |
trigger_type: Filter runs by what triggered them. Omit to return all runs. |
| 331 |
|
| 332 |
betas: Optional header to specify the beta version(s) you want to use. |
| 333 |
|
| 334 |
workspace_id: Optional header to select the Workspace for this request. The value is a |
| 335 |
Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`). |
| 336 |
|
| 337 |
Only needed for credentials that can act on more than one Workspace. A |
| 338 |
credential that belongs to a specific Workspace may omit it; if sent, it must |
| 339 |
match that Workspace. |
| 340 |
|
| 341 |
extra_headers: Send extra headers |
| 342 |
|
| 343 |
extra_query: Add additional query parameters to the request |
| 344 |
|
| 345 |
extra_body: Add additional JSON properties to the request |
| 346 |
|
| 347 |
timeout: Override the client-level default timeout for this request, in seconds |
| 348 |
""" |
| 349 |
extra_headers = { |
| 350 |
**strip_not_given( |
| 351 |
{ |
| 352 |
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["managed-agents-2026-04-01"])) |
| 353 |
if is_given(betas) |
| 354 |
else not_given, |
| 355 |
"anthropic-workspace-id": workspace_id, |
| 356 |
} |
| 357 |
), |
| 358 |
**(extra_headers or {}), |
| 359 |
} |
| 360 |
extra_headers = {"anthropic-beta": "managed-agents-2026-04-01", **(extra_headers or {})} |
| 361 |
return self._get_api_list( |
| 362 |
"/v1/deployment_runs?beta=true", |
| 363 |
page=AsyncPageCursor[BetaManagedAgentsDeploymentRun], |
| 364 |
options=make_request_options( |
| 365 |
extra_headers=extra_headers, |
| 366 |
extra_query=extra_query, |
| 367 |
extra_body=extra_body, |
| 368 |
timeout=timeout, |
| 369 |
query={ |
| 370 |
"created_at[gt]": created_at_gt, |
| 371 |
"created_at[gte]": created_at_gte, |
| 372 |
"created_at[lt]": created_at_lt, |
| 373 |
"created_at[lte]": created_at_lte, |
| 374 |
"deployment_id": deployment_id, |
| 375 |
"has_error": has_error, |
| 376 |
"limit": limit, |
| 377 |
"page": page, |
| 378 |
"trigger_type": trigger_type, |
| 379 |
}, |
| 380 |
), |
| 381 |
model=BetaManagedAgentsDeploymentRun, |
| 382 |
) |
| 383 |
|
| 384 |
|
| 385 |
class DeploymentRunsWithRawResponse: |
| 386 |
def __init__(self, deployment_runs: DeploymentRuns) -> None: |
| 387 |
self._deployment_runs = deployment_runs |
| 388 |
|
| 389 |
self.retrieve = to_raw_response_wrapper( |
| 390 |
deployment_runs.retrieve, |
| 391 |
) |
| 392 |
self.list = to_raw_response_wrapper( |
| 393 |
deployment_runs.list, |
| 394 |
) |
| 395 |
|
| 396 |
|
| 397 |
class AsyncDeploymentRunsWithRawResponse: |
| 398 |
def __init__(self, deployment_runs: AsyncDeploymentRuns) -> None: |
| 399 |
self._deployment_runs = deployment_runs |
| 400 |
|
| 401 |
self.retrieve = async_to_raw_response_wrapper( |
| 402 |
deployment_runs.retrieve, |
| 403 |
) |
| 404 |
self.list = async_to_raw_response_wrapper( |
| 405 |
deployment_runs.list, |
| 406 |
) |
| 407 |
|
| 408 |
|
| 409 |
class DeploymentRunsWithStreamingResponse: |
| 410 |
def __init__(self, deployment_runs: DeploymentRuns) -> None: |
| 411 |
self._deployment_runs = deployment_runs |
| 412 |
|
| 413 |
self.retrieve = to_streamed_response_wrapper( |
| 414 |
deployment_runs.retrieve, |
| 415 |
) |
| 416 |
self.list = to_streamed_response_wrapper( |
| 417 |
deployment_runs.list, |
| 418 |
) |
| 419 |
|
| 420 |
|
| 421 |
class AsyncDeploymentRunsWithStreamingResponse: |
| 422 |
def __init__(self, deployment_runs: AsyncDeploymentRuns) -> None: |
| 423 |
self._deployment_runs = deployment_runs |
| 424 |
|
| 425 |
self.retrieve = async_to_streamed_response_wrapper( |
| 426 |
deployment_runs.retrieve, |
| 427 |
) |
| 428 |
self.list = async_to_streamed_response_wrapper( |
| 429 |
deployment_runs.list, |
| 430 |
) |