Debian Codegraph @

src/anthropic/resources/beta/organization/workspaces/service_accounts.py

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