Skip to main content

gproxy_protocol/wire/openai/codex/
usage.rs

1//! Codex account usage contracts, not the public OpenAI organization API.
2//! Sources: samples/codex/codex-rs/backend-client/src/client/{task_usage,plan_history}.rs.
3//! Credit strings and JSON numbers retain upstream precision; missing amounts
4//! remain unknown. These services do not introduce inference OperationKeys.
5use crate::{Rest, WireRequest, WireResponse};
6use serde::{Deserialize, Serialize};
7use serde_json::Number;
8
9#[derive(
10    Debug,
11    Clone,
12    PartialEq,
13    Serialize,
14    Deserialize,
15    gproxy_protocol_macros::WireBuilder,
16    gproxy_protocol_macros::DeclaredFields,
17)]
18#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
19pub struct TaskUsageRequestBody {
20    pub threads: Vec<TaskUsageThread>,
21    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
22    pub rest: Rest,
23}
24
25#[derive(
26    Debug,
27    Clone,
28    PartialEq,
29    Serialize,
30    Deserialize,
31    gproxy_protocol_macros::WireBuilder,
32    gproxy_protocol_macros::DeclaredFields,
33)]
34#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
35pub struct TaskUsageThread {
36    pub thread_id: String,
37    pub created_at: Option<String>,
38    pub descendant_thread_ids: Vec<String>,
39    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
40    pub rest: Rest,
41}
42
43#[derive(
44    Debug,
45    Clone,
46    PartialEq,
47    Serialize,
48    Deserialize,
49    gproxy_protocol_macros::WireBuilder,
50    gproxy_protocol_macros::DeclaredFields,
51)]
52#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
53pub struct TaskUsageResponseBody {
54    pub data_as_of: Option<String>,
55    pub threads: Vec<TaskUsage>,
56    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
57    pub rest: Rest,
58}
59
60#[derive(
61    Debug,
62    Clone,
63    PartialEq,
64    Serialize,
65    Deserialize,
66    gproxy_protocol_macros::WireBuilder,
67    gproxy_protocol_macros::DeclaredFields,
68)]
69#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
70pub struct TaskUsage {
71    pub thread_id: String,
72    pub data_status: TaskUsageStatus,
73    pub usage_source: String,
74    pub five_hour_limit_percent: Option<Number>,
75    pub weekly_limit_percent: Option<Number>,
76    pub balance_usage_credits: Option<String>,
77    pub groups: Vec<TaskUsageGroup>,
78    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
79    pub rest: Rest,
80}
81
82#[derive(
83    Debug,
84    Clone,
85    Copy,
86    PartialEq,
87    Eq,
88    Serialize,
89    Deserialize,
90    gproxy_protocol_macros::DeclaredFields,
91)]
92#[serde(rename_all = "snake_case")]
93#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
94pub enum TaskUsageStatus {
95    Available,
96    Partial,
97    Unavailable,
98}
99
100#[derive(
101    Debug,
102    Clone,
103    PartialEq,
104    Serialize,
105    Deserialize,
106    gproxy_protocol_macros::WireBuilder,
107    gproxy_protocol_macros::DeclaredFields,
108)]
109#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
110pub struct TaskUsageGroup {
111    pub product_experience: Option<String>,
112    pub model: Option<String>,
113    pub reasoning_effort: Option<String>,
114    pub speed: Option<String>,
115    pub five_hour_limit_percent: Option<Number>,
116    pub weekly_limit_percent: Option<Number>,
117    pub balance_usage_credits: Option<String>,
118    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
119    pub rest: Rest,
120}
121
122#[derive(
123    Debug,
124    Clone,
125    PartialEq,
126    Serialize,
127    Deserialize,
128    gproxy_protocol_macros::WireBuilder,
129    gproxy_protocol_macros::DeclaredFields,
130)]
131#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
132pub struct PlanLimitHistory {
133    pub data_as_of: Option<String>,
134    pub coverage_start: Option<String>,
135    pub coverage_complete: bool,
136    #[serde(default = "approximate_by_default")]
137    pub approximate: bool,
138    pub boundary_tolerance_seconds: Option<u32>,
139    pub periods: Vec<PlanLimitPeriod>,
140    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
141    pub rest: Rest,
142}
143
144fn approximate_by_default() -> bool {
145    true
146}
147
148#[derive(
149    Debug,
150    Clone,
151    PartialEq,
152    Serialize,
153    Deserialize,
154    gproxy_protocol_macros::WireBuilder,
155    gproxy_protocol_macros::DeclaredFields,
156)]
157#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
158pub struct PlanLimitPeriod {
159    pub id: String,
160    pub window_minutes: u32,
161    pub plan_type: String,
162    pub starts_at: String,
163    pub ends_at: String,
164    pub accounting_complete: bool,
165    pub used_basis_points: Option<Number>,
166    pub breakdowns: Option<Vec<PlanLimitBreakdown>>,
167    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
168    pub rest: Rest,
169}
170
171#[derive(
172    Debug,
173    Clone,
174    PartialEq,
175    Serialize,
176    Deserialize,
177    gproxy_protocol_macros::WireBuilder,
178    gproxy_protocol_macros::DeclaredFields,
179)]
180#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
181pub struct PlanLimitBreakdown {
182    pub dimension: String,
183    pub rows: Vec<PlanLimitValue>,
184    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
185    pub rest: Rest,
186}
187
188#[derive(
189    Debug,
190    Clone,
191    PartialEq,
192    Serialize,
193    Deserialize,
194    gproxy_protocol_macros::WireBuilder,
195    gproxy_protocol_macros::DeclaredFields,
196)]
197#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
198pub struct PlanLimitValue {
199    pub key: String,
200    pub basis_points: Number,
201    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
202    pub rest: Rest,
203}
204
205pub type TaskUsageRequest = WireRequest<TaskUsageRequestBody>;
206pub type TaskUsageResponse = WireResponse<TaskUsageResponseBody>;
207pub type PlanLimitHistoryRequest = WireRequest<()>;
208pub type PlanLimitHistoryResponse = WireResponse<PlanLimitHistory>;