Skip to content

Commit 0dc2237

Browse files
committed
Introduce usage module with example client implementations
1 parent de44e69 commit 0dc2237

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed

src/neuralaudio/usage/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+

src/neuralaudio/usage/client.py

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# This file was auto-generated by Fern from our API Definition.
2+
3+
from ..core.client_wrapper import SyncClientWrapper
4+
import typing
5+
from ..types.breakdown_types import BreakdownTypes
6+
from ..core.request_options import RequestOptions
7+
from ..types.usage_characters_response_model import UsageCharactersResponseModel
8+
from ..core.unchecked_base_model import construct_type
9+
from ..errors.unprocessable_entity_error import UnprocessableEntityError
10+
from ..types.http_validation_error import HttpValidationError
11+
from json.decoder import JSONDecodeError
12+
from ..core.api_error import ApiError
13+
from ..core.client_wrapper import AsyncClientWrapper
14+
15+
16+
class UsageClient:
17+
def __init__(self, *, client_wrapper: SyncClientWrapper):
18+
self._client_wrapper = client_wrapper
19+
20+
def get_characters_usage_metrics(
21+
self,
22+
*,
23+
start_unix: int,
24+
end_unix: int,
25+
include_workspace_metrics: typing.Optional[bool] = None,
26+
breakdown_type: typing.Optional[BreakdownTypes] = None,
27+
request_options: typing.Optional[RequestOptions] = None,
28+
) -> UsageCharactersResponseModel:
29+
"""
30+
Returns the credit usage metrics for the current user or the entire workspace they are part of. The response will return a time axis with unix timestamps for each day and daily usage along that axis. The usage will be broken down by the specified breakdown type. For example, breakdown type "voice" will return the usage of each voice along the time axis.
31+
32+
Parameters
33+
----------
34+
start_unix : int
35+
UTC Unix timestamp for the start of the usage window, in milliseconds. To include the first day of the window, the timestamp should be at 00:00:00 of that day.
36+
37+
end_unix : int
38+
UTC Unix timestamp for the end of the usage window, in milliseconds. To include the last day of the window, the timestamp should be at 23:59:59 of that day.
39+
40+
include_workspace_metrics : typing.Optional[bool]
41+
Whether or not to include the statistics of the entire workspace.
42+
43+
breakdown_type : typing.Optional[BreakdownTypes]
44+
How to break down the information. Cannot be "user" if include_workspace_metrics is False.
45+
46+
request_options : typing.Optional[RequestOptions]
47+
Request-specific configuration.
48+
49+
Returns
50+
-------
51+
UsageCharactersResponseModel
52+
Successful Response
53+
54+
Examples
55+
--------
56+
from neuralaudio import NeuralAudio
57+
58+
client = NeuralAudio(
59+
api_key="YOUR_API_KEY",
60+
)
61+
client.usage.get_characters_usage_metrics(
62+
start_unix=1,
63+
end_unix=1,
64+
)
65+
"""
66+
_response = self._client_wrapper.httpx_client.request(
67+
"v1/usage/character-stats",
68+
method="GET",
69+
params={
70+
"start_unix": start_unix,
71+
"end_unix": end_unix,
72+
"include_workspace_metrics": include_workspace_metrics,
73+
"breakdown_type": breakdown_type,
74+
},
75+
request_options=request_options,
76+
)
77+
try:
78+
if 200 <= _response.status_code < 300:
79+
return typing.cast(
80+
UsageCharactersResponseModel,
81+
construct_type(
82+
type_=UsageCharactersResponseModel, # type: ignore
83+
object_=_response.json(),
84+
),
85+
)
86+
if _response.status_code == 422:
87+
raise UnprocessableEntityError(
88+
typing.cast(
89+
HttpValidationError,
90+
construct_type(
91+
type_=HttpValidationError, # type: ignore
92+
object_=_response.json(),
93+
),
94+
)
95+
)
96+
_response_json = _response.json()
97+
except JSONDecodeError:
98+
raise ApiError(status_code=_response.status_code, body=_response.text)
99+
raise ApiError(status_code=_response.status_code, body=_response_json)
100+
101+
102+
class AsyncUsageClient:
103+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
104+
self._client_wrapper = client_wrapper
105+
106+
async def get_characters_usage_metrics(
107+
self,
108+
*,
109+
start_unix: int,
110+
end_unix: int,
111+
include_workspace_metrics: typing.Optional[bool] = None,
112+
breakdown_type: typing.Optional[BreakdownTypes] = None,
113+
request_options: typing.Optional[RequestOptions] = None,
114+
) -> UsageCharactersResponseModel:
115+
"""
116+
Returns the credit usage metrics for the current user or the entire workspace they are part of. The response will return a time axis with unix timestamps for each day and daily usage along that axis. The usage will be broken down by the specified breakdown type. For example, breakdown type "voice" will return the usage of each voice along the time axis.
117+
118+
Parameters
119+
----------
120+
start_unix : int
121+
UTC Unix timestamp for the start of the usage window, in milliseconds. To include the first day of the window, the timestamp should be at 00:00:00 of that day.
122+
123+
end_unix : int
124+
UTC Unix timestamp for the end of the usage window, in milliseconds. To include the last day of the window, the timestamp should be at 23:59:59 of that day.
125+
126+
include_workspace_metrics : typing.Optional[bool]
127+
Whether or not to include the statistics of the entire workspace.
128+
129+
breakdown_type : typing.Optional[BreakdownTypes]
130+
How to break down the information. Cannot be "user" if include_workspace_metrics is False.
131+
132+
request_options : typing.Optional[RequestOptions]
133+
Request-specific configuration.
134+
135+
Returns
136+
-------
137+
UsageCharactersResponseModel
138+
Successful Response
139+
140+
Examples
141+
--------
142+
import asyncio
143+
144+
from neuralaudio import AsyncNeuralAudio
145+
146+
client = AsyncNeuralAudio(
147+
api_key="YOUR_API_KEY",
148+
)
149+
150+
151+
async def main() -> None:
152+
await client.usage.get_characters_usage_metrics(
153+
start_unix=1,
154+
end_unix=1,
155+
)
156+
157+
158+
asyncio.run(main())
159+
"""
160+
_response = await self._client_wrapper.httpx_client.request(
161+
"v1/usage/character-stats",
162+
method="GET",
163+
params={
164+
"start_unix": start_unix,
165+
"end_unix": end_unix,
166+
"include_workspace_metrics": include_workspace_metrics,
167+
"breakdown_type": breakdown_type,
168+
},
169+
request_options=request_options,
170+
)
171+
try:
172+
if 200 <= _response.status_code < 300:
173+
return typing.cast(
174+
UsageCharactersResponseModel,
175+
construct_type(
176+
type_=UsageCharactersResponseModel, # type: ignore
177+
object_=_response.json(),
178+
),
179+
)
180+
if _response.status_code == 422:
181+
raise UnprocessableEntityError(
182+
typing.cast(
183+
HttpValidationError,
184+
construct_type(
185+
type_=HttpValidationError, # type: ignore
186+
object_=_response.json(),
187+
),
188+
)
189+
)
190+
_response_json = _response.json()
191+
except JSONDecodeError:
192+
raise ApiError(status_code=_response.status_code, body=_response.text)
193+
raise ApiError(status_code=_response.status_code, body=_response_json)

0 commit comments

Comments
 (0)