Skip to main content

quicknode_sdk/admin/
endpoint_rate_limits.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/// A per-method rate limiter configured on an endpoint.
12#[cfg_attr(feature = "python", gen_stub_pyclass)]
13#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
14#[cfg_attr(feature = "node", napi(object))]
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct MethodRateLimiter {
17    /// Rate limiter identifier.
18    pub id: String,
19    /// Interval over which the rate applies (e.g. `second`, `minute`).
20    pub interval: String,
21    /// RPC methods the limiter applies to.
22    #[serde(default)]
23    pub methods: Vec<String>,
24    /// Maximum number of calls allowed per interval.
25    pub rate: i32,
26    /// Whether the limiter is `enabled` or `disabled`.
27    pub status: String,
28    /// Creation timestamp.
29    pub created: String,
30}
31
32/// Inner data for `get_method_rate_limits`.
33#[cfg_attr(feature = "python", gen_stub_pyclass)]
34#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
35#[cfg_attr(feature = "node", napi(object))]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct GetMethodRateLimitsData {
38    /// Rate limiters configured on the endpoint.
39    #[serde(default)]
40    pub rate_limiters: Vec<MethodRateLimiter>,
41}
42
43/// Response from `get_method_rate_limits`.
44#[cfg_attr(feature = "python", gen_stub_pyclass)]
45#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
46#[cfg_attr(feature = "node", napi(object))]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct GetMethodRateLimitsResponse {
49    /// Rate limiters payload.
50    pub data: Option<GetMethodRateLimitsData>,
51    /// Error message when the request did not succeed.
52    pub error: Option<String>,
53}
54
55/// Parameters for `create_method_rate_limit`.
56#[cfg_attr(feature = "python", gen_stub_pyclass)]
57#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
58#[cfg_attr(feature = "node", napi(object))]
59#[cfg_attr(feature = "rust", derive(Builder))]
60#[derive(Debug, Clone, Default, Serialize)]
61pub struct CreateMethodRateLimitRequest {
62    /// Interval over which the rate applies (e.g. `second`).
63    pub interval: String,
64    /// RPC methods the limiter applies to.
65    pub methods: Vec<String>,
66    /// Maximum number of calls allowed per interval.
67    pub rate: i32,
68}
69
70/// Response from `create_method_rate_limit`.
71#[cfg_attr(feature = "python", gen_stub_pyclass)]
72#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
73#[cfg_attr(feature = "node", napi(object))]
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct CreateMethodRateLimitResponse {
76    /// The created rate limiter.
77    pub data: Option<MethodRateLimiter>,
78    /// Error message when the request did not succeed.
79    pub error: Option<String>,
80}
81
82/// Parameters for `update_method_rate_limit`. Only provided fields are changed.
83#[cfg_attr(feature = "python", gen_stub_pyclass)]
84#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
85#[cfg_attr(feature = "node", napi(object))]
86#[cfg_attr(feature = "rust", derive(Builder))]
87#[derive(Debug, Clone, Default, Serialize)]
88pub struct UpdateMethodRateLimitRequest {
89    /// New set of RPC methods the limiter applies to.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub methods: Option<Vec<String>>,
92    /// New status (`enabled` or `disabled`).
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub status: Option<String>,
95    /// New rate value.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub rate: Option<i32>,
98}
99
100/// Response from `update_method_rate_limit`.
101#[cfg_attr(feature = "python", gen_stub_pyclass)]
102#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
103#[cfg_attr(feature = "node", napi(object))]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct UpdateMethodRateLimitResponse {
106    /// The updated rate limiter.
107    pub data: Option<MethodRateLimiter>,
108    /// Error message when the request did not succeed.
109    pub error: Option<String>,
110}
111
112/// Endpoint-wide rate limit settings.
113#[cfg_attr(feature = "python", gen_stub_pyclass)]
114#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
115#[cfg_attr(feature = "node", napi(object))]
116#[cfg_attr(feature = "rust", derive(Builder))]
117#[derive(Debug, Clone, Default, Serialize)]
118pub struct RateLimitSettings {
119    /// Requests per second.
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub rps: Option<i32>,
122    /// Requests per minute.
123    #[serde(skip_serializing_if = "Option::is_none")]
124    pub rpm: Option<i32>,
125    /// Requests per day.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub rpd: Option<i32>,
128}
129
130/// Parameters for `update_rate_limits`.
131#[cfg_attr(feature = "python", gen_stub_pyclass)]
132#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
133#[cfg_attr(feature = "node", napi(object))]
134#[cfg_attr(feature = "rust", derive(Builder))]
135#[derive(Debug, Clone, Default, Serialize)]
136pub struct UpdateRateLimitsRequest {
137    /// Rate limit values to apply.
138    pub rate_limits: RateLimitSettings,
139}
140
141/// A single rate-limit row returned by `get_rate_limits`, identifying the
142/// bucket (`rps`/`rpm`/`rpd`), the value enforced, and whether the value comes
143/// from the plan default or a user-set override.
144#[cfg_attr(feature = "python", gen_stub_pyclass)]
145#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
146#[cfg_attr(feature = "node", napi(object))]
147#[derive(Debug, Clone, Serialize, Deserialize)]
148pub struct RateLimitEntry {
149    /// Which bucket this row applies to: `rps`, `rpm`, or `rpd`.
150    pub bucket: String,
151    /// The enforced value for this bucket.
152    pub rate_limit: i32,
153    /// Where the value comes from: `plan_default` or `user_override`.
154    pub source: String,
155    /// Row identifier. Present on `user_override` rows — pass it to
156    /// `delete_rate_limit_override` to remove the override. May be absent on
157    /// `plan_default` rows and cannot be deleted there.
158    #[serde(default)]
159    pub id: Option<String>,
160}
161
162/// Inner data for `get_rate_limits`.
163#[cfg_attr(feature = "python", gen_stub_pyclass)]
164#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
165#[cfg_attr(feature = "node", napi(object))]
166#[derive(Debug, Clone, Serialize, Deserialize)]
167pub struct GetRateLimitsData {
168    /// One row per enforced bucket.
169    #[serde(default)]
170    pub rate_limits: Vec<RateLimitEntry>,
171}
172
173/// Response from `get_rate_limits`.
174#[cfg_attr(feature = "python", gen_stub_pyclass)]
175#[cfg_attr(feature = "python", pyclass(get_all, set_all))]
176#[cfg_attr(feature = "node", napi(object))]
177#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct GetRateLimitsResponse {
179    /// Rate-limit rows with their source.
180    pub data: Option<GetRateLimitsData>,
181    /// Error message when the request did not succeed.
182    pub error: Option<String>,
183}