portkey_sdk/model/
logs.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Export status enum
6#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum ExportStatus {
9    Draft,
10    InProgress,
11    Success,
12    Failed,
13    Stopped,
14}
15
16/// Requested data fields for log exports
17#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
18#[serde(rename_all = "snake_case")]
19pub enum LogExportField {
20    Id,
21    TraceId,
22    CreatedAt,
23    Request,
24    Response,
25    IsSuccess,
26    AiOrg,
27    AiModel,
28    ReqUnits,
29    ResUnits,
30    TotalUnits,
31    RequestUrl,
32    Cost,
33    CostCurrency,
34    ResponseTime,
35    ResponseStatusCode,
36    Mode,
37    Config,
38    PromptSlug,
39    Metadata,
40}
41
42/// Filters for log generation queries
43#[derive(Debug, Clone, Default, Serialize, Deserialize)]
44pub struct GenerationsFilter {
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub time_of_generation_min: Option<String>,
47
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub time_of_generation_max: Option<String>,
50
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub total_units_min: Option<i32>,
53
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub total_units_max: Option<i32>,
56
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub cost_min: Option<f64>,
59
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub cost_max: Option<f64>,
62
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub ai_model: Option<String>,
65
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub prompt_token_min: Option<i32>,
68
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub prompt_token_max: Option<i32>,
71
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub completion_token_min: Option<i32>,
74
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub completion_token_max: Option<i32>,
77
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub status_code: Option<String>,
80
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub metadata: Option<HashMap<String, serde_json::Value>>,
83
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub ai_org_model: Option<String>,
86
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub weighted_feedback_min: Option<f64>,
89
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub weighted_feedback_max: Option<f64>,
92
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub virtual_keys: Option<String>,
95
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub trace_id: Option<String>,
98
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub configs: Option<String>,
101
102    #[serde(skip_serializing_if = "Option::is_none")]
103    pub workspace_slug: Option<String>,
104
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub prompt_slug: Option<String>,
107
108    /// Maximum number of items per page (max: 50000, default: 50000)
109    #[serde(skip_serializing_if = "Option::is_none")]
110    pub page_size: Option<i32>,
111
112    /// Current page number
113    #[serde(skip_serializing_if = "Option::is_none")]
114    pub current_page: Option<i32>,
115}
116
117/// Request to create a log export
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct CreateLogExportRequest {
120    /// Workspace ID
121    #[serde(skip_serializing_if = "Option::is_none")]
122    pub workspace_id: Option<String>,
123
124    /// Filters to apply to the export
125    pub filters: GenerationsFilter,
126
127    /// Fields to include in the export
128    pub requested_data: Vec<LogExportField>,
129
130    /// Description of the export
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub description: Option<String>,
133}
134
135/// Response from creating or updating a log export
136#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct CreateLogExportResponse {
138    /// Export ID
139    pub id: String,
140
141    /// Total number of items in the export
142    pub total: i32,
143
144    /// Object type (always "export")
145    pub object: String,
146}
147
148/// Log export item details
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct LogExport {
151    /// Export ID
152    pub id: String,
153
154    /// Organization ID
155    pub organisation_id: String,
156
157    /// Filters applied to this export
158    pub filters: GenerationsFilter,
159
160    /// Requested data fields
161    pub requested_data: Vec<LogExportField>,
162
163    /// Export status
164    pub status: ExportStatus,
165
166    /// Export description
167    pub description: String,
168
169    /// Creation timestamp
170    pub created_at: String,
171
172    /// Last update timestamp
173    pub last_updated_at: String,
174
175    /// User who created the export
176    pub created_by: String,
177
178    /// Workspace ID
179    pub workspace_id: String,
180
181    /// Object type (always "export")
182    pub object: String,
183}
184
185/// Response from export task operations (start/cancel)
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct ExportTaskResponse {
188    /// Status message
189    pub message: String,
190
191    /// Object type (always "export")
192    pub object: String,
193}
194
195/// Response from download request
196#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct DownloadLogExportResponse {
198    /// Pre-signed URL for downloading the export
199    pub signed_url: String,
200}
201
202/// HTTP request data for a log entry
203#[derive(Debug, Clone, Serialize, Deserialize)]
204pub struct LogRequest {
205    /// Request URL
206    pub url: String,
207
208    /// HTTP method
209    #[serde(skip_serializing_if = "Option::is_none")]
210    pub method: Option<String>,
211
212    /// Request headers
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub headers: Option<HashMap<String, String>>,
215
216    /// Request body
217    pub body: serde_json::Value,
218}
219
220/// HTTP response data for a log entry
221#[derive(Debug, Clone, Serialize, Deserialize)]
222pub struct LogResponse {
223    /// HTTP status code
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub status: Option<i32>,
226
227    /// Response headers
228    #[serde(skip_serializing_if = "Option::is_none")]
229    pub headers: Option<HashMap<String, String>>,
230
231    /// Response body
232    pub body: serde_json::Value,
233
234    /// Response time in milliseconds
235    #[serde(skip_serializing_if = "Option::is_none")]
236    pub response_time: Option<i32>,
237}
238
239/// Metadata for a log entry
240#[derive(Debug, Clone, Default, Serialize, Deserialize)]
241pub struct LogMetadata {
242    /// Trace ID for distributed tracing
243    #[serde(skip_serializing_if = "Option::is_none")]
244    pub trace_id: Option<String>,
245
246    /// Span ID for distributed tracing
247    #[serde(skip_serializing_if = "Option::is_none")]
248    pub span_id: Option<String>,
249
250    /// Span name for distributed tracing
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub span_name: Option<String>,
253
254    /// Additional metadata fields
255    #[serde(flatten)]
256    pub additional: HashMap<String, serde_json::Value>,
257}
258
259/// A custom log entry
260#[derive(Debug, Clone, Serialize, Deserialize)]
261pub struct CustomLog {
262    /// Request data
263    pub request: LogRequest,
264
265    /// Response data
266    pub response: LogResponse,
267
268    /// Optional metadata
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub metadata: Option<LogMetadata>,
271}
272
273/// Request to insert one or more log entries
274#[derive(Debug, Clone, Serialize, Deserialize)]
275#[serde(untagged)]
276pub enum InsertLogRequest {
277    /// Single log entry
278    Single(Box<CustomLog>),
279    /// Multiple log entries
280    Multiple(Vec<CustomLog>),
281}
282
283/// Response from inserting log entries
284#[derive(Debug, Clone, Serialize, Deserialize)]
285pub struct InsertLogResponse {
286    /// Status message
287    pub status: String,
288
289    /// Log IDs
290    #[serde(skip_serializing_if = "Option::is_none")]
291    pub log_ids: Option<Vec<String>>,
292}
293
294/// Request to update a log export
295#[derive(Debug, Clone, Serialize, Deserialize)]
296pub struct UpdateLogExportRequest {
297    /// Workspace ID
298    #[serde(skip_serializing_if = "Option::is_none")]
299    pub workspace_id: Option<String>,
300
301    /// Filters for the export
302    pub filters: GenerationsFilter,
303
304    /// Fields to include in the export
305    #[serde(skip_serializing_if = "Option::is_none")]
306    pub requested_data: Option<Vec<LogExportField>>,
307}
308
309/// Response from updating a log export
310#[derive(Debug, Clone, Serialize, Deserialize)]
311pub struct UpdateLogExportResponse {
312    /// Export ID
313    pub id: String,
314
315    /// Total number of items
316    pub total: i32,
317
318    /// Object type (always "export")
319    pub object: String,
320}
321
322// ============================================================================
323// List Log Exports Models
324// ============================================================================
325
326/// Parameters for listing log exports
327#[derive(Debug, Clone, Default, Serialize, Deserialize)]
328pub struct ListLogExportsParams {
329    /// Workspace ID to filter by
330    #[serde(skip_serializing_if = "Option::is_none")]
331    pub workspace_id: Option<String>,
332}
333
334/// A log export item in a list
335#[derive(Debug, Clone, Serialize, Deserialize)]
336pub struct LogExportListItem {
337    /// Export ID
338    pub id: String,
339
340    /// Organization ID
341    pub organisation_id: String,
342
343    /// Export filters
344    pub filters: GenerationsFilter,
345
346    /// Requested data fields
347    pub requested_data: Vec<LogExportField>,
348
349    /// Export status
350    pub status: ExportStatus,
351
352    /// Export description
353    pub description: String,
354
355    /// Creation timestamp
356    pub created_at: String,
357
358    /// Last update timestamp
359    pub last_updated_at: String,
360
361    /// User who created the export
362    pub created_by: String,
363
364    /// Workspace ID
365    pub workspace_id: String,
366
367    /// Object type (always "export")
368    pub object: String,
369}
370
371/// Response from listing log exports
372#[derive(Debug, Clone, Serialize, Deserialize)]
373pub struct ListLogExportsResponse {
374    /// Object type (always "list")
375    pub object: String,
376
377    /// Total number of exports
378    pub total: i32,
379
380    /// Array of export items
381    pub data: Vec<LogExportListItem>,
382}