Skip to main content

systemprompt_ai/services/gateway/
spec.rs

1//! Declarative gateway-policy specification.
2//!
3//! Spec payload of `ai_gateway_policies` rows, shared with the YAML schema in
4//! `services/gateway/policies.yaml`. Carries quota windows and safety
5//! configuration.
6//!
7//! Model exposure lives on the profile's gateway catalog, not here — see
8//! `GatewayConfig::is_model_exposed`.
9//!
10//! Copyright (c) systemprompt.io — Business Source License 1.1.
11//! See <https://systemprompt.io> for licensing details.
12
13use serde::{Deserialize, Serialize};
14
15#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
16#[serde(deny_unknown_fields)]
17pub struct QuotaWindow {
18    pub window_seconds: i32,
19    pub max_requests: Option<i64>,
20    pub max_input_tokens: Option<i64>,
21    pub max_output_tokens: Option<i64>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, Default)]
25#[serde(deny_unknown_fields)]
26pub struct SafetyConfig {
27    #[serde(default)]
28    pub scanners: Vec<String>,
29    #[serde(default)]
30    pub block_categories: Vec<String>,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, Default)]
34#[serde(deny_unknown_fields)]
35pub struct GatewayPolicySpec {
36    #[serde(default)]
37    pub quota_windows: Vec<QuotaWindow>,
38    #[serde(default)]
39    pub safety: SafetyConfig,
40}
41
42impl GatewayPolicySpec {
43    #[must_use]
44    pub fn permissive() -> Self {
45        Self::default()
46    }
47}