Debian Codegraph @

src/anthropic/resources/beta/organization/invites.py

raw
1 from __future__ import annotations
2
3 from typing import List
4 from typing_extensions import Literal
5
6 import httpx2
7
8 from ...._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
9 from ...._utils import path_template
10 from ...._compat import cached_property
11 from ...._resource import SyncAPIResource, AsyncAPIResource
12 from ...._response import (
13 to_raw_response_wrapper,
14 to_streamed_response_wrapper,
15 async_to_raw_response_wrapper,
16 async_to_streamed_response_wrapper,
17 )
18 from ....pagination import SyncPage, AsyncPage
19 from ...._base_client import AsyncPaginator, make_request_options
20 from ....types.beta.organization.invite_delete_response import InviteDeleteResponse
21 from ....types.beta.organization.beta_organization_invite import BetaOrganizationInvite
22
23 __all__ = ["Invites", "AsyncInvites"]
24
25
26 class Invites(SyncAPIResource):
27 @cached_property
28 def with_raw_response(self) -> InvitesWithRawResponse:
29 """
30 This property can be used as a prefix for any HTTP method call to return
31 the raw response object instead of the parsed content.
32
33 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
34 """
35 return InvitesWithRawResponse(self)
36
37 @cached_property
38 def with_streaming_response(self) -> InvitesWithStreamingResponse:
39 """
40 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
41
42 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
43 """
44 return InvitesWithStreamingResponse(self)
45
46 def create(
47 self,
48 *,
49 email: str,
50 role: Literal["billing", "claude_code_user", "developer", "managed", "user"],
51 rbac_group_ids: SequenceNotStr[str] | Omit = omit,
52 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
53 # The extra values given here take precedence over values defined on the client or passed to this method.
54 extra_headers: Headers | None = None,
55 extra_query: Query | None = None,
56 extra_body: Body | None = None,
57 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
58 ) -> BetaOrganizationInvite:
59 """
60 Invite a user to join the organization by email.
61
62 On plans that draw members from a finite pool of purchased seats, the invite
63 automatically consumes a seat from the lowest tier with availability; there is
64 no seat-tier parameter. When no seat is free the request fails with a 400 error
65 rather than purchasing a seat.
66
67 Args:
68 email: Email of the User.
69
70 role: Role for the invited User.
71
72 The accepted values depend on the organization type. Console and API
73 organizations accept `user`, `developer`, `billing`, and `claude_code_user`;
74 `admin` cannot be assigned through the API. Claude Enterprise organizations
75 accept `user` and `managed`.
76
77 rbac_group_ids: RBAC group IDs to assign to the User when the Invite is accepted. A non-empty
78 array is accepted only for a Claude Enterprise organization with RBAC groups,
79 and requires the key to carry the `write:rbac_groups` scope.
80
81 extra_headers: Send extra headers
82
83 extra_query: Add additional query parameters to the request
84
85 extra_body: Add additional JSON properties to the request
86
87 timeout: Override the client-level default timeout for this request, in seconds
88 """
89 return self._post(
90 "/v1/organizations/invites?beta=true",
91 body={
92 "email": email,
93 "role": role,
94 "rbac_group_ids": rbac_group_ids,
95 },
96 options=make_request_options(
97 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
98 ),
99 cast_to=BetaOrganizationInvite,
100 )
101
102 def retrieve(
103 self,
104 invite_id: str,
105 *,
106 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
107 # The extra values given here take precedence over values defined on the client or passed to this method.
108 extra_headers: Headers | None = None,
109 extra_query: Query | None = None,
110 extra_body: Body | None = None,
111 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
112 ) -> BetaOrganizationInvite:
113 """
114 Retrieve an invite by ID.
115
116 Args:
117 invite_id: ID of the Invite.
118
119 extra_headers: Send extra headers
120
121 extra_query: Add additional query parameters to the request
122
123 extra_body: Add additional JSON properties to the request
124
125 timeout: Override the client-level default timeout for this request, in seconds
126 """
127 if not invite_id:
128 raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
129 return self._get(
130 path_template("/v1/organizations/invites/{invite_id}?beta=true", invite_id=invite_id),
131 options=make_request_options(
132 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
133 ),
134 cast_to=BetaOrganizationInvite,
135 )
136
137 def list(
138 self,
139 *,
140 after_id: str | Omit = omit,
141 before_id: str | Omit = omit,
142 email: str | Omit = omit,
143 limit: int | Omit = omit,
144 roles: SequenceNotStr[str] | Omit = omit,
145 statuses: List[Literal["accepted", "expired", "pending"]] | Omit = omit,
146 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
147 # The extra values given here take precedence over values defined on the client or passed to this method.
148 extra_headers: Headers | None = None,
149 extra_query: Query | None = None,
150 extra_body: Body | None = None,
151 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
152 ) -> SyncPage[BetaOrganizationInvite]:
153 """
154 List the organization's invites.
155
156 Args:
157 after_id: ID of the object to use as a cursor for pagination. When provided, returns the
158 page of results immediately after this object.
159
160 before_id: ID of the object to use as a cursor for pagination. When provided, returns the
161 page of results immediately before this object.
162
163 email: Filter by the email address the Invite was sent to. Matches the same way as the
164 Users list's `email` filter (normalized, case-insensitive).
165
166 limit: Number of items to return per page.
167
168 Defaults to `20`. Ranges from `1` to `1000`.
169
170 roles: Filter to items whose `role` equals one of the supplied values. Repeatable;
171 values are OR'ed together.
172
173 Accepted values depend on the organization type: Console and API organizations
174 accept `user`, `developer`, `billing`, `admin`, and `claude_code_user`; Claude
175 Enterprise organizations accept `user`, `owner`, `primary_owner`,
176 `membership_admin`, and `managed`.
177
178 statuses: Filter by Invite status. Repeatable; values are OR'ed together. Omit to return
179 `pending`, `accepted`, and `expired` Invites alike.
180
181 extra_headers: Send extra headers
182
183 extra_query: Add additional query parameters to the request
184
185 extra_body: Add additional JSON properties to the request
186
187 timeout: Override the client-level default timeout for this request, in seconds
188 """
189 return self._get_api_list(
190 "/v1/organizations/invites?beta=true",
191 page=SyncPage[BetaOrganizationInvite],
192 options=make_request_options(
193 extra_headers=extra_headers,
194 extra_query=extra_query,
195 extra_body=extra_body,
196 timeout=timeout,
197 query={
198 "after_id": after_id,
199 "before_id": before_id,
200 "email": email,
201 "limit": limit,
202 "roles": roles,
203 "statuses": statuses,
204 },
205 ),
206 model=BetaOrganizationInvite,
207 )
208
209 def delete(
210 self,
211 invite_id: str,
212 *,
213 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
214 # The extra values given here take precedence over values defined on the client or passed to this method.
215 extra_headers: Headers | None = None,
216 extra_query: Query | None = None,
217 extra_body: Body | None = None,
218 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
219 ) -> InviteDeleteResponse:
220 """
221 Delete a pending invite.
222
223 Args:
224 invite_id: ID of the Invite.
225
226 extra_headers: Send extra headers
227
228 extra_query: Add additional query parameters to the request
229
230 extra_body: Add additional JSON properties to the request
231
232 timeout: Override the client-level default timeout for this request, in seconds
233 """
234 if not invite_id:
235 raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
236 return self._delete(
237 path_template("/v1/organizations/invites/{invite_id}?beta=true", invite_id=invite_id),
238 options=make_request_options(
239 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
240 ),
241 cast_to=InviteDeleteResponse,
242 )
243
244
245 class AsyncInvites(AsyncAPIResource):
246 @cached_property
247 def with_raw_response(self) -> AsyncInvitesWithRawResponse:
248 """
249 This property can be used as a prefix for any HTTP method call to return
250 the raw response object instead of the parsed content.
251
252 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
253 """
254 return AsyncInvitesWithRawResponse(self)
255
256 @cached_property
257 def with_streaming_response(self) -> AsyncInvitesWithStreamingResponse:
258 """
259 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
260
261 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
262 """
263 return AsyncInvitesWithStreamingResponse(self)
264
265 async def create(
266 self,
267 *,
268 email: str,
269 role: Literal["billing", "claude_code_user", "developer", "managed", "user"],
270 rbac_group_ids: SequenceNotStr[str] | Omit = omit,
271 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
272 # The extra values given here take precedence over values defined on the client or passed to this method.
273 extra_headers: Headers | None = None,
274 extra_query: Query | None = None,
275 extra_body: Body | None = None,
276 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
277 ) -> BetaOrganizationInvite:
278 """
279 Invite a user to join the organization by email.
280
281 On plans that draw members from a finite pool of purchased seats, the invite
282 automatically consumes a seat from the lowest tier with availability; there is
283 no seat-tier parameter. When no seat is free the request fails with a 400 error
284 rather than purchasing a seat.
285
286 Args:
287 email: Email of the User.
288
289 role: Role for the invited User.
290
291 The accepted values depend on the organization type. Console and API
292 organizations accept `user`, `developer`, `billing`, and `claude_code_user`;
293 `admin` cannot be assigned through the API. Claude Enterprise organizations
294 accept `user` and `managed`.
295
296 rbac_group_ids: RBAC group IDs to assign to the User when the Invite is accepted. A non-empty
297 array is accepted only for a Claude Enterprise organization with RBAC groups,
298 and requires the key to carry the `write:rbac_groups` scope.
299
300 extra_headers: Send extra headers
301
302 extra_query: Add additional query parameters to the request
303
304 extra_body: Add additional JSON properties to the request
305
306 timeout: Override the client-level default timeout for this request, in seconds
307 """
308 return await self._post(
309 "/v1/organizations/invites?beta=true",
310 body={
311 "email": email,
312 "role": role,
313 "rbac_group_ids": rbac_group_ids,
314 },
315 options=make_request_options(
316 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
317 ),
318 cast_to=BetaOrganizationInvite,
319 )
320
321 async def retrieve(
322 self,
323 invite_id: str,
324 *,
325 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
326 # The extra values given here take precedence over values defined on the client or passed to this method.
327 extra_headers: Headers | None = None,
328 extra_query: Query | None = None,
329 extra_body: Body | None = None,
330 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
331 ) -> BetaOrganizationInvite:
332 """
333 Retrieve an invite by ID.
334
335 Args:
336 invite_id: ID of the Invite.
337
338 extra_headers: Send extra headers
339
340 extra_query: Add additional query parameters to the request
341
342 extra_body: Add additional JSON properties to the request
343
344 timeout: Override the client-level default timeout for this request, in seconds
345 """
346 if not invite_id:
347 raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
348 return await self._get(
349 path_template("/v1/organizations/invites/{invite_id}?beta=true", invite_id=invite_id),
350 options=make_request_options(
351 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
352 ),
353 cast_to=BetaOrganizationInvite,
354 )
355
356 def list(
357 self,
358 *,
359 after_id: str | Omit = omit,
360 before_id: str | Omit = omit,
361 email: str | Omit = omit,
362 limit: int | Omit = omit,
363 roles: SequenceNotStr[str] | Omit = omit,
364 statuses: List[Literal["accepted", "expired", "pending"]] | Omit = omit,
365 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
366 # The extra values given here take precedence over values defined on the client or passed to this method.
367 extra_headers: Headers | None = None,
368 extra_query: Query | None = None,
369 extra_body: Body | None = None,
370 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
371 ) -> AsyncPaginator[BetaOrganizationInvite, AsyncPage[BetaOrganizationInvite]]:
372 """
373 List the organization's invites.
374
375 Args:
376 after_id: ID of the object to use as a cursor for pagination. When provided, returns the
377 page of results immediately after this object.
378
379 before_id: ID of the object to use as a cursor for pagination. When provided, returns the
380 page of results immediately before this object.
381
382 email: Filter by the email address the Invite was sent to. Matches the same way as the
383 Users list's `email` filter (normalized, case-insensitive).
384
385 limit: Number of items to return per page.
386
387 Defaults to `20`. Ranges from `1` to `1000`.
388
389 roles: Filter to items whose `role` equals one of the supplied values. Repeatable;
390 values are OR'ed together.
391
392 Accepted values depend on the organization type: Console and API organizations
393 accept `user`, `developer`, `billing`, `admin`, and `claude_code_user`; Claude
394 Enterprise organizations accept `user`, `owner`, `primary_owner`,
395 `membership_admin`, and `managed`.
396
397 statuses: Filter by Invite status. Repeatable; values are OR'ed together. Omit to return
398 `pending`, `accepted`, and `expired` Invites alike.
399
400 extra_headers: Send extra headers
401
402 extra_query: Add additional query parameters to the request
403
404 extra_body: Add additional JSON properties to the request
405
406 timeout: Override the client-level default timeout for this request, in seconds
407 """
408 return self._get_api_list(
409 "/v1/organizations/invites?beta=true",
410 page=AsyncPage[BetaOrganizationInvite],
411 options=make_request_options(
412 extra_headers=extra_headers,
413 extra_query=extra_query,
414 extra_body=extra_body,
415 timeout=timeout,
416 query={
417 "after_id": after_id,
418 "before_id": before_id,
419 "email": email,
420 "limit": limit,
421 "roles": roles,
422 "statuses": statuses,
423 },
424 ),
425 model=BetaOrganizationInvite,
426 )
427
428 async def delete(
429 self,
430 invite_id: str,
431 *,
432 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
433 # The extra values given here take precedence over values defined on the client or passed to this method.
434 extra_headers: Headers | None = None,
435 extra_query: Query | None = None,
436 extra_body: Body | None = None,
437 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
438 ) -> InviteDeleteResponse:
439 """
440 Delete a pending invite.
441
442 Args:
443 invite_id: ID of the Invite.
444
445 extra_headers: Send extra headers
446
447 extra_query: Add additional query parameters to the request
448
449 extra_body: Add additional JSON properties to the request
450
451 timeout: Override the client-level default timeout for this request, in seconds
452 """
453 if not invite_id:
454 raise ValueError(f"Expected a non-empty value for `invite_id` but received {invite_id!r}")
455 return await self._delete(
456 path_template("/v1/organizations/invites/{invite_id}?beta=true", invite_id=invite_id),
457 options=make_request_options(
458 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
459 ),
460 cast_to=InviteDeleteResponse,
461 )
462
463
464 class InvitesWithRawResponse:
465 def __init__(self, invites: Invites) -> None:
466 self._invites = invites
467
468 self.create = to_raw_response_wrapper(
469 invites.create,
470 )
471 self.retrieve = to_raw_response_wrapper(
472 invites.retrieve,
473 )
474 self.list = to_raw_response_wrapper(
475 invites.list,
476 )
477 self.delete = to_raw_response_wrapper(
478 invites.delete,
479 )
480
481
482 class AsyncInvitesWithRawResponse:
483 def __init__(self, invites: AsyncInvites) -> None:
484 self._invites = invites
485
486 self.create = async_to_raw_response_wrapper(
487 invites.create,
488 )
489 self.retrieve = async_to_raw_response_wrapper(
490 invites.retrieve,
491 )
492 self.list = async_to_raw_response_wrapper(
493 invites.list,
494 )
495 self.delete = async_to_raw_response_wrapper(
496 invites.delete,
497 )
498
499
500 class InvitesWithStreamingResponse:
501 def __init__(self, invites: Invites) -> None:
502 self._invites = invites
503
504 self.create = to_streamed_response_wrapper(
505 invites.create,
506 )
507 self.retrieve = to_streamed_response_wrapper(
508 invites.retrieve,
509 )
510 self.list = to_streamed_response_wrapper(
511 invites.list,
512 )
513 self.delete = to_streamed_response_wrapper(
514 invites.delete,
515 )
516
517
518 class AsyncInvitesWithStreamingResponse:
519 def __init__(self, invites: AsyncInvites) -> None:
520 self._invites = invites
521
522 self.create = async_to_streamed_response_wrapper(
523 invites.create,
524 )
525 self.retrieve = async_to_streamed_response_wrapper(
526 invites.retrieve,
527 )
528 self.list = async_to_streamed_response_wrapper(
529 invites.list,
530 )
531 self.delete = async_to_streamed_response_wrapper(
532 invites.delete,
533 )