Upload a file
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.The File object (not file name) to be uploaded.
The intended purpose of the uploaded file. Options:
assistants: For use with the Assistants APIbatch: For the Batch APIfine-tune: For fine-tuningvision: For vision tasks
The expiration policy for a file. By default, files with
purpose=batch expire after 24 hours.Response
Returns aFileObject.
The file identifier, which can be referenced in API endpoints.
The object type, always
file.The size of the file in bytes.
Unix timestamp of when the file was created.
The name of the file.
The intended purpose of the file.
The current status of the file:
uploaded, processed, or error.Examples
Upload a fine-tuning file
Upload for Assistants
Upload with expiration
Retrieve a file
Returns information about a specific file.The ID of the file to use for this request.
Response
Returns aFileObject.
Examples
Get file information
Check file status
List files
Returns a list of files that belong to the user’s organization.Only return files with the given purpose.
A limit on the number of objects to be returned. Limit can range between 1 and 10,000.
Sort order by the
created_at timestamp. Options: asc for ascending order or desc for descending order.A cursor for use in pagination.
after is an object ID that defines your place in the list.Response
Returns a paginated list ofFileObject items.
Examples
List all files
Filter by purpose
Paginate through files
Delete a file
Delete a file and remove it from all vector stores.The ID of the file to use for this request.
Response
Returns aFileDeleted object.
The ID of the deleted file.
The object type, always
file.Whether the file was successfully deleted.
Examples
Delete a file
Clean up old files
Retrieve file content
Returns the contents of the specified file.The ID of the file to use for this request.
Response
Returns aStringIO object containing the file content.
Examples
Download file content
Read file content
File formats
Fine-tuning files
Must be.jsonl files with specific formats:
Batch API files
Must be.jsonl files up to 200 MB:
Assistants files
Supports various formats including:- Documents:
.pdf,.docx,.txt,.md - Spreadsheets:
.xlsx,.csv - Code:
.py,.js,.rb,.java, etc. - Images:
.png,.jpg,.gif,.webp
Storage limits
- Individual file size: Up to 512 MB
- Project storage: Up to 2.5 TB total
- Batch files: Up to 200 MB per file
- Assistants files: Up to 2 million tokens
Best practices
- Verify upload: Check the
statusfield after uploading - Set expiration: Use
expires_afterfor temporary files to manage storage - Clean up: Delete files you no longer need to free up space
- Use correct purpose: Specify the right purpose for proper processing
- Handle errors: Implement retry logic for failed uploads
- Monitor storage: Keep track of your total storage usage