Skip to main content

quicknode_sdk/admin/
usage.rs

1#[cfg(feature = "rust")]
2use bon::Builder;
3#[cfg(feature = "node")]
4use napi_derive::napi;
5#[cfg(feature = "python")]
6use pyo3::pyclass;
7#[cfg(feature = "python")]
8use pyo3_stub_gen::derive::gen_stub_pyclass;
9use serde::{Deserialize, Serialize};
10
11/// Parameters for the account usage methods (`get_usage`, `get_usage_by_*`).
12/// Both bounds are optional; omit for account-to-date totals.
13#[cfg_attr(feature = "python", gen_stub_pyclass)]
14#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
15#[cfg_attr(feature = "node", napi(object))]
16#[cfg_attr(feature = "rust", derive(Builder))]
17#[derive(Debug, Clone, Default, Serialize)]
18pub struct GetUsageRequest {
19    /// Start of the query window (Unix timestamp).
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub start_time: Option<i64>,
22    /// End of the query window (Unix timestamp).
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub end_time: Option<i64>,
25}
26
27/// Aggregate account usage for a time window.
28#[cfg_attr(feature = "python", gen_stub_pyclass)]
29#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
30#[cfg_attr(feature = "node", napi(object))]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct UsageData {
33    /// Credits consumed during the window.
34    pub credits_used: i64,
35    /// Credits still available, when the plan has a finite limit.
36    pub credits_remaining: Option<i64>,
37    /// Plan's credit limit, when applicable.
38    pub limit: Option<i64>,
39    /// Credits consumed beyond the plan limit.
40    pub overages: Option<i64>,
41    /// Start of the queried window.
42    pub start_time: i64,
43    /// End of the queried window.
44    pub end_time: i64,
45}
46
47/// Response from `get_usage`.
48#[cfg_attr(feature = "python", gen_stub_pyclass)]
49#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
50#[cfg_attr(feature = "node", napi(object))]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct GetUsageResponse {
53    /// Aggregate usage payload.
54    pub data: Option<UsageData>,
55    /// Error message when the request did not succeed.
56    pub error: Option<String>,
57}
58
59/// Per-endpoint usage row.
60#[cfg_attr(feature = "python", gen_stub_pyclass)]
61#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
62#[cfg_attr(feature = "node", napi(object))]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct EndpointUsage {
65    /// Endpoint subdomain.
66    pub name: String,
67    /// Blockchain the endpoint serves.
68    pub chain: Option<String>,
69    /// Network within the chain.
70    pub network: Option<String>,
71    /// Operational status during the window.
72    pub status: Option<String>,
73    /// Total credits consumed by this endpoint.
74    pub credits_used: i64,
75    /// Human-readable label.
76    pub label: Option<String>,
77    /// Per-method credit breakdown.
78    #[serde(default)]
79    pub methods_breakdown: Vec<MethodUsage>,
80    /// Request count during the window.
81    pub requests: Option<i64>,
82}
83
84/// Per-method usage row.
85#[cfg_attr(feature = "python", gen_stub_pyclass)]
86#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
87#[cfg_attr(feature = "node", napi(object))]
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct MethodUsage {
90    /// RPC method name.
91    pub method_name: String,
92    /// Credits consumed by this method.
93    pub credits_used: i64,
94    /// Whether the call required an archival node.
95    pub archive: Option<bool>,
96    /// Network the calls targeted.
97    pub network: Option<String>,
98    /// Chain the calls targeted.
99    pub chain: Option<String>,
100}
101
102/// Per-chain usage row.
103#[cfg_attr(feature = "python", gen_stub_pyclass)]
104#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
105#[cfg_attr(feature = "node", napi(object))]
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct ChainUsage {
108    /// Chain name or slug.
109    pub name: String,
110    /// Credits consumed on the chain.
111    pub credits_used: i64,
112}
113
114/// Inner data for `get_usage_by_endpoint`.
115#[cfg_attr(feature = "python", gen_stub_pyclass)]
116#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
117#[cfg_attr(feature = "node", napi(object))]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct UsageByEndpointData {
120    /// Per-endpoint rows.
121    #[serde(default)]
122    pub endpoints: Vec<EndpointUsage>,
123    /// Start of the queried window.
124    pub start_time: Option<i64>,
125    /// End of the queried window.
126    pub end_time: Option<i64>,
127}
128
129/// Response from `get_usage_by_endpoint`.
130#[cfg_attr(feature = "python", gen_stub_pyclass)]
131#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
132#[cfg_attr(feature = "node", napi(object))]
133#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct GetUsageByEndpointResponse {
135    /// Per-endpoint usage payload.
136    pub data: Option<UsageByEndpointData>,
137    /// Error message when the request did not succeed.
138    pub error: Option<String>,
139}
140
141/// Inner data for `get_usage_by_method`.
142#[cfg_attr(feature = "python", gen_stub_pyclass)]
143#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
144#[cfg_attr(feature = "node", napi(object))]
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct UsageByMethodData {
147    /// Per-method rows.
148    #[serde(default)]
149    pub methods: Vec<MethodUsage>,
150    /// Start of the queried window.
151    pub start_time: Option<i64>,
152    /// End of the queried window.
153    pub end_time: Option<i64>,
154}
155
156/// Response from `get_usage_by_method`.
157#[cfg_attr(feature = "python", gen_stub_pyclass)]
158#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
159#[cfg_attr(feature = "node", napi(object))]
160#[derive(Debug, Clone, Serialize, Deserialize)]
161pub struct GetUsageByMethodResponse {
162    /// Per-method usage payload.
163    pub data: Option<UsageByMethodData>,
164    /// Error message when the request did not succeed.
165    pub error: Option<String>,
166}
167
168/// Inner data for `get_usage_by_chain`.
169#[cfg_attr(feature = "python", gen_stub_pyclass)]
170#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
171#[cfg_attr(feature = "node", napi(object))]
172#[derive(Debug, Clone, Serialize, Deserialize)]
173pub struct UsageByChainData {
174    /// Per-chain rows.
175    #[serde(default)]
176    pub chains: Vec<ChainUsage>,
177    /// Start of the queried window.
178    pub start_time: Option<i64>,
179    /// End of the queried window.
180    pub end_time: Option<i64>,
181}
182
183/// Response from `get_usage_by_chain`.
184#[cfg_attr(feature = "python", gen_stub_pyclass)]
185#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
186#[cfg_attr(feature = "node", napi(object))]
187#[derive(Debug, Clone, Serialize, Deserialize)]
188pub struct GetUsageByChainResponse {
189    /// Per-chain usage payload.
190    pub data: Option<UsageByChainData>,
191    /// Error message when the request did not succeed.
192    pub error: Option<String>,
193}
194
195/// Per-tag usage row.
196#[cfg_attr(feature = "python", gen_stub_pyclass)]
197#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
198#[cfg_attr(feature = "node", napi(object))]
199#[derive(Debug, Clone, Serialize, Deserialize)]
200pub struct TagUsage {
201    /// Tag identifier.
202    pub tag_id: Option<i32>,
203    /// Tag label.
204    pub label: String,
205    /// Credits consumed by endpoints with this tag.
206    pub credits_used: i64,
207    /// Request count during the window.
208    pub requests: i64,
209}
210
211/// Inner data for `get_usage_by_tag`.
212#[cfg_attr(feature = "python", gen_stub_pyclass)]
213#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
214#[cfg_attr(feature = "node", napi(object))]
215#[derive(Debug, Clone, Serialize, Deserialize)]
216pub struct UsageByTagData {
217    /// Per-tag rows.
218    #[serde(default)]
219    pub tags: Vec<TagUsage>,
220    /// Start of the queried window.
221    pub start_time: Option<i64>,
222    /// End of the queried window.
223    pub end_time: Option<i64>,
224}
225
226/// Response from `get_usage_by_tag`.
227#[cfg_attr(feature = "python", gen_stub_pyclass)]
228#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
229#[cfg_attr(feature = "node", napi(object))]
230#[derive(Debug, Clone, Serialize, Deserialize)]
231pub struct GetUsageByTagResponse {
232    /// Per-tag usage payload.
233    pub data: Option<UsageByTagData>,
234    /// Error message when the request did not succeed.
235    pub error: Option<String>,
236}