Skip to content

Upload file

POST https://api.fastapi.ai/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.

By default, files with purpose=batch expire after 30 days and all other files are retained until they are deleted.

Request body


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


purpose string Required
The intended purpose of the uploaded file.

Use assistants for Assistants API files, batch for Batch API, fine-tune for Fine-tuning, vision for images used in vision fine-tuning, user_data for flexible file storage, and evals for evaluation datasets.


expires_after object Optional
The expiration policy for the file.


anchor string Required
The expiration anchor. One of created_at.


seconds integer Required
Number of seconds after the anchor time when the file expires. Must be between 3600 (1 hour) and 2592000 (30 days).

Returns


Returns the File object.

The uploaded File object.


The file object

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


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


bytes integer
The size of the file, in bytes.


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


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


filename string
The name of the file.


object string
The object type, which is always file.


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


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


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


OBJECT The file object
bash
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1680202602,
  "filename": "salesOverview.pdf",
  "purpose": "assistants"
}

Example

Request

bash
curl https://api.fastapi.ai/v1/files \
  -H "Authorization: Bearer $FAST_API_KEY" \
  -F purpose="fine-tune" \
  -F file="@mydata.jsonl" \
  -F expires_after[anchor]="created_at" \
  -F expires_after[seconds]=2592000

Response

bash
{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1677614202,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune"
}

那年我双手插兜, 让bug稳如老狗