go/resources/files/methods/create/index.md +0 −176 deleted
File Deleted View Diff
1## Upload file
2
3`client.Files.New(ctx, body) (*FileObject, error)`
4
5**post** `/files`
6
7Upload a file that can be used across various endpoints. Individual files
8can be up to 512 MB, and each project can store up to 2.5 TB of files in
9total. There is no organization-wide storage limit. Uploads to this
10endpoint are rate-limited to 1,000 requests per minute per authenticated
11user.
12
13- The Assistants API supports files up to 2 million tokens and of specific
14 file types. See the [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) for
15 details.
16- The Fine-tuning API only supports `.jsonl` files. The input also has
17 certain required formats for fine-tuning
18 [chat](https://platform.openai.com/docs/api-reference/fine-tuning/chat-input) or
19 [completions](https://platform.openai.com/docs/api-reference/fine-tuning/completions-input) models.
20- The Batch API only supports `.jsonl` files up to 200 MB in size. The input
21 also has a specific required
22 [format](https://platform.openai.com/docs/api-reference/batch/request-input).
23- For Retrieval or `file_search` ingestion, upload files here first. If
24 you need to attach multiple uploaded files to the same vector store, use
25 [`/vector_stores/{vector_store_id}/file_batches`](https://platform.openai.com/docs/api-reference/vector-stores-file-batches/createBatch)
26 instead of attaching them one by one. Vector store attachment has separate
27 limits from file upload, including 2,000 attached files per minute per
28 organization.
29
30Please [contact us](https://help.openai.com/) if you need to increase these
31storage limits.
32
33### Parameters
34
35- `body FileNewParams`
36
37 - `File param.Field[Reader]`
38
39 The File object (not file name) to be uploaded.
40
41 - `Purpose param.Field[FilePurpose]`
42
43 The intended purpose of the uploaded file. One of:
44
45 - `assistants`: Used in the Assistants API
46 - `batch`: Used in the Batch API
47 - `fine-tune`: Used for fine-tuning
48 - `vision`: Images used for vision fine-tuning
49 - `user_data`: Flexible file type for any purpose
50 - `evals`: Used for eval data sets
51
52 - `ExpiresAfter param.Field[FileNewParamsExpiresAfter]`
53
54 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.
55
56 - `Anchor CreatedAt`
57
58 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
59
60 - `const CreatedAtCreatedAt CreatedAt = "created_at"`
61
62 - `Seconds int64`
63
64 The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
65
66### Returns
67
68- `type FileObject struct{…}`
69
70 The `File` object represents a document that has been uploaded to OpenAI.
71
72 - `ID string`
73
74 The file identifier, which can be referenced in the API endpoints.
75
76 - `Bytes int64`
77
78 The size of the file, in bytes.
79
80 - `CreatedAt int64`
81
82 The Unix timestamp (in seconds) for when the file was created.
83
84 - `Filename string`
85
86 The name of the file.
87
88 - `Object File`
89
90 The object type, which is always `file`.
91
92 - `const FileFile File = "file"`
93
94 - `Purpose FileObjectPurpose`
95
96 The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
97
98 - `const FileObjectPurposeAssistants FileObjectPurpose = "assistants"`
99
100 - `const FileObjectPurposeAssistantsOutput FileObjectPurpose = "assistants_output"`
101
102 - `const FileObjectPurposeBatch FileObjectPurpose = "batch"`
103
104 - `const FileObjectPurposeBatchOutput FileObjectPurpose = "batch_output"`
105
106 - `const FileObjectPurposeFineTune FileObjectPurpose = "fine-tune"`
107
108 - `const FileObjectPurposeFineTuneResults FileObjectPurpose = "fine-tune-results"`
109
110 - `const FileObjectPurposeVision FileObjectPurpose = "vision"`
111
112 - `const FileObjectPurposeUserData FileObjectPurpose = "user_data"`
113
114 - `Status FileObjectStatus`
115
116 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
117
118 - `const FileObjectStatusUploaded FileObjectStatus = "uploaded"`
119
120 - `const FileObjectStatusProcessed FileObjectStatus = "processed"`
121
122 - `const FileObjectStatusError FileObjectStatus = "error"`
123
124 - `ExpiresAt int64`
125
126 The Unix timestamp (in seconds) for when the file will expire.
127
128 - `StatusDetails string`
129
130 Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
131
132### Example
133
134```go
135package main
136
137import (
138 "bytes"
139 "context"
140 "fmt"
141 "io"
142
143 "github.com/openai/openai-go"
144 "github.com/openai/openai-go/option"
145)
146
147func main() {
148 client := openai.NewClient(
149 option.WithAPIKey("My API Key"),
150 )
151 fileObject, err := client.Files.New(context.TODO(), openai.FileNewParams{
152 File: io.Reader(bytes.NewBuffer([]byte("Example data"))),
153 Purpose: openai.FilePurposeAssistants,
154 })
155 if err != nil {
156 panic(err.Error())
157 }
158 fmt.Printf("%+v\n", fileObject.ID)
159}
160```
161
162#### Response
163
164```json
165{
166 "id": "id",
167 "bytes": 0,
168 "created_at": 0,
169 "filename": "filename",
170 "object": "file",
171 "purpose": "assistants",
172 "status": "uploaded",
173 "expires_at": 0,
174 "status_details": "status_details"
175}
176```