Files API

Upload

View as Markdown


Upload a file

/v1/files

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

filestring

The file to upload. The filename from the multipart `Content-Disposition: filename=` header is recorded as the file's `filename`.

Response Body

bytesinteger

The size of the file, in bytes.

created_atinteger

The Unix timestamp (in seconds) for file creation time.

filenamestring

The name of the file.

idstring

The file identifier, which can be used in other API requests.

objectstring

The object type, which is always `file`. Only included for compatability.

purposestring

The intended purpose of the uploaded file. Only included for OAI compatability.

Exampletext

text

No parameters.
Exampletext

text

{
  "id": "file_a128090d-f0c9-4873-bd84-e499777e7417",
  "object": "file",
  "bytes": 12345,
  "created_at": 1762345678,
  "expires_at": 1762432078,
  "filename": "document.pdf",
  "purpose": ""
}

Initialize a file upload

/v1/files:initialize

API endpoint for POST requests to /v1/files:initialize.


Exampletext

text

No parameters.
Exampletext

text

No response.

Upload a file in chunks

/v1/files:uploadChunks

API endpoint for POST requests to /v1/files:uploadChunks.

Exampletext

text

No parameters.
Exampletext

text

No response.

Last updated:April 28, 2026