ruby/resources/files/methods/create/index.md +0 −168 deleted
File Deleted View Diff
1## Upload file
2
3`files.create(**kwargs) -> FileObject`
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- `file: String`
36
37 The File object (not file name) to be uploaded.
38
39- `purpose: FilePurpose`
40
41 The intended purpose of the uploaded file. One of:
42
43 - `assistants`: Used in the Assistants API
44 - `batch`: Used in the Batch API
45 - `fine-tune`: Used for fine-tuning
46 - `vision`: Images used for vision fine-tuning
47 - `user_data`: Flexible file type for any purpose
48 - `evals`: Used for eval data sets
49
50 - `:assistants`
51
52 - `:batch`
53
54 - `:"fine-tune"`
55
56 - `:vision`
57
58 - `:user_data`
59
60 - `:evals`
61
62- `expires_after: ExpiresAfter{ anchor, seconds}`
63
64 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.
65
66 - `anchor: :created_at`
67
68 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
69
70 - `:created_at`
71
72 - `seconds: Integer`
73
74 The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).
75
76### Returns
77
78- `class FileObject`
79
80 The `File` object represents a document that has been uploaded to OpenAI.
81
82 - `id: String`
83
84 The file identifier, which can be referenced in the API endpoints.
85
86 - `bytes: Integer`
87
88 The size of the file, in bytes.
89
90 - `created_at: Integer`
91
92 The Unix timestamp (in seconds) for when the file was created.
93
94 - `filename: String`
95
96 The name of the file.
97
98 - `object: :file`
99
100 The object type, which is always `file`.
101
102 - `:file`
103
104 - `purpose: :assistants | :assistants_output | :batch | 5 more`
105
106 The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.
107
108 - `:assistants`
109
110 - `:assistants_output`
111
112 - `:batch`
113
114 - `:batch_output`
115
116 - `:"fine-tune"`
117
118 - `:"fine-tune-results"`
119
120 - `:vision`
121
122 - `:user_data`
123
124 - `status: :uploaded | :processed | :error`
125
126 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
127
128 - `:uploaded`
129
130 - `:processed`
131
132 - `:error`
133
134 - `expires_at: Integer`
135
136 The Unix timestamp (in seconds) for when the file will expire.
137
138 - `status_details: String`
139
140 Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.
141
142### Example
143
144```ruby
145require "openai"
146
147openai = OpenAI::Client.new(api_key: "My API Key")
148
149file_object = openai.files.create(file: StringIO.new("Example data"), purpose: :assistants)
150
151puts(file_object)
152```
153
154#### Response
155
156```json
157{
158 "id": "id",
159 "bytes": 0,
160 "created_at": 0,
161 "filename": "filename",
162 "object": "file",
163 "purpose": "assistants",
164 "status": "uploaded",
165 "expires_at": 0,
166 "status_details": "status_details"
167}
168```