python/resources/containers/subresources/files/index.md +0 −435 deleted
File Deleted View Diff
1# Files
2
3## List container files
4
5`containers.files.list(strcontainer_id, FileListParams**kwargs) -> SyncCursorPage[FileListResponse]`
6
7**get** `/containers/{container_id}/files`
8
9List Container files
10
11### Parameters
12
13- `container_id: str`
14
15- `after: Optional[str]`
16
17 A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
18
19- `limit: Optional[int]`
20
21 A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
22
23- `order: Optional[Literal["asc", "desc"]]`
24
25 Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order.
26
27 - `"asc"`
28
29 - `"desc"`
30
31### Returns
32
33- `class FileListResponse: …`
34
35 - `id: str`
36
37 Unique identifier for the file.
38
39 - `bytes: int`
40
41 Size of the file in bytes.
42
43 - `container_id: str`
44
45 The container this file belongs to.
46
47 - `created_at: int`
48
49 Unix timestamp (in seconds) when the file was created.
50
51 - `object: Literal["container.file"]`
52
53 The type of this object (`container.file`).
54
55 - `"container.file"`
56
57 - `path: str`
58
59 Path of the file in the container.
60
61 - `source: str`
62
63 Source of the file (e.g., `user`, `assistant`).
64
65### Example
66
67```python
68import os
69from openai import OpenAI
70
71client = OpenAI(
72 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
73)
74page = client.containers.files.list(
75 container_id="container_id",
76)
77page = page.data[0]
78print(page.id)
79```
80
81#### Response
82
83```json
84{
85 "data": [
86 {
87 "id": "id",
88 "bytes": 0,
89 "container_id": "container_id",
90 "created_at": 0,
91 "object": "container.file",
92 "path": "path",
93 "source": "source"
94 }
95 ],
96 "first_id": "first_id",
97 "has_more": true,
98 "last_id": "last_id",
99 "object": "list"
100}
101```
102
103## Create container file
104
105`containers.files.create(strcontainer_id, FileCreateParams**kwargs) -> FileCreateResponse`
106
107**post** `/containers/{container_id}/files`
108
109Create a Container File
110
111You can send either a multipart/form-data request with the raw file content, or a JSON request with a file ID.
112
113### Parameters
114
115- `container_id: str`
116
117- `file: Optional[FileTypes]`
118
119 The File object (not file name) to be uploaded.
120
121- `file_id: Optional[str]`
122
123 Name of the file to create.
124
125### Returns
126
127- `class FileCreateResponse: …`
128
129 - `id: str`
130
131 Unique identifier for the file.
132
133 - `bytes: int`
134
135 Size of the file in bytes.
136
137 - `container_id: str`
138
139 The container this file belongs to.
140
141 - `created_at: int`
142
143 Unix timestamp (in seconds) when the file was created.
144
145 - `object: Literal["container.file"]`
146
147 The type of this object (`container.file`).
148
149 - `"container.file"`
150
151 - `path: str`
152
153 Path of the file in the container.
154
155 - `source: str`
156
157 Source of the file (e.g., `user`, `assistant`).
158
159### Example
160
161```python
162import os
163from openai import OpenAI
164
165client = OpenAI(
166 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
167)
168file = client.containers.files.create(
169 container_id="container_id",
170)
171print(file.id)
172```
173
174#### Response
175
176```json
177{
178 "id": "id",
179 "bytes": 0,
180 "container_id": "container_id",
181 "created_at": 0,
182 "object": "container.file",
183 "path": "path",
184 "source": "source"
185}
186```
187
188## Retrieve container file
189
190`containers.files.retrieve(strfile_id, FileRetrieveParams**kwargs) -> FileRetrieveResponse`
191
192**get** `/containers/{container_id}/files/{file_id}`
193
194Retrieve Container File
195
196### Parameters
197
198- `container_id: str`
199
200- `file_id: str`
201
202### Returns
203
204- `class FileRetrieveResponse: …`
205
206 - `id: str`
207
208 Unique identifier for the file.
209
210 - `bytes: int`
211
212 Size of the file in bytes.
213
214 - `container_id: str`
215
216 The container this file belongs to.
217
218 - `created_at: int`
219
220 Unix timestamp (in seconds) when the file was created.
221
222 - `object: Literal["container.file"]`
223
224 The type of this object (`container.file`).
225
226 - `"container.file"`
227
228 - `path: str`
229
230 Path of the file in the container.
231
232 - `source: str`
233
234 Source of the file (e.g., `user`, `assistant`).
235
236### Example
237
238```python
239import os
240from openai import OpenAI
241
242client = OpenAI(
243 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
244)
245file = client.containers.files.retrieve(
246 file_id="file_id",
247 container_id="container_id",
248)
249print(file.id)
250```
251
252#### Response
253
254```json
255{
256 "id": "id",
257 "bytes": 0,
258 "container_id": "container_id",
259 "created_at": 0,
260 "object": "container.file",
261 "path": "path",
262 "source": "source"
263}
264```
265
266## Delete a container file
267
268`containers.files.delete(strfile_id, FileDeleteParams**kwargs)`
269
270**delete** `/containers/{container_id}/files/{file_id}`
271
272Delete Container File
273
274### Parameters
275
276- `container_id: str`
277
278- `file_id: str`
279
280### Example
281
282```python
283import os
284from openai import OpenAI
285
286client = OpenAI(
287 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
288)
289client.containers.files.delete(
290 file_id="file_id",
291 container_id="container_id",
292)
293```
294
295## Domain Types
296
297### File List Response
298
299- `class FileListResponse: …`
300
301 - `id: str`
302
303 Unique identifier for the file.
304
305 - `bytes: int`
306
307 Size of the file in bytes.
308
309 - `container_id: str`
310
311 The container this file belongs to.
312
313 - `created_at: int`
314
315 Unix timestamp (in seconds) when the file was created.
316
317 - `object: Literal["container.file"]`
318
319 The type of this object (`container.file`).
320
321 - `"container.file"`
322
323 - `path: str`
324
325 Path of the file in the container.
326
327 - `source: str`
328
329 Source of the file (e.g., `user`, `assistant`).
330
331### File Create Response
332
333- `class FileCreateResponse: …`
334
335 - `id: str`
336
337 Unique identifier for the file.
338
339 - `bytes: int`
340
341 Size of the file in bytes.
342
343 - `container_id: str`
344
345 The container this file belongs to.
346
347 - `created_at: int`
348
349 Unix timestamp (in seconds) when the file was created.
350
351 - `object: Literal["container.file"]`
352
353 The type of this object (`container.file`).
354
355 - `"container.file"`
356
357 - `path: str`
358
359 Path of the file in the container.
360
361 - `source: str`
362
363 Source of the file (e.g., `user`, `assistant`).
364
365### File Retrieve Response
366
367- `class FileRetrieveResponse: …`
368
369 - `id: str`
370
371 Unique identifier for the file.
372
373 - `bytes: int`
374
375 Size of the file in bytes.
376
377 - `container_id: str`
378
379 The container this file belongs to.
380
381 - `created_at: int`
382
383 Unix timestamp (in seconds) when the file was created.
384
385 - `object: Literal["container.file"]`
386
387 The type of this object (`container.file`).
388
389 - `"container.file"`
390
391 - `path: str`
392
393 Path of the file in the container.
394
395 - `source: str`
396
397 Source of the file (e.g., `user`, `assistant`).
398
399# Content
400
401## Retrieve container file content
402
403`containers.files.content.retrieve(strfile_id, ContentRetrieveParams**kwargs) -> BinaryResponseContent`
404
405**get** `/containers/{container_id}/files/{file_id}/content`
406
407Retrieve Container File Content
408
409### Parameters
410
411- `container_id: str`
412
413- `file_id: str`
414
415### Returns
416
417- `BinaryResponseContent`
418
419### Example
420
421```python
422import os
423from openai import OpenAI
424
425client = OpenAI(
426 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
427)
428content = client.containers.files.content.retrieve(
429 file_id="file_id",
430 container_id="container_id",
431)
432print(content)
433data = content.read()
434print(data)
435```