java/resources/files/methods/create/index.md +0 −173 deleted
File Deleted View Diff
1## Upload file
2
3`FileObject files().create(FileCreateParamsparams, RequestOptionsrequestOptions = RequestOptions.none())`
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- `FileCreateParams params`
36
37 - `String file`
38
39 The File object (not file name) to be uploaded.
40
41 - `FilePurpose purpose`
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 - `Optional<ExpiresAfter> expiresAfter`
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 - `JsonValue; anchor "created_at"constant`
57
58 Anchor timestamp after which the expiration policy applies. Supported anchors: `created_at`.
59
60 - `CREATED_AT("created_at")`
61
62 - `long seconds`
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- `class FileObject:`
69
70 The `File` object represents a document that has been uploaded to OpenAI.
71
72 - `String id`
73
74 The file identifier, which can be referenced in the API endpoints.
75
76 - `long bytes`
77
78 The size of the file, in bytes.
79
80 - `long createdAt`
81
82 The Unix timestamp (in seconds) for when the file was created.
83
84 - `String filename`
85
86 The name of the file.
87
88 - `JsonValue; object_ "file"constant`
89
90 The object type, which is always `file`.
91
92 - `FILE("file")`
93
94 - `Purpose purpose`
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 - `ASSISTANTS("assistants")`
99
100 - `ASSISTANTS_OUTPUT("assistants_output")`
101
102 - `BATCH("batch")`
103
104 - `BATCH_OUTPUT("batch_output")`
105
106 - `FINE_TUNE("fine-tune")`
107
108 - `FINE_TUNE_RESULTS("fine-tune-results")`
109
110 - `VISION("vision")`
111
112 - `USER_DATA("user_data")`
113
114 - `Status status`
115
116 Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.
117
118 - `UPLOADED("uploaded")`
119
120 - `PROCESSED("processed")`
121
122 - `ERROR("error")`
123
124 - `Optional<Long> expiresAt`
125
126 The Unix timestamp (in seconds) for when the file will expire.
127
128 - `Optional<String> statusDetails`
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```java
135package com.openai.example;
136
137import com.openai.client.OpenAIClient;
138import com.openai.client.okhttp.OpenAIOkHttpClient;
139import com.openai.models.files.FileCreateParams;
140import com.openai.models.files.FileObject;
141import com.openai.models.files.FilePurpose;
142import java.io.ByteArrayInputStream;
143
144public final class Main {
145 private Main() {}
146
147 public static void main(String[] args) {
148 OpenAIClient client = OpenAIOkHttpClient.fromEnv();
149
150 FileCreateParams params = FileCreateParams.builder()
151 .file(new ByteArrayInputStream("Example data".getBytes()))
152 .purpose(FilePurpose.ASSISTANTS)
153 .build();
154 FileObject fileObject = client.files().create(params);
155 }
156}
157```
158
159#### Response
160
161```json
162{
163 "id": "id",
164 "bytes": 0,
165 "created_at": 0,
166 "filename": "filename",
167 "object": "file",
168 "purpose": "assistants",
169 "status": "uploaded",
170 "expires_at": 0,
171 "status_details": "status_details"
172}
173```