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/files

Body must be multipart/form-data. The maximum upload size is 100 MB per file.

Headers

AuthorizationBearerrequired

API key. See Authentication.

Content-Typestringrequired

Must be multipart/form-data.

Form fields

filebinaryrequired

The file contents to upload.

purposestringrequired

What the file will be used for. Use user_data for general chat-completion attachments.

Allowed values:user_data
expires_after[anchor]'created_at'optional

Optional. Anchor for the expiration timer. Only created_at is supported.

expires_after[seconds]integeroptional

Optional. Number of seconds after the anchor at which the file is auto-deleted. Range: 3600 (1 hour) to 2592000 (30 days).

Response

idstringoptional

The new file's id (prefixed file-).

object'file'optional

Always file.

bytesintegeroptional

Size of the upload in bytes.

created_atintegeroptional

Unix timestamp of upload.

filenamestringoptional

Filename as sent in the multipart body.

purposestringoptional

Echo of the requested purpose.

status'processed'optional

Files are immediately available - status will always be processed on a successful upload.

expires_atintegeroptional

Only 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

StatusReason
400Missing required form field, invalid purpose, or invalid expires_after.
401Missing or invalid API key.
403API key has no associated user.
413Upload exceeds 100 MB.