python/resources/batches/methods/retrieve/index.md +0 −303 deleted
File Deleted View Diff
1## Retrieve batch
2
3`batches.retrieve(strbatch_id) -> Batch`
4
5**get** `/batches/{batch_id}`
6
7Retrieves a batch.
8
9### Parameters
10
11- `batch_id: str`
12
13### Returns
14
15- `class Batch: …`
16
17 - `id: str`
18
19 - `completion_window: str`
20
21 The time frame within which the batch should be processed.
22
23 - `created_at: int`
24
25 The Unix timestamp (in seconds) for when the batch was created.
26
27 - `endpoint: str`
28
29 The OpenAI API endpoint used by the batch.
30
31 - `input_file_id: str`
32
33 The ID of the input file for the batch.
34
35 - `object: Literal["batch"]`
36
37 The object type, which is always `batch`.
38
39 - `"batch"`
40
41 - `status: Literal["validating", "failed", "in_progress", 5 more]`
42
43 The current status of the batch.
44
45 - `"validating"`
46
47 - `"failed"`
48
49 - `"in_progress"`
50
51 - `"finalizing"`
52
53 - `"completed"`
54
55 - `"expired"`
56
57 - `"cancelling"`
58
59 - `"cancelled"`
60
61 - `cancelled_at: Optional[int]`
62
63 The Unix timestamp (in seconds) for when the batch was cancelled.
64
65 - `cancelling_at: Optional[int]`
66
67 The Unix timestamp (in seconds) for when the batch started cancelling.
68
69 - `completed_at: Optional[int]`
70
71 The Unix timestamp (in seconds) for when the batch was completed.
72
73 - `error_file_id: Optional[str]`
74
75 The ID of the file containing the outputs of requests with errors.
76
77 - `errors: Optional[Errors]`
78
79 - `data: Optional[List[BatchError]]`
80
81 - `code: Optional[str]`
82
83 An error code identifying the error type.
84
85 - `line: Optional[int]`
86
87 The line number of the input file where the error occurred, if applicable.
88
89 - `message: Optional[str]`
90
91 A human-readable message providing more details about the error.
92
93 - `param: Optional[str]`
94
95 The name of the parameter that caused the error, if applicable.
96
97 - `object: Optional[str]`
98
99 The object type, which is always `list`.
100
101 - `expired_at: Optional[int]`
102
103 The Unix timestamp (in seconds) for when the batch expired.
104
105 - `expires_at: Optional[int]`
106
107 The Unix timestamp (in seconds) for when the batch will expire.
108
109 - `failed_at: Optional[int]`
110
111 The Unix timestamp (in seconds) for when the batch failed.
112
113 - `finalizing_at: Optional[int]`
114
115 The Unix timestamp (in seconds) for when the batch started finalizing.
116
117 - `in_progress_at: Optional[int]`
118
119 The Unix timestamp (in seconds) for when the batch started processing.
120
121 - `metadata: Optional[Metadata]`
122
123 Set of 16 key-value pairs that can be attached to an object. This can be
124 useful for storing additional information about the object in a structured
125 format, and querying for objects via API or the dashboard.
126
127 Keys are strings with a maximum length of 64 characters. Values are strings
128 with a maximum length of 512 characters.
129
130 - `model: Optional[str]`
131
132 Model ID used to process the batch, like `gpt-5-2025-08-07`. OpenAI
133 offers a wide range of models with different capabilities, performance
134 characteristics, and price points. Refer to the [model
135 guide](https://platform.openai.com/docs/models) to browse and compare available models.
136
137 - `output_file_id: Optional[str]`
138
139 The ID of the file containing the outputs of successfully executed requests.
140
141 - `request_counts: Optional[BatchRequestCounts]`
142
143 The request counts for different statuses within the batch.
144
145 - `completed: int`
146
147 Number of requests that have been completed successfully.
148
149 - `failed: int`
150
151 Number of requests that have failed.
152
153 - `total: int`
154
155 Total number of requests in the batch.
156
157 - `usage: Optional[BatchUsage]`
158
159 Represents token usage details including input tokens, output tokens, a
160 breakdown of output tokens, and the total tokens used. Only populated on
161 batches created after September 7, 2025.
162
163 - `input_tokens: int`
164
165 The number of input tokens.
166
167 - `input_tokens_details: InputTokensDetails`
168
169 A detailed breakdown of the input tokens.
170
171 - `cached_tokens: int`
172
173 The number of tokens that were retrieved from the cache. [More on
174 prompt caching](https://platform.openai.com/docs/guides/prompt-caching).
175
176 - `output_tokens: int`
177
178 The number of output tokens.
179
180 - `output_tokens_details: OutputTokensDetails`
181
182 A detailed breakdown of the output tokens.
183
184 - `reasoning_tokens: int`
185
186 The number of reasoning tokens.
187
188 - `total_tokens: int`
189
190 The total number of tokens used.
191
192### Example
193
194```python
195import os
196from openai import OpenAI
197
198client = OpenAI(
199 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
200)
201batch = client.batches.retrieve(
202 "batch_id",
203)
204print(batch.id)
205```
206
207#### Response
208
209```json
210{
211 "id": "id",
212 "completion_window": "completion_window",
213 "created_at": 0,
214 "endpoint": "endpoint",
215 "input_file_id": "input_file_id",
216 "object": "batch",
217 "status": "validating",
218 "cancelled_at": 0,
219 "cancelling_at": 0,
220 "completed_at": 0,
221 "error_file_id": "error_file_id",
222 "errors": {
223 "data": [
224 {
225 "code": "code",
226 "line": 0,
227 "message": "message",
228 "param": "param"
229 }
230 ],
231 "object": "object"
232 },
233 "expired_at": 0,
234 "expires_at": 0,
235 "failed_at": 0,
236 "finalizing_at": 0,
237 "in_progress_at": 0,
238 "metadata": {
239 "foo": "string"
240 },
241 "model": "model",
242 "output_file_id": "output_file_id",
243 "request_counts": {
244 "completed": 0,
245 "failed": 0,
246 "total": 0
247 },
248 "usage": {
249 "input_tokens": 0,
250 "input_tokens_details": {
251 "cached_tokens": 0
252 },
253 "output_tokens": 0,
254 "output_tokens_details": {
255 "reasoning_tokens": 0
256 },
257 "total_tokens": 0
258 }
259}
260```
261
262### Example
263
264```python
265from openai import OpenAI
266client = OpenAI()
267
268client.batches.retrieve("batch_abc123")
269```
270
271#### Response
272
273```json
274{
275 "id": "batch_abc123",
276 "object": "batch",
277 "endpoint": "/v1/completions",
278 "errors": null,
279 "input_file_id": "file-abc123",
280 "completion_window": "24h",
281 "status": "completed",
282 "output_file_id": "file-cvaTdG",
283 "error_file_id": "file-HOWS94",
284 "created_at": 1711471533,
285 "in_progress_at": 1711471538,
286 "expires_at": 1711557933,
287 "finalizing_at": 1711493133,
288 "completed_at": 1711493163,
289 "failed_at": null,
290 "expired_at": null,
291 "cancelling_at": null,
292 "cancelled_at": null,
293 "request_counts": {
294 "total": 100,
295 "completed": 95,
296 "failed": 5
297 },
298 "metadata": {
299 "customer_id": "user_123456789",
300 "batch_description": "Nightly eval job",
301 }
302}
303```