python/resources/files/methods/retrieve/index.md +0 −131 deleted
File Deleted View Diff
1## Retrieve file
2
3`files.retrieve(strfile_id) -> FileObject`
4
5**get** `/files/{file_id}`
6
7Returns information about a specific file.
8
9### Parameters
10
11- `file_id: str`
12
13### Returns
14
15- `class FileObject: …`
16
17 The `File` object represents a document that has been uploaded to OpenAI.
18
19 - `id: str`
20
21 The file identifier, which can be referenced in the API endpoints.
22
23 - `bytes: int`
24
25 The size of the file, in bytes.
26
27 - `created_at: int`
28
29 The Unix timestamp (in seconds) for when the file was created.
30
31 - `filename: str`
32
33 The name of the file.
34
35 - `object: Literal["file"]`
36
37 The object type, which is always `file`.
38
39 - `"file"`
40
41 - `purpose: Literal["assistants", "assistants_output", "batch", 5 more]`
42
43 The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
44
45 - `"assistants"`
46
47 - `"assistants_output"`
48
49 - `"batch"`
50
51 - `"batch_output"`
52
53 - `"fine-tune"`
54
55 - `"fine-tune-results"`
56
57 - `"vision"`
58
59 - `"user_data"`
60
61 - `status: Literal["uploaded", "processed", "error"]`
62
63 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
64
65 - `"uploaded"`
66
67 - `"processed"`
68
69 - `"error"`
70
71 - `expires_at: Optional[int]`
72
73 The Unix timestamp (in seconds) for when the file will expire.
74
75 - `status_details: Optional[str]`
76
77 Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
78
79### Example
80
81```python
82import os
83from openai import OpenAI
84
85client = OpenAI(
86 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
87)
88file_object = client.files.retrieve(
89 "file_id",
90)
91print(file_object.id)
92```
93
94#### Response
95
96```json
97{
98 "id": "id",
99 "bytes": 0,
100 "created_at": 0,
101 "filename": "filename",
102 "object": "file",
103 "purpose": "assistants",
104 "status": "uploaded",
105 "expires_at": 0,
106 "status_details": "status_details"
107}
108```
109
110### Example
111
112```python
113from openai import OpenAI
114client = OpenAI()
115
116client.files.retrieve("file-abc123")
117```
118
119#### Response
120
121```json
122{
123 "id": "file-abc123",
124 "object": "file",
125 "bytes": 120000,
126 "created_at": 1677610602,
127 "expires_at": 1677614202,
128 "filename": "mydata.jsonl",
129 "purpose": "fine-tune",
130}
131```