Skip to main content

outfox_openai/admin/
project_rate_limits.rs

1use crate::config::Config;
2use crate::error::OpenAIError;
3use crate::spec::admin::project_rate_limits::{
4    ProjectRateLimit, ProjectRateLimitListResponse, ProjectRateLimitUpdateRequest,
5};
6use crate::{Client, RequestOptions};
7
8/// Manage rate limits for a given project. Supports listing and updating rate limits per model.
9pub struct ProjectRateLimits<'c, C: Config> {
10    client: &'c Client<C>,
11    pub project_id: String,
12    pub(crate) request_options: RequestOptions,
13}
14
15impl<'c, C: Config> ProjectRateLimits<'c, C> {
16    pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
17        Self {
18            client,
19            project_id: project_id.into(),
20            request_options: RequestOptions::new(),
21        }
22    }
23
24    /// Returns the rate limits per model for a project.
25    #[crate::byot(R = serde::de::DeserializeOwned)]
26    pub async fn list(&self) -> Result<ProjectRateLimitListResponse, OpenAIError> {
27        self.client
28            .get(
29                format!("/organization/projects/{}/rate_limits", self.project_id).as_str(),
30                &self.request_options,
31            )
32            .await
33    }
34
35    /// Updates a project rate limit.
36    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
37    pub async fn update(
38        &self,
39        rate_limit_id: &str,
40        request: ProjectRateLimitUpdateRequest,
41    ) -> Result<ProjectRateLimit, OpenAIError> {
42        self.client
43            .post(
44                format!(
45                    "/organization/projects/{}/rate_limits/{rate_limit_id}",
46                    self.project_id
47                )
48                .as_str(),
49                request,
50                &self.request_options,
51            )
52            .await
53    }
54}