Files API
Upload
Upload a file
/v1/files
Multipart field ordering: expires_after must appear before the file field in the
multipart body. Requests that send expires_after after file are rejected with 400.
See the Managing Files guide for end-to-end examples.
Upload a file to xAI's storage. Returns the file's metadata. Files can
be referenced by ID anywhere a file_id is accepted (e.g. chat
attachments). Maximum file size: 50 MB. Files are kept until you
delete them, or until expires_after elapses if set at upload time.
Request Body
file
string
required
The file to upload. The filename from the multipart
Content-Disposition: filename= header is recorded as the file's
filename.
Response Body
bytes
integer
The size of the file, in bytes.
created_at
integer
The Unix timestamp (in seconds) for file creation time.
filename
string
The name of the file.
id
string
The file identifier, which can be used in other API requests.
object
string
The object type, which is always file. Only included for compatability.
purpose
string
The intended purpose of the uploaded file. Only included for OAI compatability.
Initialize a file upload
/v1/files:initialize
Upload a file in chunks
/v1/files:uploadChunks
Did you find this page helpful?
Last updated: April 28, 2026