Debian Codegraph @

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

raw
1 from __future__ import annotations
2
3 from typing import Optional
4 from typing_extensions import Literal
5
6 import httpx2
7
8 from ...._types import Body, Omit, Query, Headers, NotGiven, 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.beta_api_key import BetaAPIKey
21
22 __all__ = ["APIKeys", "AsyncAPIKeys"]
23
24
25 class APIKeys(SyncAPIResource):
26 @cached_property
27 def with_raw_response(self) -> APIKeysWithRawResponse:
28 """
29 This property can be used as a prefix for any HTTP method call to return
30 the raw response object instead of the parsed content.
31
32 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
33 """
34 return APIKeysWithRawResponse(self)
35
36 @cached_property
37 def with_streaming_response(self) -> APIKeysWithStreamingResponse:
38 """
39 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
40
41 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
42 """
43 return APIKeysWithStreamingResponse(self)
44
45 def retrieve(
46 self,
47 api_key_id: str,
48 *,
49 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
50 # The extra values given here take precedence over values defined on the client or passed to this method.
51 extra_headers: Headers | None = None,
52 extra_query: Query | None = None,
53 extra_body: Body | None = None,
54 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
55 ) -> BetaAPIKey:
56 """
57 Get API Key
58
59 Args:
60 api_key_id: ID of the API key.
61
62 extra_headers: Send extra headers
63
64 extra_query: Add additional query parameters to the request
65
66 extra_body: Add additional JSON properties to the request
67
68 timeout: Override the client-level default timeout for this request, in seconds
69 """
70 if not api_key_id:
71 raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
72 return self._get(
73 path_template("/v1/organizations/api_keys/{api_key_id}?beta=true", api_key_id=api_key_id),
74 options=make_request_options(
75 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
76 ),
77 cast_to=BetaAPIKey,
78 )
79
80 def update(
81 self,
82 api_key_id: str,
83 *,
84 name: Optional[str] | Omit = omit,
85 status: Optional[Literal["active", "archived", "inactive"]] | Omit = omit,
86 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
87 # The extra values given here take precedence over values defined on the client or passed to this method.
88 extra_headers: Headers | None = None,
89 extra_query: Query | None = None,
90 extra_body: Body | None = None,
91 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
92 ) -> BetaAPIKey:
93 """
94 Update API Key
95
96 Args:
97 api_key_id: ID of the API key.
98
99 name: Name of the API key.
100
101 status: Status of the API key.
102
103 extra_headers: Send extra headers
104
105 extra_query: Add additional query parameters to the request
106
107 extra_body: Add additional JSON properties to the request
108
109 timeout: Override the client-level default timeout for this request, in seconds
110 """
111 if not api_key_id:
112 raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
113 return self._post(
114 path_template("/v1/organizations/api_keys/{api_key_id}?beta=true", api_key_id=api_key_id),
115 body={
116 "name": name,
117 "status": status,
118 },
119 options=make_request_options(
120 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
121 ),
122 cast_to=BetaAPIKey,
123 )
124
125 def list(
126 self,
127 *,
128 after_id: str | Omit = omit,
129 before_id: str | Omit = omit,
130 created_by_user_id: Optional[str] | Omit = omit,
131 limit: int | Omit = omit,
132 status: Optional[Literal["active", "archived", "expired", "inactive"]] | Omit = omit,
133 workspace_id: Optional[str] | Omit = omit,
134 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
135 # The extra values given here take precedence over values defined on the client or passed to this method.
136 extra_headers: Headers | None = None,
137 extra_query: Query | None = None,
138 extra_body: Body | None = None,
139 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
140 ) -> SyncPage[BetaAPIKey]:
141 """
142 List API Keys
143
144 Args:
145 after_id: ID of the object to use as a cursor for pagination. When provided, returns the
146 page of results immediately after this object.
147
148 before_id: ID of the object to use as a cursor for pagination. When provided, returns the
149 page of results immediately before this object.
150
151 created_by_user_id: Filter by the ID of the User who created the object.
152
153 limit: Number of items to return per page.
154
155 Defaults to `20`. Ranges from `1` to `1000`.
156
157 status: Filter by API key status.
158
159 workspace_id: Filter by Workspace ID.
160
161 extra_headers: Send extra headers
162
163 extra_query: Add additional query parameters to the request
164
165 extra_body: Add additional JSON properties to the request
166
167 timeout: Override the client-level default timeout for this request, in seconds
168 """
169 return self._get_api_list(
170 "/v1/organizations/api_keys?beta=true",
171 page=SyncPage[BetaAPIKey],
172 options=make_request_options(
173 extra_headers=extra_headers,
174 extra_query=extra_query,
175 extra_body=extra_body,
176 timeout=timeout,
177 query={
178 "after_id": after_id,
179 "before_id": before_id,
180 "created_by_user_id": created_by_user_id,
181 "limit": limit,
182 "status": status,
183 "workspace_id": workspace_id,
184 },
185 ),
186 model=BetaAPIKey,
187 )
188
189
190 class AsyncAPIKeys(AsyncAPIResource):
191 @cached_property
192 def with_raw_response(self) -> AsyncAPIKeysWithRawResponse:
193 """
194 This property can be used as a prefix for any HTTP method call to return
195 the raw response object instead of the parsed content.
196
197 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
198 """
199 return AsyncAPIKeysWithRawResponse(self)
200
201 @cached_property
202 def with_streaming_response(self) -> AsyncAPIKeysWithStreamingResponse:
203 """
204 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
205
206 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
207 """
208 return AsyncAPIKeysWithStreamingResponse(self)
209
210 async def retrieve(
211 self,
212 api_key_id: str,
213 *,
214 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
215 # The extra values given here take precedence over values defined on the client or passed to this method.
216 extra_headers: Headers | None = None,
217 extra_query: Query | None = None,
218 extra_body: Body | None = None,
219 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
220 ) -> BetaAPIKey:
221 """
222 Get API Key
223
224 Args:
225 api_key_id: ID of the API key.
226
227 extra_headers: Send extra headers
228
229 extra_query: Add additional query parameters to the request
230
231 extra_body: Add additional JSON properties to the request
232
233 timeout: Override the client-level default timeout for this request, in seconds
234 """
235 if not api_key_id:
236 raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
237 return await self._get(
238 path_template("/v1/organizations/api_keys/{api_key_id}?beta=true", api_key_id=api_key_id),
239 options=make_request_options(
240 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
241 ),
242 cast_to=BetaAPIKey,
243 )
244
245 async def update(
246 self,
247 api_key_id: str,
248 *,
249 name: Optional[str] | Omit = omit,
250 status: Optional[Literal["active", "archived", "inactive"]] | Omit = omit,
251 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
252 # The extra values given here take precedence over values defined on the client or passed to this method.
253 extra_headers: Headers | None = None,
254 extra_query: Query | None = None,
255 extra_body: Body | None = None,
256 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
257 ) -> BetaAPIKey:
258 """
259 Update API Key
260
261 Args:
262 api_key_id: ID of the API key.
263
264 name: Name of the API key.
265
266 status: Status of the API key.
267
268 extra_headers: Send extra headers
269
270 extra_query: Add additional query parameters to the request
271
272 extra_body: Add additional JSON properties to the request
273
274 timeout: Override the client-level default timeout for this request, in seconds
275 """
276 if not api_key_id:
277 raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
278 return await self._post(
279 path_template("/v1/organizations/api_keys/{api_key_id}?beta=true", api_key_id=api_key_id),
280 body={
281 "name": name,
282 "status": status,
283 },
284 options=make_request_options(
285 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
286 ),
287 cast_to=BetaAPIKey,
288 )
289
290 def list(
291 self,
292 *,
293 after_id: str | Omit = omit,
294 before_id: str | Omit = omit,
295 created_by_user_id: Optional[str] | Omit = omit,
296 limit: int | Omit = omit,
297 status: Optional[Literal["active", "archived", "expired", "inactive"]] | Omit = omit,
298 workspace_id: Optional[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[BetaAPIKey, AsyncPage[BetaAPIKey]]:
306 """
307 List API Keys
308
309 Args:
310 after_id: ID of the object to use as a cursor for pagination. When provided, returns the
311 page of results immediately after this object.
312
313 before_id: ID of the object to use as a cursor for pagination. When provided, returns the
314 page of results immediately before this object.
315
316 created_by_user_id: Filter by the ID of the User who created the object.
317
318 limit: Number of items to return per page.
319
320 Defaults to `20`. Ranges from `1` to `1000`.
321
322 status: Filter by API key status.
323
324 workspace_id: Filter by Workspace ID.
325
326 extra_headers: Send extra headers
327
328 extra_query: Add additional query parameters to the request
329
330 extra_body: Add additional JSON properties to the request
331
332 timeout: Override the client-level default timeout for this request, in seconds
333 """
334 return self._get_api_list(
335 "/v1/organizations/api_keys?beta=true",
336 page=AsyncPage[BetaAPIKey],
337 options=make_request_options(
338 extra_headers=extra_headers,
339 extra_query=extra_query,
340 extra_body=extra_body,
341 timeout=timeout,
342 query={
343 "after_id": after_id,
344 "before_id": before_id,
345 "created_by_user_id": created_by_user_id,
346 "limit": limit,
347 "status": status,
348 "workspace_id": workspace_id,
349 },
350 ),
351 model=BetaAPIKey,
352 )
353
354
355 class APIKeysWithRawResponse:
356 def __init__(self, api_keys: APIKeys) -> None:
357 self._api_keys = api_keys
358
359 self.retrieve = to_raw_response_wrapper(
360 api_keys.retrieve,
361 )
362 self.update = to_raw_response_wrapper(
363 api_keys.update,
364 )
365 self.list = to_raw_response_wrapper(
366 api_keys.list,
367 )
368
369
370 class AsyncAPIKeysWithRawResponse:
371 def __init__(self, api_keys: AsyncAPIKeys) -> None:
372 self._api_keys = api_keys
373
374 self.retrieve = async_to_raw_response_wrapper(
375 api_keys.retrieve,
376 )
377 self.update = async_to_raw_response_wrapper(
378 api_keys.update,
379 )
380 self.list = async_to_raw_response_wrapper(
381 api_keys.list,
382 )
383
384
385 class APIKeysWithStreamingResponse:
386 def __init__(self, api_keys: APIKeys) -> None:
387 self._api_keys = api_keys
388
389 self.retrieve = to_streamed_response_wrapper(
390 api_keys.retrieve,
391 )
392 self.update = to_streamed_response_wrapper(
393 api_keys.update,
394 )
395 self.list = to_streamed_response_wrapper(
396 api_keys.list,
397 )
398
399
400 class AsyncAPIKeysWithStreamingResponse:
401 def __init__(self, api_keys: AsyncAPIKeys) -> None:
402 self._api_keys = api_keys
403
404 self.retrieve = async_to_streamed_response_wrapper(
405 api_keys.retrieve,
406 )
407 self.update = async_to_streamed_response_wrapper(
408 api_keys.update,
409 )
410 self.list = async_to_streamed_response_wrapper(
411 api_keys.list,
412 )