Files

Files are used to upload documents that can be used with features like Assistants, Fine-tuning, and Batch API.

Upload file

post https://api.openai.com/v1/files

Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and each project can store up to 2.5 TB of files in total. There is no organization-wide storage limit.

  • The Assistants API supports files up to 2 million tokens and of specific file types. See the Assistants Tools guide for details.
  • The Fine-tuning API only supports .jsonl files. The input also has certain required formats for fine-tuning chat or completions models.
  • The Batch API only supports .jsonl files up to 200 MB in size. The input also has a specific required format.

Please contact us if you need to increase these storage limits.

Request body

The File object (not file name) to be uploaded.

The intended purpose of the uploaded file. One of:

  • assistants: Used in the Assistants API
  • batch: Used in the Batch API
  • fine-tune: Used for fine-tuning
  • vision: Images used for vision fine-tuning
  • user_data: Flexible file type for any purpose
  • evals: Used for eval data sets

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.

Returns

The uploaded File object.

Example request
1
2
3
4
5
6
curl https://api.openai.com/v1/files \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F purpose="fine-tune" \
  -F file="@mydata.jsonl"
  -F expires_after[anchor]="created_at"
  -F expires_after[seconds]=2592000
Response
1
2
3
4
5
6
7
8
9
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1677614202,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune",
}

List files

get https://api.openai.com/v1/files

Returns a list of files.

Query parameters

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.

A limit on the number of objects to be returned. Limit can range between 1 and 10,000, and the default is 10,000.

Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.

Only return files with the given purpose.

Returns

A list of File objects.

Example request
1
2
curl https://api.openai.com/v1/files \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  "object": "list",
  "data": [
    {
      "id": "file-abc123",
      "object": "file",
      "bytes": 175,
      "created_at": 1613677385,
      "expires_at": 1677614202,
      "filename": "salesOverview.pdf",
      "purpose": "assistants",
    },
    {
      "id": "file-abc456",
      "object": "file",
      "bytes": 140,
      "created_at": 1613779121,
      "expires_at": 1677614202,
      "filename": "puppy.jsonl",
      "purpose": "fine-tune",
    }
  ],
  "first_id": "file-abc123",
  "last_id": "file-abc456",
  "has_more": false
}

Retrieve file

get https://api.openai.com/v1/files/{file_id}

Returns information about a specific file.

Path parameters

The ID of the file to use for this request.

Returns

The File object matching the specified ID.

Example request
1
2
curl https://api.openai.com/v1/files/file-abc123 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1677614202,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune",
}

Delete file

delete https://api.openai.com/v1/files/{file_id}

Delete a file and remove it from all vector stores.

Path parameters

The ID of the file to use for this request.

Returns

Deletion status.

Example request
1
2
3
curl https://api.openai.com/v1/files/file-abc123 \
  -X DELETE \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
{
  "id": "file-abc123",
  "object": "file",
  "deleted": true
}

Retrieve file content

get https://api.openai.com/v1/files/{file_id}/content

Returns the contents of the specified file.

Path parameters

The ID of the file to use for this request.

Returns

The file content.

Example request
1
2
curl https://api.openai.com/v1/files/file-abc123/content \
  -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl

The file object

The File object represents a document that has been uploaded to OpenAI.

The size of the file, in bytes.

The Unix timestamp (in seconds) for when the file was created.

The Unix timestamp (in seconds) for when the file will expire.

The name of the file.

The file identifier, which can be referenced in the API endpoints.

The object type, which is always file.

The intended purpose of the file. Supported values are assistants, assistants_output, batch, batch_output, fine-tune, fine-tune-results, vision, and user_data.

Deprecated. The current status of the file, which can be either uploaded, processed, or error.

Deprecated. For details on why a fine-tuning training file failed validation, see the error field on fine_tuning.job.

OBJECT The file object
1
2
3
4
5
6
7
8
9
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1680202602,
  "filename": "salesOverview.pdf",
  "purpose": "assistants",
}