Method Signature
Parameters
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
The intended purpose of the uploaded file. Must be one of:
assistants- Used in the Assistants APIbatch- Used in the Batch APIfine-tune- Used for fine-tuning (.jsonlfiles only)vision- Images used for vision fine-tuninguser_data- Flexible file type for any purposeevals- Used for eval data sets
- Assistants API: Files up to 2 million tokens, specific file types only
- Fine-tuning API: Only
.jsonlfiles with specific formats for chat or completions - Batch API: Only
.jsonlfiles up to 200 MB with specific format
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 aFileObject:
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-dataencoding - The file parameter must be a file object, not a file path string
- Always open files in binary mode (
"rb") - Use context managers (
withstatement) to ensure files are properly closed - Contact OpenAI support to increase storage limits