openai_tools/batch/response.rs
1//! OpenAI Batch API Response Types
2//!
3//! This module defines the response types for the OpenAI Batch API.
4
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// The status of a batch job.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum BatchStatus {
12 /// The batch is being validated.
13 Validating,
14 /// The batch failed validation.
15 Failed,
16 /// The batch is currently being processed.
17 InProgress,
18 /// The batch is being finalized.
19 Finalizing,
20 /// The batch has been completed successfully.
21 Completed,
22 /// The batch has expired (24h window passed).
23 Expired,
24 /// The batch is being cancelled.
25 Cancelling,
26 /// The batch has been cancelled.
27 Cancelled,
28}
29
30/// Counts of requests in different states within the batch.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct RequestCounts {
33 /// Total number of requests in the batch.
34 pub total: u32,
35 /// Number of requests that have been completed successfully.
36 pub completed: u32,
37 /// Number of requests that have failed.
38 pub failed: u32,
39}
40
41/// An error that occurred during batch processing.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct BatchError {
44 /// A machine-readable error code.
45 pub code: String,
46 /// A human-readable error message.
47 pub message: String,
48 /// The parameter related to the error, if any.
49 pub param: Option<String>,
50 /// The line number in the input file, if applicable.
51 pub line: Option<u32>,
52}
53
54/// A collection of errors from batch processing.
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct BatchErrors {
57 /// The type of object (always "list").
58 pub object: Option<String>,
59 /// The list of errors.
60 pub data: Vec<BatchError>,
61}
62
63/// A batch object representing an async batch job.
64///
65/// The Batch API allows you to send asynchronous groups of requests
66/// with 50% lower costs and higher rate limits.
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct BatchObject {
69 /// The unique identifier for the batch.
70 pub id: String,
71
72 /// The object type (always "batch").
73 pub object: String,
74
75 /// The API endpoint used for the batch.
76 pub endpoint: String,
77
78 /// Any errors that occurred during batch processing.
79 pub errors: Option<BatchErrors>,
80
81 /// The ID of the input file containing the requests.
82 pub input_file_id: String,
83
84 /// The time window for batch completion (e.g., "24h").
85 pub completion_window: String,
86
87 /// The current status of the batch.
88 pub status: BatchStatus,
89
90 /// The ID of the output file containing the results.
91 pub output_file_id: Option<String>,
92
93 /// The ID of the error file containing failed requests.
94 pub error_file_id: Option<String>,
95
96 /// The Unix timestamp when the batch was created.
97 pub created_at: i64,
98
99 /// The Unix timestamp when processing started.
100 pub in_progress_at: Option<i64>,
101
102 /// The Unix timestamp when the batch expires.
103 pub expires_at: Option<i64>,
104
105 /// The Unix timestamp when finalization started.
106 pub finalizing_at: Option<i64>,
107
108 /// The Unix timestamp when the batch completed.
109 pub completed_at: Option<i64>,
110
111 /// The Unix timestamp when the batch failed.
112 pub failed_at: Option<i64>,
113
114 /// The Unix timestamp when the batch expired.
115 pub expired_at: Option<i64>,
116
117 /// The Unix timestamp when cancellation started.
118 pub cancelling_at: Option<i64>,
119
120 /// The Unix timestamp when the batch was cancelled.
121 pub cancelled_at: Option<i64>,
122
123 /// Counts of requests in different states.
124 pub request_counts: Option<RequestCounts>,
125
126 /// User-defined metadata attached to the batch.
127 pub metadata: Option<HashMap<String, String>>,
128}
129
130/// Response for listing batch jobs.
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct BatchListResponse {
133 /// The object type (always "list").
134 pub object: String,
135
136 /// The list of batch objects.
137 pub data: Vec<BatchObject>,
138
139 /// The ID of the first batch in the list.
140 pub first_id: Option<String>,
141
142 /// The ID of the last batch in the list.
143 pub last_id: Option<String>,
144
145 /// Whether there are more batches to retrieve.
146 pub has_more: bool,
147}