Upload File
Upload a file to be referenced by chat completions and other endpoints.
Upload a file. Returns a FileObject
that can be referenced by file_id in chat completions and other
file-aware endpoints.
POST /v1/filesBody must be multipart/form-data. The maximum upload size is 100 MB
per file.
Headers
AuthorizationBearerrequiredAPI key. See Authentication.
Content-TypestringrequiredMust be multipart/form-data.
Form fields
filebinaryrequiredThe file contents to upload.
purposestringrequiredWhat the file will be used for. Use user_data for general
chat-completion attachments.
user_dataexpires_after[anchor]'created_at'optionalOptional. Anchor for the expiration timer. Only created_at is
supported.
expires_after[seconds]integeroptionalOptional. Number of seconds after the anchor at which the file is
auto-deleted. Range: 3600 (1 hour) to 2592000 (30 days).
Response
idstringoptionalThe new file's id (prefixed file-).
object'file'optionalAlways file.
bytesintegeroptionalSize of the upload in bytes.
created_atintegeroptionalUnix timestamp of upload.
filenamestringoptionalFilename as sent in the multipart body.
purposestringoptionalEcho of the requested purpose.
status'processed'optionalFiles are immediately available - status will always be processed
on a successful upload.
expires_atintegeroptionalOnly present when expires_after was set. Unix timestamp of
auto-deletion.
Caching
After upload we asynchronously pre-extract the file's text and cache it
to reduce latency. The first chat completion that references the new
file_id typically skips the extraction step entirely.
Errors
| Status | Reason |
|---|---|
400 | Missing required form field, invalid purpose, or invalid expires_after. |
401 | Missing or invalid API key. |
403 | API key has no associated user. |
413 | Upload exceeds 100 MB. |