Debian Codegraph @

src/anthropic/resources/beta/user_profiles.py

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