python/resources/uploads/methods/create/index.md +0 −231 deleted
File Deleted View Diff
1## Create upload
2
3`uploads.create(UploadCreateParams**kwargs) -> Upload`
4
5**post** `/uploads`
6
7Creates an intermediate [Upload](https://platform.openai.com/docs/api-reference/uploads/object) object
8that you can add [Parts](https://platform.openai.com/docs/api-reference/uploads/part-object) to.
9Currently, an Upload can accept at most 8 GB in total and expires after an
10hour after you create it.
11
12Once you complete the Upload, we will create a
13[File](https://platform.openai.com/docs/api-reference/files/object) object that contains all the parts
14you uploaded. This File is usable in the rest of our platform as a regular
15File object.
16
17For certain `purpose` values, the correct `mime_type` must be specified.
18Please refer to documentation for the
19[supported MIME types for your use case](https://platform.openai.com/docs/assistants/tools/file-search#supported-files).
20
21For guidance on the proper filename extensions for each purpose, please
22follow the documentation on [creating a
23File](https://platform.openai.com/docs/api-reference/files/create).
24
25Returns the Upload object with status `pending`.
26
27### Parameters
28
29- `bytes: int`
30
31 The number of bytes in the file you are uploading.
32
33- `filename: str`
34
35 The name of the file to upload.
36
37- `mime_type: str`
38
39 The MIME type of the file.
40
41 This must fall within the supported MIME types for your file purpose. See
42 the supported MIME types for assistants and vision.
43
44- `purpose: FilePurpose`
45
46 The intended purpose of the uploaded file.
47
48 See the [documentation on File
49 purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
50
51 - `"assistants"`
52
53 - `"batch"`
54
55 - `"fine-tune"`
56
57 - `"vision"`
58
59 - `"user_data"`
60
61 - `"evals"`
62
63- `expires_after: Optional[ExpiresAfter]`
64
65 The expiration policy for a file. By default, files with `purpose=batch` expire after 30 days and all other files are persisted until they are manually deleted.
66
67 - `anchor: Literal["created_at"]`
68
69 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
70
71 - `"created_at"`
72
73 - `seconds: int`
74
75 The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
76
77### Returns
78
79- `class Upload: …`
80
81 The Upload object can accept byte chunks in the form of Parts.
82
83 - `id: str`
84
85 The Upload unique identifier, which can be referenced in API endpoints.
86
87 - `bytes: int`
88
89 The intended number of bytes to be uploaded.
90
91 - `created_at: int`
92
93 The Unix timestamp (in seconds) for when the Upload was created.
94
95 - `expires_at: int`
96
97 The Unix timestamp (in seconds) for when the Upload will expire.
98
99 - `filename: str`
100
101 The name of the file to be uploaded.
102
103 - `object: Literal["upload"]`
104
105 The object type, which is always "upload".
106
107 - `"upload"`
108
109 - `purpose: str`
110
111 The intended purpose of the file. [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose) for acceptable values.
112
113 - `status: Literal["pending", "completed", "cancelled", "expired"]`
114
115 The status of the Upload.
116
117 - `"pending"`
118
119 - `"completed"`
120
121 - `"cancelled"`
122
123 - `"expired"`
124
125 - `file: Optional[FileObject]`
126
127 The `File` object represents a document that has been uploaded to OpenAI.
128
129 - `id: str`
130
131 The file identifier, which can be referenced in the API endpoints.
132
133 - `bytes: int`
134
135 The size of the file, in bytes.
136
137 - `created_at: int`
138
139 The Unix timestamp (in seconds) for when the file was created.
140
141 - `filename: str`
142
143 The name of the file.
144
145 - `object: Literal["file"]`
146
147 The object type, which is always `file`.
148
149 - `"file"`
150
151 - `purpose: Literal["assistants", "assistants_output", "batch", 5 more]`
152
153 The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
154
155 - `"assistants"`
156
157 - `"assistants_output"`
158
159 - `"batch"`
160
161 - `"batch_output"`
162
163 - `"fine-tune"`
164
165 - `"fine-tune-results"`
166
167 - `"vision"`
168
169 - `"user_data"`
170
171 - `status: Literal["uploaded", "processed", "error"]`
172
173 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
174
175 - `"uploaded"`
176
177 - `"processed"`
178
179 - `"error"`
180
181 - `expires_at: Optional[int]`
182
183 The Unix timestamp (in seconds) for when the file will expire.
184
185 - `status_details: Optional[str]`
186
187 Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
188
189### Example
190
191```python
192import os
193from openai import OpenAI
194
195client = OpenAI(
196 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
197)
198upload = client.uploads.create(
199 bytes=0,
200 filename="filename",
201 mime_type="mime_type",
202 purpose="assistants",
203)
204print(upload.id)
205```
206
207#### Response
208
209```json
210{
211 "id": "id",
212 "bytes": 0,
213 "created_at": 0,
214 "expires_at": 0,
215 "filename": "filename",
216 "object": "upload",
217 "purpose": "purpose",
218 "status": "pending",
219 "file": {
220 "id": "id",
221 "bytes": 0,
222 "created_at": 0,
223 "filename": "filename",
224 "object": "file",
225 "purpose": "assistants",
226 "status": "uploaded",
227 "expires_at": 0,
228 "status_details": "status_details"
229 }
230}
231```