---
title: "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."
method: POST
path: "/v1/files"
tags: ["v1"]
---

# 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.

`POST /v1/files`

## Response `200`

Success

- File — An uploaded file.
  - `bytes` integer, required — The size of the file, in bytes.
  - `created_at` integer, required — The Unix timestamp (in seconds) for file creation time.
  - `expires_at` integer, nullable — The Unix timestamp (in seconds) for file expiry time. null if file does not expire.
  - `filename` string, required — The name of the file.
  - `id` string, required — The file identifier, which can be used in other API requests.
  - `object` string, required — The object type, which is always `file`. Only included for compatability.
  - `public_url` string, nullable — Public URL for the file. Only present when the file has an active public URL.
  - `public_url_expires_at` integer, nullable — Unix timestamp (seconds) when the public URL expires. Only present when the public URL has an independent expiry.
  - `purpose` string — The intended purpose of the uploaded file. Only included for OAI compatability.

## Other responses

- `400` — Bad request. Common causes: `expires_after` outside [3600, 2592000], `expires_after` field appearing after `file` in the multipart body, missing or unnamed `file` part, invalid filename.
- `413` — Payload too large -- file exceeds 50 MB.

---

[API](https://skmtc.net/x/apis/xai-s-rest-api.md) · [All operations](https://skmtc.net/x/apis/xai-s-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/x/xai-s-rest-api/versions/8f6014272113/schema)
