Skip to main content

Method Signature

Parameters

FileTypes
required
The File object (not file name) to be uploaded. This should be a file-like object opened in binary mode.Size limits:
  • Individual files: up to 512 MB
  • Per project: up to 2.5 TB total
  • No organization-wide limit
FilePurpose
required
The intended purpose of the uploaded file. Must be one of:
  • assistants - Used in the Assistants API
  • batch - Used in the Batch API
  • fine-tune - Used for fine-tuning (.jsonl files only)
  • vision - Images used for vision fine-tuning
  • user_data - Flexible file type for any purpose
  • evals - Used for eval data sets
Purpose-specific requirements:
  • Assistants API: Files up to 2 million tokens, specific file types only
  • Fine-tuning API: Only .jsonl files with specific formats for chat or completions
  • Batch API: Only .jsonl files up to 200 MB with specific format
ExpiresAfter
The expiration policy for the file.Default behavior:
  • Files with purpose=batch: expire after 30 days
  • All other files: persisted until manually deleted

Response

Returns a FileObject:

Examples

Upload Training File for Fine-tuning

Upload File for Assistants

Upload Batch File with Expiration

Upload from Path Using Pathlib

Wait for File Processing

Async Usage

File Format Requirements

Fine-tuning (JSONL)

Batch API (JSONL)

Notes

  • Files are uploaded using multipart/form-data encoding
  • The file parameter must be a file object, not a file path string
  • Always open files in binary mode ("rb")
  • Use context managers (with statement) to ensure files are properly closed
  • Contact OpenAI support to increase storage limits