|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from .._types import Body, Query, Headers, NotGiven, not_given |
| 8 | +from .._compat import cached_property |
| 9 | +from .._resource import SyncAPIResource, AsyncAPIResource |
| 10 | +from .._response import ( |
| 11 | + to_raw_response_wrapper, |
| 12 | + to_streamed_response_wrapper, |
| 13 | + async_to_raw_response_wrapper, |
| 14 | + async_to_streamed_response_wrapper, |
| 15 | +) |
| 16 | +from .._base_client import make_request_options |
| 17 | +from ..types.usage_retrieve_response import UsageRetrieveResponse |
| 18 | + |
| 19 | +__all__ = ["UsageResource", "AsyncUsageResource"] |
| 20 | + |
| 21 | + |
| 22 | +class UsageResource(SyncAPIResource): |
| 23 | + @cached_property |
| 24 | + def with_raw_response(self) -> UsageResourceWithRawResponse: |
| 25 | + """ |
| 26 | + This property can be used as a prefix for any HTTP method call to return |
| 27 | + the raw response object instead of the parsed content. |
| 28 | +
|
| 29 | + For more information, see https://www.github.com/ArkHQ-io/ark-python#accessing-raw-response-data-eg-headers |
| 30 | + """ |
| 31 | + return UsageResourceWithRawResponse(self) |
| 32 | + |
| 33 | + @cached_property |
| 34 | + def with_streaming_response(self) -> UsageResourceWithStreamingResponse: |
| 35 | + """ |
| 36 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 37 | +
|
| 38 | + For more information, see https://www.github.com/ArkHQ-io/ark-python#with_streaming_response |
| 39 | + """ |
| 40 | + return UsageResourceWithStreamingResponse(self) |
| 41 | + |
| 42 | + def retrieve( |
| 43 | + self, |
| 44 | + *, |
| 45 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 46 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 47 | + extra_headers: Headers | None = None, |
| 48 | + extra_query: Query | None = None, |
| 49 | + extra_body: Body | None = None, |
| 50 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 51 | + ) -> UsageRetrieveResponse: |
| 52 | + """ |
| 53 | + Returns current usage and limit information for your account. |
| 54 | +
|
| 55 | + This endpoint is designed for: |
| 56 | +
|
| 57 | + - **AI agents/MCP servers:** Check constraints before planning batch operations |
| 58 | + - **Monitoring dashboards:** Display current usage status |
| 59 | + - **Rate limit awareness:** Know remaining capacity before making requests |
| 60 | +
|
| 61 | + **Response includes:** |
| 62 | +
|
| 63 | + - `rateLimit` - API request rate limit (requests per second) |
| 64 | + - `sendLimit` - Email sending limit (emails per hour) |
| 65 | + - `billing` - Credit balance and auto-recharge configuration |
| 66 | +
|
| 67 | + **Notes:** |
| 68 | +
|
| 69 | + - This request counts against your rate limit |
| 70 | + - `sendLimit` may be null if Postal is temporarily unavailable |
| 71 | + - `billing` is null if billing is not configured |
| 72 | + - Send limit resets at the top of each hour |
| 73 | + """ |
| 74 | + return self._get( |
| 75 | + "/usage", |
| 76 | + options=make_request_options( |
| 77 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 78 | + ), |
| 79 | + cast_to=UsageRetrieveResponse, |
| 80 | + ) |
| 81 | + |
| 82 | + |
| 83 | +class AsyncUsageResource(AsyncAPIResource): |
| 84 | + @cached_property |
| 85 | + def with_raw_response(self) -> AsyncUsageResourceWithRawResponse: |
| 86 | + """ |
| 87 | + This property can be used as a prefix for any HTTP method call to return |
| 88 | + the raw response object instead of the parsed content. |
| 89 | +
|
| 90 | + For more information, see https://www.github.com/ArkHQ-io/ark-python#accessing-raw-response-data-eg-headers |
| 91 | + """ |
| 92 | + return AsyncUsageResourceWithRawResponse(self) |
| 93 | + |
| 94 | + @cached_property |
| 95 | + def with_streaming_response(self) -> AsyncUsageResourceWithStreamingResponse: |
| 96 | + """ |
| 97 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 98 | +
|
| 99 | + For more information, see https://www.github.com/ArkHQ-io/ark-python#with_streaming_response |
| 100 | + """ |
| 101 | + return AsyncUsageResourceWithStreamingResponse(self) |
| 102 | + |
| 103 | + async def retrieve( |
| 104 | + self, |
| 105 | + *, |
| 106 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 107 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 108 | + extra_headers: Headers | None = None, |
| 109 | + extra_query: Query | None = None, |
| 110 | + extra_body: Body | None = None, |
| 111 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 112 | + ) -> UsageRetrieveResponse: |
| 113 | + """ |
| 114 | + Returns current usage and limit information for your account. |
| 115 | +
|
| 116 | + This endpoint is designed for: |
| 117 | +
|
| 118 | + - **AI agents/MCP servers:** Check constraints before planning batch operations |
| 119 | + - **Monitoring dashboards:** Display current usage status |
| 120 | + - **Rate limit awareness:** Know remaining capacity before making requests |
| 121 | +
|
| 122 | + **Response includes:** |
| 123 | +
|
| 124 | + - `rateLimit` - API request rate limit (requests per second) |
| 125 | + - `sendLimit` - Email sending limit (emails per hour) |
| 126 | + - `billing` - Credit balance and auto-recharge configuration |
| 127 | +
|
| 128 | + **Notes:** |
| 129 | +
|
| 130 | + - This request counts against your rate limit |
| 131 | + - `sendLimit` may be null if Postal is temporarily unavailable |
| 132 | + - `billing` is null if billing is not configured |
| 133 | + - Send limit resets at the top of each hour |
| 134 | + """ |
| 135 | + return await self._get( |
| 136 | + "/usage", |
| 137 | + options=make_request_options( |
| 138 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 139 | + ), |
| 140 | + cast_to=UsageRetrieveResponse, |
| 141 | + ) |
| 142 | + |
| 143 | + |
| 144 | +class UsageResourceWithRawResponse: |
| 145 | + def __init__(self, usage: UsageResource) -> None: |
| 146 | + self._usage = usage |
| 147 | + |
| 148 | + self.retrieve = to_raw_response_wrapper( |
| 149 | + usage.retrieve, |
| 150 | + ) |
| 151 | + |
| 152 | + |
| 153 | +class AsyncUsageResourceWithRawResponse: |
| 154 | + def __init__(self, usage: AsyncUsageResource) -> None: |
| 155 | + self._usage = usage |
| 156 | + |
| 157 | + self.retrieve = async_to_raw_response_wrapper( |
| 158 | + usage.retrieve, |
| 159 | + ) |
| 160 | + |
| 161 | + |
| 162 | +class UsageResourceWithStreamingResponse: |
| 163 | + def __init__(self, usage: UsageResource) -> None: |
| 164 | + self._usage = usage |
| 165 | + |
| 166 | + self.retrieve = to_streamed_response_wrapper( |
| 167 | + usage.retrieve, |
| 168 | + ) |
| 169 | + |
| 170 | + |
| 171 | +class AsyncUsageResourceWithStreamingResponse: |
| 172 | + def __init__(self, usage: AsyncUsageResource) -> None: |
| 173 | + self._usage = usage |
| 174 | + |
| 175 | + self.retrieve = async_to_streamed_response_wrapper( |
| 176 | + usage.retrieve, |
| 177 | + ) |
0 commit comments