Debian Codegraph @

src/anthropic/resources/beta/organization/workspaces/rate_limits.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 SyncPageCursor, AsyncPageCursor
19 from ....._base_client import AsyncPaginator, make_request_options
20 from .....types.beta.organization.workspaces.beta_workspace_rate_limit import BetaWorkspaceRateLimit
21
22 __all__ = ["RateLimits", "AsyncRateLimits"]
23
24
25 class RateLimits(SyncAPIResource):
26 @cached_property
27 def with_raw_response(self) -> RateLimitsWithRawResponse:
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 RateLimitsWithRawResponse(self)
35
36 @cached_property
37 def with_streaming_response(self) -> RateLimitsWithStreamingResponse:
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 RateLimitsWithStreamingResponse(self)
44
45 def list(
46 self,
47 workspace_id: str,
48 *,
49 group_type: Optional[Literal["batch", "files", "model_group", "skills", "token_count", "web_search"]]
50 | Omit = omit,
51 limit: Optional[int] | Omit = omit,
52 page: Optional[str] | Omit = omit,
53 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
54 # The extra values given here take precedence over values defined on the client or passed to this method.
55 extra_headers: Headers | None = None,
56 extra_query: Query | None = None,
57 extra_body: Body | None = None,
58 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
59 ) -> SyncPageCursor[BetaWorkspaceRateLimit]:
60 """
61 List rate-limit overrides configured for a workspace.
62
63 Returns only the groups and limiter types that have a workspace-level override.
64 Groups without overrides inherit the organization limits and are not listed; use
65 `GET /v1/organizations/rate_limits` to see those.
66
67 When `limit` is omitted, every matching entry is returned in a single page; when
68 `limit` truncates the result, follow `next_page` to fetch the remaining entries.
69
70 Args:
71 workspace_id: The ID of the workspace.
72
73 group_type: Filter by group type.
74
75 limit: Maximum number of items to return per page. Ranges from `1` to `1000`.
76
77 When omitted, every remaining entry is returned in a single page and `next_page`
78 is `null`.
79
80 page: Opaque cursor from a previous response's `next_page`.
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 return self._get_api_list(
93 path_template(
94 "/v1/organizations/workspaces/{workspace_id}/rate_limits?beta=true", workspace_id=workspace_id
95 ),
96 page=SyncPageCursor[BetaWorkspaceRateLimit],
97 options=make_request_options(
98 extra_headers=extra_headers,
99 extra_query=extra_query,
100 extra_body=extra_body,
101 timeout=timeout,
102 query={
103 "group_type": group_type,
104 "limit": limit,
105 "page": page,
106 },
107 ),
108 model=BetaWorkspaceRateLimit,
109 )
110
111
112 class AsyncRateLimits(AsyncAPIResource):
113 @cached_property
114 def with_raw_response(self) -> AsyncRateLimitsWithRawResponse:
115 """
116 This property can be used as a prefix for any HTTP method call to return
117 the raw response object instead of the parsed content.
118
119 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
120 """
121 return AsyncRateLimitsWithRawResponse(self)
122
123 @cached_property
124 def with_streaming_response(self) -> AsyncRateLimitsWithStreamingResponse:
125 """
126 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
127
128 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
129 """
130 return AsyncRateLimitsWithStreamingResponse(self)
131
132 def list(
133 self,
134 workspace_id: str,
135 *,
136 group_type: Optional[Literal["batch", "files", "model_group", "skills", "token_count", "web_search"]]
137 | Omit = omit,
138 limit: Optional[int] | Omit = omit,
139 page: Optional[str] | Omit = omit,
140 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
141 # The extra values given here take precedence over values defined on the client or passed to this method.
142 extra_headers: Headers | None = None,
143 extra_query: Query | None = None,
144 extra_body: Body | None = None,
145 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
146 ) -> AsyncPaginator[BetaWorkspaceRateLimit, AsyncPageCursor[BetaWorkspaceRateLimit]]:
147 """
148 List rate-limit overrides configured for a workspace.
149
150 Returns only the groups and limiter types that have a workspace-level override.
151 Groups without overrides inherit the organization limits and are not listed; use
152 `GET /v1/organizations/rate_limits` to see those.
153
154 When `limit` is omitted, every matching entry is returned in a single page; when
155 `limit` truncates the result, follow `next_page` to fetch the remaining entries.
156
157 Args:
158 workspace_id: The ID of the workspace.
159
160 group_type: Filter by group type.
161
162 limit: Maximum number of items to return per page. Ranges from `1` to `1000`.
163
164 When omitted, every remaining entry is returned in a single page and `next_page`
165 is `null`.
166
167 page: Opaque cursor from a previous response's `next_page`.
168
169 extra_headers: Send extra headers
170
171 extra_query: Add additional query parameters to the request
172
173 extra_body: Add additional JSON properties to the request
174
175 timeout: Override the client-level default timeout for this request, in seconds
176 """
177 if not workspace_id:
178 raise ValueError(f"Expected a non-empty value for `workspace_id` but received {workspace_id!r}")
179 return self._get_api_list(
180 path_template(
181 "/v1/organizations/workspaces/{workspace_id}/rate_limits?beta=true", workspace_id=workspace_id
182 ),
183 page=AsyncPageCursor[BetaWorkspaceRateLimit],
184 options=make_request_options(
185 extra_headers=extra_headers,
186 extra_query=extra_query,
187 extra_body=extra_body,
188 timeout=timeout,
189 query={
190 "group_type": group_type,
191 "limit": limit,
192 "page": page,
193 },
194 ),
195 model=BetaWorkspaceRateLimit,
196 )
197
198
199 class RateLimitsWithRawResponse:
200 def __init__(self, rate_limits: RateLimits) -> None:
201 self._rate_limits = rate_limits
202
203 self.list = to_raw_response_wrapper(
204 rate_limits.list,
205 )
206
207
208 class AsyncRateLimitsWithRawResponse:
209 def __init__(self, rate_limits: AsyncRateLimits) -> None:
210 self._rate_limits = rate_limits
211
212 self.list = async_to_raw_response_wrapper(
213 rate_limits.list,
214 )
215
216
217 class RateLimitsWithStreamingResponse:
218 def __init__(self, rate_limits: RateLimits) -> None:
219 self._rate_limits = rate_limits
220
221 self.list = to_streamed_response_wrapper(
222 rate_limits.list,
223 )
224
225
226 class AsyncRateLimitsWithStreamingResponse:
227 def __init__(self, rate_limits: AsyncRateLimits) -> None:
228 self._rate_limits = rate_limits
229
230 self.list = async_to_streamed_response_wrapper(
231 rate_limits.list,
232 )