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