portkey_sdk/model/
responses.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Represents a response from the Portkey API.
6///
7/// A response contains information about API calls made through Portkey,
8/// including metadata, status, and associated input/output items.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Response {
11    /// Unique identifier for the response
12    pub id: String,
13
14    /// Timestamp when the response was created
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub created_at: Option<String>,
17
18    /// Timestamp when the response was last updated
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub updated_at: Option<String>,
21
22    /// The status of the response
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub status: Option<String>,
25
26    /// The model used for this response
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub model: Option<String>,
29
30    /// The provider used for this response
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub provider: Option<String>,
33
34    /// Additional metadata associated with the response
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub metadata: Option<HashMap<String, serde_json::Value>>,
37
38    /// The trace ID associated with this response
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub trace_id: Option<String>,
41
42    /// Request body sent to the provider
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub request: Option<serde_json::Value>,
45
46    /// Response body received from the provider
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub response: Option<serde_json::Value>,
49
50    /// Total tokens used in the request and response
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub total_tokens: Option<i64>,
53
54    /// Number of tokens in the prompt
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub prompt_tokens: Option<i64>,
57
58    /// Number of tokens in the completion
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub completion_tokens: Option<i64>,
61
62    /// Time taken to complete the request in milliseconds
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub latency_ms: Option<i64>,
65
66    /// Cost of the request
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub cost: Option<f64>,
69}
70
71/// Request body for creating a new response.
72///
73/// # Example
74///
75/// ```rust
76/// use portkey_sdk::model::CreateResponseRequest;
77/// use std::collections::HashMap;
78///
79/// let mut metadata = HashMap::new();
80/// metadata.insert("user_id".to_string(), serde_json::json!("user123"));
81///
82/// let request = CreateResponseRequest {
83///     trace_id: Some("trace-123".to_string()),
84///     metadata: Some(metadata),
85///     model: Some("gpt-4".to_string()),
86///     provider: Some("openai".to_string()),
87///     status: Some("success".to_string()),
88///     request: None,
89///     response: None,
90///     total_tokens: Some(150),
91///     prompt_tokens: Some(100),
92///     completion_tokens: Some(50),
93///     latency_ms: Some(1500),
94///     cost: Some(0.003),
95/// };
96/// ```
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct CreateResponseRequest {
99    /// The trace ID to associate with this response
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub trace_id: Option<String>,
102
103    /// Additional metadata to associate with the response
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub metadata: Option<HashMap<String, serde_json::Value>>,
106
107    /// The model used for this response
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub model: Option<String>,
110
111    /// The provider used for this response
112    #[serde(skip_serializing_if = "Option::is_none")]
113    pub provider: Option<String>,
114
115    /// The status of the response
116    #[serde(skip_serializing_if = "Option::is_none")]
117    pub status: Option<String>,
118
119    /// Request body sent to the provider
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub request: Option<serde_json::Value>,
122
123    /// Response body received from the provider
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub response: Option<serde_json::Value>,
126
127    /// Total tokens used in the request and response
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub total_tokens: Option<i64>,
130
131    /// Number of tokens in the prompt
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub prompt_tokens: Option<i64>,
134
135    /// Number of tokens in the completion
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub completion_tokens: Option<i64>,
138
139    /// Time taken to complete the request in milliseconds
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub latency_ms: Option<i64>,
142
143    /// Cost of the request
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub cost: Option<f64>,
146}
147
148/// Represents an input item associated with a response.
149///
150/// Input items contain the individual messages or prompts that were
151/// part of the request to the AI provider.
152#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct InputItem {
154    /// Unique identifier for the input item
155    pub id: String,
156
157    /// The response ID this input item belongs to
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub response_id: Option<String>,
160
161    /// Timestamp when the input item was created
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub created_at: Option<String>,
164
165    /// The role of the message (e.g., "system", "user", "assistant")
166    #[serde(skip_serializing_if = "Option::is_none")]
167    pub role: Option<String>,
168
169    /// The content of the message
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub content: Option<String>,
172
173    /// Additional metadata for the input item
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub metadata: Option<HashMap<String, serde_json::Value>>,
176}
177
178/// Response containing a list of input items.
179///
180/// Returned by the list input items endpoint.
181#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct ListInputItemsResponse {
183    /// List of input items
184    pub data: Vec<InputItem>,
185
186    /// Total count of input items
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub total: Option<i64>,
189
190    /// Whether there are more items available
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub has_more: Option<bool>,
193}
194
195/// Parameters for listing input items.
196///
197/// Used to paginate through input items for a specific response.
198///
199/// # Example
200///
201/// ```rust
202/// use portkey_sdk::model::ListInputItemsParams;
203///
204/// let params = ListInputItemsParams {
205///     limit: Some(50),
206///     offset: Some(0),
207/// };
208/// ```
209#[derive(Debug, Clone, Default, Serialize, Deserialize)]
210pub struct ListInputItemsParams {
211    /// Maximum number of items to return
212    #[serde(skip_serializing_if = "Option::is_none")]
213    pub limit: Option<i32>,
214
215    /// Number of items to skip
216    #[serde(skip_serializing_if = "Option::is_none")]
217    pub offset: Option<i32>,
218}