Files API
Upload, manage, and retrieve documents for RAG integration
The Files API allows you to upload, manage, and retrieve documents for use with the RAG system. This API serves as the foundation for document management before semantic search.
The official documentation for the Files API is available here.
Key Capabilities
Document Upload
Upload documents in various formats (PDF, TXT, DOCX, CSV, JSON, etc.)
File Management
List, retrieve, and delete files with filtering options
Content Access
Access file content and metadata through a unified API
RAG Integration
Seamlessly connect with vector stores for embedding generation
API Endpoints
Upload a File
Upload a document to make it available for vector stores and semantic search.
Endpoint: POST /v1/files
Content-Type: multipart/form-data
Request Parameters:
file
: The file to upload (required)purpose
: The intended use of the file (required)- Supported values:
assistants
,batch
,fine_tune
,vision
,user_data
,evals
- Supported values:
Example Response:
Supported formats include PDF, TXT, DOCX, CSV, JSON, and many others. The returned file ID is used for all other operations with this file. The bytes field will be 0 until the file is processed.
List Files
Retrieve a list of all files you’ve uploaded, with optional filtering.
Endpoint: GET /v1/files
Query Parameters:
purpose
: Filter files by purpose (optional)limit
: Maximum number of files to return (default: 100, range: 1-100)order
: Sort order by creation timestamp (asc
ordesc
, default:desc
)after
: Return files after this ID for pagination (optional)
Example Response:
Retrieve File Metadata
Get metadata about a specific file.
Endpoint: GET /v1/files/{file_id}
Path Parameters:
file_id
: The ID of the file to retrieve (required)
Example Response:
Retrieve File Content
Download the content of a specific file.
Endpoint: GET /v1/files/{file_id}/content
Path Parameters:
file_id
: The ID of the file to retrieve (required)
Response: The file content with appropriate Content-Type header.
Delete a File
Delete a file when it’s no longer needed.
Endpoint: DELETE /v1/files/{file_id}
Path Parameters:
file_id
: The ID of the file to delete (required)
Example Response:
Deleting a file will also remove it from any vector stores it has been added to.
Using Files with Vector Stores
After uploading a file, you can add it to a vector store for semantic search. This workflow connects the Files API to the Vector Store API.
Upload a File
Use the Files API to upload your document
Create a Vector Store
If you don’t already have a vector store, create one
Add the File to Vector Store
Add your uploaded file to the vector store
Search for Content
Now you can search for content in your documents
Best Practices
File Organization
File Management
- Regularly review and clean up unused files to maintain optimal performance
- Use the
purpose
parameter to categorize files based on their intended use - Leverage file metadata for tracking document versions and categories
- Consider creating a file inventory system for larger implementations