SPB Git

Repository Public

files.md 12.2 KB 606 lines markdown

1# Files23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45## Retrieve file content67**get** `/files/{file_id}/content`89Returns a response containing the contents of the specified file.1011### Path Parameters1213- `file_id: string`1415### Example1617```http18curl https://api.openai.com/v1/files/$FILE_ID/content \19    -H "Authorization: Bearer $OPENAI_API_KEY"20```2122### Example2324```http25curl https://api.openai.com/v1/files/file-abc123/content \26  -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl27```2829## Upload file3031**post** `/files`3233Upload a file that can be used across various endpoints. Individual files34can be up to 512 MB, and each project can store up to 2.5 TB of files in35total. There is no organization-wide storage limit. Uploads to this36endpoint are rate-limited to 1,000 requests per minute per authenticated37user.3839- The Assistants API supports files up to 2 million tokens and of specific40  file types. See the [Assistants Tools guide](/api/docs/guides/tools) for41  details.42- The Fine-tuning API only supports `.jsonl` files. The input also has43  certain required formats for fine-tuning44  [chat](/api/docs/guides/supervised-fine-tuning#formatting-your-data) or45  [completions](/api/docs/guides/supervised-fine-tuning#formatting-your-data) models.46- The Batch API only supports `.jsonl` files up to 200 MB in size. The input47  also has a specific required48  [format](/api/docs/guides/batch#1-prepare-your-batch-file).49- For Retrieval or `file_search` ingestion, upload files here first. If50  you need to attach multiple uploaded files to the same vector store, use51  [`/vector_stores/{vector_store_id}/file_batches`](/api/reference/resources/vector_stores/subresources/file_batches/methods/create)52  instead of attaching them one by one. Vector store attachment has separate53  limits from file upload, including 2,000 attached files per minute per54  organization.5556Please [contact us](https://help.openai.com/) if you need to increase these57storage limits.5859### Returns6061- `FileObject object { id, bytes, created_at, 6 more }`6263  The `File` object represents a document that has been uploaded to OpenAI.6465  - `id: string`6667    The file identifier, which can be referenced in the API endpoints.6869  - `bytes: number`7071    The size of the file, in bytes.7273  - `created_at: number`7475    The Unix timestamp (in seconds) for when the file was created.7677  - `filename: string`7879    The name of the file.8081  - `object: "file"`8283    The object type, which is always `file`.8485    - `"file"`8687  - `purpose: "assistants" or "assistants_output" or "batch" or 5 more`8889    The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.9091    - `"assistants"`9293    - `"assistants_output"`9495    - `"batch"`9697    - `"batch_output"`9899    - `"fine-tune"`100101    - `"fine-tune-results"`102103    - `"vision"`104105    - `"user_data"`106107  - `status: "uploaded" or "processed" or "error"`108109    Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.110111    - `"uploaded"`112113    - `"processed"`114115    - `"error"`116117  - `expires_at: optional number`118119    The Unix timestamp (in seconds) for when the file will expire.120121  - `status_details: optional string`122123    Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.124125### Example126127```http128curl https://api.openai.com/v1/files \129    -H 'Content-Type: multipart/form-data' \130    -H "Authorization: Bearer $OPENAI_API_KEY" \131    -F 'file=@/path/to/file' \132    -F purpose=assistants133```134135#### Response136137```json138{139  "id": "id",140  "bytes": 0,141  "created_at": 0,142  "filename": "filename",143  "object": "file",144  "purpose": "assistants",145  "status": "uploaded",146  "expires_at": 0,147  "status_details": "status_details"148}149```150151### Example152153```http154curl https://api.openai.com/v1/files \155  -H "Authorization: Bearer $OPENAI_API_KEY" \156  -F purpose="fine-tune" \157  -F file="@mydata.jsonl"158  -F expires_after[anchor]="created_at"159  -F expires_after[seconds]=2592000160```161162#### Response163164```json165{166  "id": "file-abc123",167  "object": "file",168  "bytes": 120000,169  "created_at": 1677610602,170  "expires_at": 1677614202,171  "filename": "mydata.jsonl",172  "purpose": "fine-tune",173}174```175176## Delete file177178**delete** `/files/{file_id}`179180Delete a file and remove it from all vector stores.181182### Path Parameters183184- `file_id: string`185186### Returns187188- `FileDeleted object { id, deleted, object }`189190  - `id: string`191192  - `deleted: boolean`193194  - `object: "file"`195196    - `"file"`197198### Example199200```http201curl https://api.openai.com/v1/files/$FILE_ID \202    -X DELETE \203    -H "Authorization: Bearer $OPENAI_API_KEY"204```205206#### Response207208```json209{210  "id": "id",211  "deleted": true,212  "object": "file"213}214```215216### Example217218```http219curl https://api.openai.com/v1/files/file-abc123 \220  -X DELETE \221  -H "Authorization: Bearer $OPENAI_API_KEY"222```223224#### Response225226```json227{228  "id": "file-abc123",229  "object": "file",230  "deleted": true231}232```233234## List files235236**get** `/files`237238Returns a list of files.239240### Query Parameters241242- `after: optional string`243244  A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.245246- `limit: optional number`247248  A limit on the number of objects to be returned. Limit can range between 1 and 10,000, and the default is 10,000.249250- `order: optional "asc" or "desc"`251252  Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and `desc` for descending order.253254  - `"asc"`255256  - `"desc"`257258- `purpose: optional string`259260  Only return files with the given purpose.261262### Returns263264- `data: array of FileObject`265266  - `id: string`267268    The file identifier, which can be referenced in the API endpoints.269270  - `bytes: number`271272    The size of the file, in bytes.273274  - `created_at: number`275276    The Unix timestamp (in seconds) for when the file was created.277278  - `filename: string`279280    The name of the file.281282  - `object: "file"`283284    The object type, which is always `file`.285286    - `"file"`287288  - `purpose: "assistants" or "assistants_output" or "batch" or 5 more`289290    The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.291292    - `"assistants"`293294    - `"assistants_output"`295296    - `"batch"`297298    - `"batch_output"`299300    - `"fine-tune"`301302    - `"fine-tune-results"`303304    - `"vision"`305306    - `"user_data"`307308  - `status: "uploaded" or "processed" or "error"`309310    Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.311312    - `"uploaded"`313314    - `"processed"`315316    - `"error"`317318  - `expires_at: optional number`319320    The Unix timestamp (in seconds) for when the file will expire.321322  - `status_details: optional string`323324    Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.325326- `first_id: string`327328- `has_more: boolean`329330- `last_id: string`331332- `object: string`333334### Example335336```http337curl https://api.openai.com/v1/files \338    -H "Authorization: Bearer $OPENAI_API_KEY"339```340341#### Response342343```json344{345  "data": [346    {347      "id": "id",348      "bytes": 0,349      "created_at": 0,350      "filename": "filename",351      "object": "file",352      "purpose": "assistants",353      "status": "uploaded",354      "expires_at": 0,355      "status_details": "status_details"356    }357  ],358  "first_id": "file-abc123",359  "has_more": false,360  "last_id": "file-abc456",361  "object": "list"362}363```364365### Example366367```http368curl https://api.openai.com/v1/files \369  -H "Authorization: Bearer $OPENAI_API_KEY"370```371372#### Response373374```json375{376  "object": "list",377  "data": [378    {379      "id": "file-abc123",380      "object": "file",381      "bytes": 175,382      "created_at": 1613677385,383      "expires_at": 1677614202,384      "filename": "salesOverview.pdf",385      "purpose": "assistants",386    },387    {388      "id": "file-abc456",389      "object": "file",390      "bytes": 140,391      "created_at": 1613779121,392      "expires_at": 1677614202,393      "filename": "puppy.jsonl",394      "purpose": "fine-tune",395    }396  ],397  "first_id": "file-abc123",398  "last_id": "file-abc456",399  "has_more": false400}401```402403## Retrieve file404405**get** `/files/{file_id}`406407Returns information about a specific file.408409### Path Parameters410411- `file_id: string`412413### Returns414415- `FileObject object { id, bytes, created_at, 6 more }`416417  The `File` object represents a document that has been uploaded to OpenAI.418419  - `id: string`420421    The file identifier, which can be referenced in the API endpoints.422423  - `bytes: number`424425    The size of the file, in bytes.426427  - `created_at: number`428429    The Unix timestamp (in seconds) for when the file was created.430431  - `filename: string`432433    The name of the file.434435  - `object: "file"`436437    The object type, which is always `file`.438439    - `"file"`440441  - `purpose: "assistants" or "assistants_output" or "batch" or 5 more`442443    The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.444445    - `"assistants"`446447    - `"assistants_output"`448449    - `"batch"`450451    - `"batch_output"`452453    - `"fine-tune"`454455    - `"fine-tune-results"`456457    - `"vision"`458459    - `"user_data"`460461  - `status: "uploaded" or "processed" or "error"`462463    Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.464465    - `"uploaded"`466467    - `"processed"`468469    - `"error"`470471  - `expires_at: optional number`472473    The Unix timestamp (in seconds) for when the file will expire.474475  - `status_details: optional string`476477    Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.478479### Example480481```http482curl https://api.openai.com/v1/files/$FILE_ID \483    -H "Authorization: Bearer $OPENAI_API_KEY"484```485486#### Response487488```json489{490  "id": "id",491  "bytes": 0,492  "created_at": 0,493  "filename": "filename",494  "object": "file",495  "purpose": "assistants",496  "status": "uploaded",497  "expires_at": 0,498  "status_details": "status_details"499}500```501502### Example503504```http505curl https://api.openai.com/v1/files/file-abc123 \506  -H "Authorization: Bearer $OPENAI_API_KEY"507```508509#### Response510511```json512{513  "id": "file-abc123",514  "object": "file",515  "bytes": 120000,516  "created_at": 1677610602,517  "expires_at": 1677614202,518  "filename": "mydata.jsonl",519  "purpose": "fine-tune",520}521```522523## Domain Types524525### File Content526527- `FileContent = string`528529### File Deleted530531- `FileDeleted object { id, deleted, object }`532533  - `id: string`534535  - `deleted: boolean`536537  - `object: "file"`538539    - `"file"`540541### File Object542543- `FileObject object { id, bytes, created_at, 6 more }`544545  The `File` object represents a document that has been uploaded to OpenAI.546547  - `id: string`548549    The file identifier, which can be referenced in the API endpoints.550551  - `bytes: number`552553    The size of the file, in bytes.554555  - `created_at: number`556557    The Unix timestamp (in seconds) for when the file was created.558559  - `filename: string`560561    The name of the file.562563  - `object: "file"`564565    The object type, which is always `file`.566567    - `"file"`568569  - `purpose: "assistants" or "assistants_output" or "batch" or 5 more`570571    The intended purpose of the file. Supported values are `assistants`, `assistants_output`, `batch`, `batch_output`, `fine-tune`, `fine-tune-results`, `vision`, and `user_data`.572573    - `"assistants"`574575    - `"assistants_output"`576577    - `"batch"`578579    - `"batch_output"`580581    - `"fine-tune"`582583    - `"fine-tune-results"`584585    - `"vision"`586587    - `"user_data"`588589  - `status: "uploaded" or "processed" or "error"`590591    Deprecated. The current status of the file, which can be either `uploaded`, `processed`, or `error`.592593    - `"uploaded"`594595    - `"processed"`596597    - `"error"`598599  - `expires_at: optional number`600601    The Unix timestamp (in seconds) for when the file will expire.602603  - `status_details: optional string`604605    Deprecated. For details on why a fine-tuning training file failed validation, see the `error` field on `fine_tuning.job`.606
Files main
Menu

Theme