Debian Codegraph @

src/anthropic/resources/beta/organization/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 ...._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.beta_organization_rate_limit import BetaOrganizationRateLimit
20
21 __all__ = ["RateLimits", "AsyncRateLimits"]
22
23
24 class RateLimits(SyncAPIResource):
25 @cached_property
26 def with_raw_response(self) -> RateLimitsWithRawResponse:
27 """
28 This property can be used as a prefix for any HTTP method call to return
29 the raw response object instead of the parsed content.
30
31 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
32 """
33 return RateLimitsWithRawResponse(self)
34
35 @cached_property
36 def with_streaming_response(self) -> RateLimitsWithStreamingResponse:
37 """
38 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
39
40 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
41 """
42 return RateLimitsWithStreamingResponse(self)
43
44 def list(
45 self,
46 *,
47 group_type: Optional[Literal["batch", "files", "model_group", "skills", "token_count", "web_search"]]
48 | Omit = omit,
49 limit: Optional[int] | Omit = omit,
50 model: Optional[str] | Omit = omit,
51 page: Optional[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 ) -> SyncPageCursor[BetaOrganizationRateLimit]:
59 """
60 List Messages API rate limits for your organization.
61
62 Each entry corresponds to one rate-limit group (either a model family or an
63 API-surface category such as the Files API or Message Batches) and contains the
64 set of limiter values that apply to it.
65
66 When `limit` is omitted, every matching entry is returned in a single page; when
67 `limit` truncates the result, follow `next_page` to fetch the remaining entries.
68
69 Args:
70 group_type: Filter by group type.
71
72 limit: Maximum number of items to return per page. Ranges from `1` to `1000`.
73
74 When omitted, every remaining entry is returned in a single page and `next_page`
75 is `null`.
76
77 model: Filter to the single entry containing this model. Accepts full model names and
78 aliases. Returns 404 if the model is not found or has no rate limits for this
79 organization.
80
81 page: Opaque cursor from a previous response's `next_page`.
82
83 extra_headers: Send extra headers
84
85 extra_query: Add additional query parameters to the request
86
87 extra_body: Add additional JSON properties to the request
88
89 timeout: Override the client-level default timeout for this request, in seconds
90 """
91 return self._get_api_list(
92 "/v1/organizations/rate_limits?beta=true",
93 page=SyncPageCursor[BetaOrganizationRateLimit],
94 options=make_request_options(
95 extra_headers=extra_headers,
96 extra_query=extra_query,
97 extra_body=extra_body,
98 timeout=timeout,
99 query={
100 "group_type": group_type,
101 "limit": limit,
102 "model": model,
103 "page": page,
104 },
105 ),
106 model=BetaOrganizationRateLimit,
107 )
108
109
110 class AsyncRateLimits(AsyncAPIResource):
111 @cached_property
112 def with_raw_response(self) -> AsyncRateLimitsWithRawResponse:
113 """
114 This property can be used as a prefix for any HTTP method call to return
115 the raw response object instead of the parsed content.
116
117 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
118 """
119 return AsyncRateLimitsWithRawResponse(self)
120
121 @cached_property
122 def with_streaming_response(self) -> AsyncRateLimitsWithStreamingResponse:
123 """
124 An alternative to `.with_raw_response` that doesn't eagerly read the response body.
125
126 For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
127 """
128 return AsyncRateLimitsWithStreamingResponse(self)
129
130 def list(
131 self,
132 *,
133 group_type: Optional[Literal["batch", "files", "model_group", "skills", "token_count", "web_search"]]
134 | Omit = omit,
135 limit: Optional[int] | Omit = omit,
136 model: Optional[str] | Omit = omit,
137 page: Optional[str] | Omit = omit,
138 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
139 # The extra values given here take precedence over values defined on the client or passed to this method.
140 extra_headers: Headers | None = None,
141 extra_query: Query | None = None,
142 extra_body: Body | None = None,
143 timeout: float | httpx2.Timeout | None | NotGiven = not_given,
144 ) -> AsyncPaginator[BetaOrganizationRateLimit, AsyncPageCursor[BetaOrganizationRateLimit]]:
145 """
146 List Messages API rate limits for your organization.
147
148 Each entry corresponds to one rate-limit group (either a model family or an
149 API-surface category such as the Files API or Message Batches) and contains the
150 set of limiter values that apply to it.
151
152 When `limit` is omitted, every matching entry is returned in a single page; when
153 `limit` truncates the result, follow `next_page` to fetch the remaining entries.
154
155 Args:
156 group_type: Filter by group type.
157
158 limit: Maximum number of items to return per page. Ranges from `1` to `1000`.
159
160 When omitted, every remaining entry is returned in a single page and `next_page`
161 is `null`.
162
163 model: Filter to the single entry containing this model. Accepts full model names and
164 aliases. Returns 404 if the model is not found or has no rate limits for this
165 organization.
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 return self._get_api_list(
178 "/v1/organizations/rate_limits?beta=true",
179 page=AsyncPageCursor[BetaOrganizationRateLimit],
180 options=make_request_options(
181 extra_headers=extra_headers,
182 extra_query=extra_query,
183 extra_body=extra_body,
184 timeout=timeout,
185 query={
186 "group_type": group_type,
187 "limit": limit,
188 "model": model,
189 "page": page,
190 },
191 ),
192 model=BetaOrganizationRateLimit,
193 )
194
195
196 class RateLimitsWithRawResponse:
197 def __init__(self, rate_limits: RateLimits) -> None:
198 self._rate_limits = rate_limits
199
200 self.list = to_raw_response_wrapper(
201 rate_limits.list,
202 )
203
204
205 class AsyncRateLimitsWithRawResponse:
206 def __init__(self, rate_limits: AsyncRateLimits) -> None:
207 self._rate_limits = rate_limits
208
209 self.list = async_to_raw_response_wrapper(
210 rate_limits.list,
211 )
212
213
214 class RateLimitsWithStreamingResponse:
215 def __init__(self, rate_limits: RateLimits) -> None:
216 self._rate_limits = rate_limits
217
218 self.list = to_streamed_response_wrapper(
219 rate_limits.list,
220 )
221
222
223 class AsyncRateLimitsWithStreamingResponse:
224 def __init__(self, rate_limits: AsyncRateLimits) -> None:
225 self._rate_limits = rate_limits
226
227 self.list = async_to_streamed_response_wrapper(
228 rate_limits.list,
229 )