Skip to main content

systemprompt_models/profile/
rate_limits.rs

1//! Rate limits configuration.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
9#[serde(deny_unknown_fields)]
10pub struct TierMultipliers {
11    #[serde(default = "default_admin_multiplier")]
12    pub admin: f64,
13
14    #[serde(default = "default_user_multiplier")]
15    pub user: f64,
16
17    #[serde(default = "default_a2a_multiplier")]
18    pub a2a: f64,
19
20    #[serde(default = "default_mcp_multiplier")]
21    pub mcp: f64,
22
23    #[serde(default = "default_service_multiplier")]
24    pub service: f64,
25
26    #[serde(default = "default_anon_multiplier")]
27    pub anon: f64,
28}
29
30pub const fn default_admin_multiplier() -> f64 {
31    10.0
32}
33pub const fn default_user_multiplier() -> f64 {
34    1.0
35}
36pub const fn default_a2a_multiplier() -> f64 {
37    5.0
38}
39pub const fn default_mcp_multiplier() -> f64 {
40    5.0
41}
42pub const fn default_service_multiplier() -> f64 {
43    5.0
44}
45pub const fn default_anon_multiplier() -> f64 {
46    0.5
47}
48
49impl Default for TierMultipliers {
50    fn default() -> Self {
51        Self {
52            admin: default_admin_multiplier(),
53            user: default_user_multiplier(),
54            a2a: default_a2a_multiplier(),
55            mcp: default_mcp_multiplier(),
56            service: default_service_multiplier(),
57            anon: default_anon_multiplier(),
58        }
59    }
60}
61
62#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
63#[serde(deny_unknown_fields)]
64pub struct RateLimitsConfig {
65    #[serde(default)]
66    pub disabled: bool,
67
68    #[serde(default = "default_oauth_public")]
69    pub oauth_public_per_second: u64,
70
71    #[serde(default = "default_oauth_auth")]
72    pub oauth_auth_per_second: u64,
73
74    #[serde(default = "default_contexts")]
75    pub contexts_per_second: u64,
76
77    #[serde(default = "default_tasks")]
78    pub tasks_per_second: u64,
79
80    #[serde(default = "default_artifacts")]
81    pub artifacts_per_second: u64,
82
83    #[serde(default = "default_agent_registry")]
84    pub agent_registry_per_second: u64,
85
86    #[serde(default = "default_agents")]
87    pub agents_per_second: u64,
88
89    #[serde(default = "default_mcp_registry")]
90    pub mcp_registry_per_second: u64,
91
92    #[serde(default = "default_mcp")]
93    pub mcp_per_second: u64,
94
95    #[serde(default = "default_stream")]
96    pub stream_per_second: u64,
97
98    #[serde(default = "default_content")]
99    pub content_per_second: u64,
100
101    #[serde(default = "default_burst")]
102    pub burst_multiplier: u64,
103
104    #[serde(default)]
105    pub tier_multipliers: TierMultipliers,
106}
107
108pub const fn default_oauth_public() -> u64 {
109    10
110}
111pub const fn default_oauth_auth() -> u64 {
112    10
113}
114pub const fn default_contexts() -> u64 {
115    100
116}
117pub const fn default_tasks() -> u64 {
118    50
119}
120pub const fn default_artifacts() -> u64 {
121    50
122}
123pub const fn default_agent_registry() -> u64 {
124    50
125}
126pub const fn default_agents() -> u64 {
127    20
128}
129pub const fn default_mcp_registry() -> u64 {
130    50
131}
132pub const fn default_mcp() -> u64 {
133    200
134}
135pub const fn default_stream() -> u64 {
136    100
137}
138pub const fn default_content() -> u64 {
139    50
140}
141pub const fn default_burst() -> u64 {
142    3
143}
144
145impl Default for RateLimitsConfig {
146    fn default() -> Self {
147        Self {
148            disabled: false,
149            oauth_public_per_second: default_oauth_public(),
150            oauth_auth_per_second: default_oauth_auth(),
151            contexts_per_second: default_contexts(),
152            tasks_per_second: default_tasks(),
153            artifacts_per_second: default_artifacts(),
154            agent_registry_per_second: default_agent_registry(),
155            agents_per_second: default_agents(),
156            mcp_registry_per_second: default_mcp_registry(),
157            mcp_per_second: default_mcp(),
158            stream_per_second: default_stream(),
159            content_per_second: default_content(),
160            burst_multiplier: default_burst(),
161            tier_multipliers: TierMultipliers::default(),
162        }
163    }
164}