
Get Files API metadata and check expiry
Get Files API metadata and check expiry
GET https://api.x.ai/v1/files/{id} returns one file’s metadata without downloading bytes. Use it after upload, before an Imagine file_id reference, or to see whether a TTL is still live. List, download, and delete live in List, download, and delete Files API uploads.
curl
curl https://api.x.ai/v1/files/file-abc123 \
-H "Authorization: Bearer $XAI_API_KEY"
xAI SDK (HasField)
Permanent files omit expires_at. Check the field before you read it:
import os
from xai_sdk import Client
client = Client(api_key=os.getenv("XAI_API_KEY"))
file = client.files.get("file-abc123")
print(file.filename, file.size, file.created_at)
if file.HasField("expires_at"):
print("Expires at:", file.expires_at.ToDatetime())
else:
print("Expires at: never")
OpenAI-compatible SDK
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("XAI_API_KEY"),
base_url="https://api.x.ai/v1",
)
file = client.files.retrieve("file-abc123")
print(file.filename, file.bytes, file.expires_at) # expires_at is None when permanent
Object fields
| Field | Meaning |
|---|---|
id |
Stable file_… id for chat, Imagine, and content download |
filename |
Name supplied at upload |
bytes / size |
Size in bytes (JSON vs xAI SDK naming) |
created_at |
Upload time (Unix seconds on JSON) |
expires_at |
Absolute delete time, or absent / null when permanent |
purpose |
Echoed for SDK compatibility; xAI does not enforce it |
object |
Always "file" on JSON responses |
After expires_at, get / list / content return not found and the id cannot be referenced. Manual delete still works before then. Max upload size is 512 MB.
Pitfalls
- Calling
.expires_aton the xAI SDK object withoutHasFieldwhen the file is permanent. - Treating
purposeas an access control flag. - Caching ids past TTL — expired ids stop resolving.