Files
Upload and manage private files for chat attachments, image/video media references, batches, and collections. Official xAI pages currently conflict between 48 MB and 50 MB file limits, so automation should use 48 MB as the conservative ceiling.
curl https://api.x.ai/v1/files -H "Authorization: Bearer $XAI_API_KEY" -F expires_after=86400 -F purpose=assistants -F file=@document.pdf | Endpoint | Purpose |
|---|---|
POST /v1/files | Multipart upload from path, bytes, object, or open handle. Returns reusable file_id. |
GET /v1/files | List with limit, order, sort_by, and pagination_token. |
GET /v1/files/{file_id} | Read metadata. |
GET /v1/files/{file_id}/content | Download file content. |
DELETE /v1/files/{file_id} | Delete the uploaded file. |
POST /v1/files:initialize | Start chunked upload for larger/more resilient transfers. |
POST /v1/files:uploadChunks | Upload chunk data after initialization. |
expires_after must be sent before the file field in multipart requests. Files referenced in chat attachments can activate attachment_search; media APIs can reference uploaded assets as file_id.