go/resources/uploads/methods/create/index.md +0 −233 deleted
File Deleted View Diff
1## Create upload
2
3`client.Uploads.New(ctx, body) (*Upload, error)`
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- `body UploadNewParams`
30
31 - `Bytes param.Field[int64]`
32
33 The number of bytes in the file you are uploading.
34
35 - `Filename param.Field[string]`
36
37 The name of the file to upload.
38
39 - `MimeType param.Field[string]`
40
41 The MIME type of the file.
42
43 This must fall within the supported MIME types for your file purpose. See
44 the supported MIME types for assistants and vision.
45
46 - `Purpose param.Field[FilePurpose]`
47
48 The intended purpose of the uploaded file.
49
50 See the [documentation on File
51 purposes](https://platform.openai.com/docs/api-reference/files/create#files-create-purpose).
52
53 - `ExpiresAfter param.Field[UploadNewParamsExpiresAfter]`
54
55 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.
56
57 - `Anchor CreatedAt`
58
59 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
60
61 - `const CreatedAtCreatedAt CreatedAt = "created_at"`
62
63 - `Seconds int64`
64
65 The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
66
67### Returns
68
69- `type Upload struct{…}`
70
71 The Upload object can accept byte chunks in the form of Parts.
72
73 - `ID string`
74
75 The Upload unique identifier, which can be referenced in API endpoints.
76
77 - `Bytes int64`
78
79 The intended number of bytes to be uploaded.
80
81 - `CreatedAt int64`
82
83 The Unix timestamp (in seconds) for when the Upload was created.
84
85 - `ExpiresAt int64`
86
87 The Unix timestamp (in seconds) for when the Upload will expire.
88
89 - `Filename string`
90
91 The name of the file to be uploaded.
92
93 - `Object Upload`
94
95 The object type, which is always "upload".
96
97 - `const UploadUpload Upload = "upload"`
98
99 - `Purpose string`
100
101 The intended purpose of the file. [Please refer here](https://platform.openai.com/docs/api-reference/files/object#files/object-purpose) for acceptable values.
102
103 - `Status UploadStatus`
104
105 The status of the Upload.
106
107 - `const UploadStatusPending UploadStatus = "pending"`
108
109 - `const UploadStatusCompleted UploadStatus = "completed"`
110
111 - `const UploadStatusCancelled UploadStatus = "cancelled"`
112
113 - `const UploadStatusExpired UploadStatus = "expired"`
114
115 - `File FileObject`
116
117 The `File` object represents a document that has been uploaded to OpenAI.
118
119 - `ID string`
120
121 The file identifier, which can be referenced in the API endpoints.
122
123 - `Bytes int64`
124
125 The size of the file, in bytes.
126
127 - `CreatedAt int64`
128
129 The Unix timestamp (in seconds) for when the file was created.
130
131 - `Filename string`
132
133 The name of the file.
134
135 - `Object File`
136
137 The object type, which is always `file`.
138
139 - `const FileFile File = "file"`
140
141 - `Purpose FileObjectPurpose`
142
143 The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
144
145 - `const FileObjectPurposeAssistants FileObjectPurpose = "assistants"`
146
147 - `const FileObjectPurposeAssistantsOutput FileObjectPurpose = "assistants_output"`
148
149 - `const FileObjectPurposeBatch FileObjectPurpose = "batch"`
150
151 - `const FileObjectPurposeBatchOutput FileObjectPurpose = "batch_output"`
152
153 - `const FileObjectPurposeFineTune FileObjectPurpose = "fine-tune"`
154
155 - `const FileObjectPurposeFineTuneResults FileObjectPurpose = "fine-tune-results"`
156
157 - `const FileObjectPurposeVision FileObjectPurpose = "vision"`
158
159 - `const FileObjectPurposeUserData FileObjectPurpose = "user_data"`
160
161 - `Status FileObjectStatus`
162
163 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
164
165 - `const FileObjectStatusUploaded FileObjectStatus = "uploaded"`
166
167 - `const FileObjectStatusProcessed FileObjectStatus = "processed"`
168
169 - `const FileObjectStatusError FileObjectStatus = "error"`
170
171 - `ExpiresAt int64`
172
173 The Unix timestamp (in seconds) for when the file will expire.
174
175 - `StatusDetails string`
176
177 Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
178
179### Example
180
181```go
182package main
183
184import (
185 "context"
186 "fmt"
187
188 "github.com/openai/openai-go"
189 "github.com/openai/openai-go/option"
190)
191
192func main() {
193 client := openai.NewClient(
194 option.WithAPIKey("My API Key"),
195 )
196 upload, err := client.Uploads.New(context.TODO(), openai.UploadNewParams{
197 Bytes: 0,
198 Filename: "filename",
199 MimeType: "mime_type",
200 Purpose: openai.FilePurposeAssistants,
201 })
202 if err != nil {
203 panic(err.Error())
204 }
205 fmt.Printf("%+v\n", upload.ID)
206}
207```
208
209#### Response
210
211```json
212{
213 "id": "id",
214 "bytes": 0,
215 "created_at": 0,
216 "expires_at": 0,
217 "filename": "filename",
218 "object": "upload",
219 "purpose": "purpose",
220 "status": "pending",
221 "file": {
222 "id": "id",
223 "bytes": 0,
224 "created_at": 0,
225 "filename": "filename",
226 "object": "file",
227 "purpose": "assistants",
228 "status": "uploaded",
229 "expires_at": 0,
230 "status_details": "status_details"
231 }
232}
233```