Skip to main content

outfox_openai/spec/admin/usage/
api.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5
6/// Query parameters for organization usage endpoints.
7#[derive(Debug, Clone, Serialize, Default, Builder)]
8#[builder(name = "UsageQueryParamsArgs")]
9#[builder(pattern = "mutable")]
10#[builder(setter(into, strip_option), default)]
11#[builder(derive(Debug))]
12#[builder(build_fn(error = "OpenAIError"))]
13pub struct UsageQueryParams {
14    /// Start time (Unix seconds) of the query time range, inclusive.
15    pub start_time: u64,
16    /// End time (Unix seconds) of the query time range, exclusive.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub end_time: Option<u64>,
19    /// Width of each time bucket in response. Currently `1m`, `1h` and `1d` are supported, default
20    /// to `1d`.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub bucket_width: Option<UsageBucketWidth>,
23    /// Return only usage for these projects.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub project_ids: Option<Vec<String>>,
26    /// Return only usage for these users.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub user_ids: Option<Vec<String>>,
29    /// Return only usage for these API keys.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub api_key_ids: Option<Vec<String>>,
32    /// Return only usage for these models.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub models: Option<Vec<String>>,
35    /// If `true`, return batch jobs only. If `false`, return non-batch jobs only. By default,
36    /// return both.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub batch: Option<bool>,
39    /// Group the usage data by the specified fields.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub group_by: Option<Vec<UsageGroupBy>>,
42    /// Specifies the number of buckets to return.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub limit: Option<u32>,
45    /// A cursor for use in pagination. Corresponding to the `next_page` field from the previous
46    /// response.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub page: Option<String>,
49}
50
51/// Width of each time bucket in response.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(rename_all = "lowercase")]
54pub enum UsageBucketWidth {
55    #[serde(rename = "1m")]
56    OneMinute,
57    #[serde(rename = "1h")]
58    OneHour,
59    #[serde(rename = "1d")]
60    OneDay,
61}
62
63/// Fields to group usage data by.
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(rename_all = "snake_case")]
66pub enum UsageGroupBy {
67    ProjectId,
68    UserId,
69    ApiKeyId,
70    Model,
71    Batch,
72    ServiceTier,
73}