Files
Upload a file, read its metadata, download its content, and attach it to a chat turn with file_ids. Chat reads text, PDF, Word, and image files.
A file is content you upload once and name by id afterwards. A chat message
attaches files with file_ids, and the gateway reads each one into the turn.
A file belongs to you, within the organization your key names: only you can
list, read, or delete it. To hold a file where a team can read it, put it in a
vault; see Vaults.
Upload a file
POST /api/v1/files takes multipart/form-data with the content in a part
named file. The upload is rate-limited and not billed.
curl https://api.cruxy.ai/api/v1/files \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-F "[email protected]" \
-F "purpose=general"import { openAsBlob } from 'node:fs'
const form = new FormData()
form.append('file', await openAsBlob('report.pdf'), 'report.pdf')
form.append('purpose', 'general')
const res = await fetch('https://api.cruxy.ai/api/v1/files', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.CRUXY_API_KEY}` },
body: form,
})
if (!res.ok) throw new Error(`upload failed: ${res.status} ${await res.text()}`)
const file = await res.json()
console.log(file.id, file.content_type, file.text_status)import { openAsBlob } from 'node:fs'
import { Cruxy } from '@cruxy/api'
const cruxy = new Cruxy({ bearerAuth: process.env.CRUXY_API_KEY })
const { result: file } = await cruxy.files.uploadFile({
body: { file: await openAsBlob('report.pdf'), purpose: 'general' },
})
console.log(file.id, file.contentType, file.textStatus)The 201 describes the stored file:
| Field | Meaning |
|---|---|
id | The id you name in file_ids and in every other file call. |
filename | The name the upload carried. The content is never addressed by it. |
bytes | The size of the content. |
content_type | The media type the gateway detected from the content's first bytes. The Content-Type you declared on the part is ignored. |
purpose | The label you sent: a short token of letters, digits, ., _, and -. It defaults to general. |
expires_at | When the file stops existing, or null for a file kept until you delete it. |
text_status, text_tokens | For a PDF or Word document, what reading its text at upload found. Both are null for every other file. |
Two optional fields change how long a file lives:
expires_ingives the file a lifetime in seconds, from 60 to 604800 (7 days). Once it passes, the file is gone to every read and to chat, and its bytes are deleted within 15 minutes. Setting it requiresCruxy-Version: 2026-10-07or later; without the pin, or with a value out of range, the upload is400invalid_requestand nothing is stored.purpose=chat_attachmentmarks a file uploaded to be attached to a stored conversation message. One that no message has attached 24 hours after upload is deleted. See Conversations.
Without either, a file lives until you delete it.
Documents
A PDF or a Word document (.docx) has its text read once, as part of the
upload, so chat can read it like a text file. Reading never fails the upload:
the file is stored whatever it holds, and text_status says what was found.
text_status | Meaning |
|---|---|
extracted | Chat can read the document. text_tokens is the size of its text, by a characters-over-four estimate. |
no_text | No text was found, as in a scanned PDF. |
encrypted | The document needs a password. |
corrupt | The document is damaged, or uses a feature the reader does not support. |
too_long | The text is over 1 MiB and is not kept. text_tokens says how much there was. |
too_many_pages, too_big | The document is over the reader's bounds: 500 pages, or 64 MiB. |
failed | Reading ran out of time or memory. |
busy | Every reader stayed busy while the document waited. Nothing is wrong with the file: upload it again and it is read. |
Chat refuses a turn that attaches a document with any status but extracted.
A legacy Word 97-2003 document (.doc) is stored and not read.
Attach files to a chat turn
Name the files on a user message in file_ids. The gateway places each one
in the turn immediately before that message. The request must pin
Cruxy-Version: 2026-10-05 or later; without the pin, file_ids is 400
invalid_request with required_version.
curl https://api.cruxy.ai/api/v1/chat \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-H "Content-Type: application/json" \
-H "Cruxy-Version: 2026-10-05" \
-d "{
\"model\": \"saga\",
\"stream\": false,
\"messages\": [
{
\"role\": \"user\",
\"content\": \"List the three main findings.\",
\"file_ids\": [\"$FILE_ID\"]
}
]
}"const fileId = process.env.FILE_ID // the id an upload returned
const res = await fetch('https://api.cruxy.ai/api/v1/chat', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CRUXY_API_KEY}`,
'Content-Type': 'application/json',
'Cruxy-Version': '2026-10-05',
},
body: JSON.stringify({
model: 'saga',
stream: false,
messages: [
{ role: 'user', content: 'List the three main findings.', file_ids: [fileId] },
],
}),
})
if (!res.ok) throw new Error(`chat failed: ${res.status} ${await res.text()}`)
const completion = await res.json()
console.log(completion.message.content)
// Files on earlier messages that this turn left out, and why.
console.log(completion.cruxy.files_omitted?.items ?? [])What chat reads:
- Text. A UTF-8 text file, as it is.
- Documents. A PDF or Word document, as the text read from it at upload, measured and billed as that text.
- Images. A JPEG, PNG, or WebP image, on a tier that reads images:
supports_visioninGET /api/v1/models.model: "auto"routes a turn with an image to a tier that does. You do not need to resize an image first.
The rules for a turn:
file_idsis valid on user messages only, onPOST /api/v1/chatandPOST /api/v2/chat.POST /v1/chat/completionsandPOST /api/v1/tokens/countrefuse it.- The messages after the last assistant message may name at most 20 distinct files, and each must be readable, or the request fails with one of the codes below.
- A file on an earlier message never fails the request. It is sent again
while it still resolves and fits, newest first; otherwise it is left out,
the model is told so, and the response lists it in
cruxy.files_omittedwith areason, such asnot_found,over_budget,context_window, orno_vision. More reasons may be added, so read one you do not know as "left out". - A file's tokens are input like any other. They are billed in full on the turn that attaches the file, and again as history on each later turn that replays the message; see Usage and cost.
A file on the current turn that cannot be read fails the request:
| Status | code | When |
|---|---|---|
404 | file_not_found | An id that is not a file of yours. |
400 | file_not_text | A file that is not text, a document whose text could not be read, or an image that does not open. |
400 | file_too_large | A file over the token caps, a PDF too big to read, an image over 15,000,000 bytes or with one side over 200 times the other, or images over 30,000,000 bytes together. |
400 | image_not_supported | An image on a tier that does not read images. |
List, read, and download
GET /api/v1/files lists your files, newest first. Page with limit (default
20, at most 100) and the cursor from the previous page's next_cursor,
which is null on the last page. total is how many files the listing pages
through. GET /api/v1/files/{id} returns one file's metadata. Both name the
conversations of yours a file is attached in, under conversations.
GET /api/v1/files/{id}/content streams the file's raw bytes. The response is
always application/octet-stream with Content-Disposition: attachment, so
content is never rendered inline.
curl https://api.cruxy.ai/api/v1/files/$FILE_ID/content \
-H "Authorization: Bearer $CRUXY_API_KEY" \
-o report-copy.pdfimport { writeFile } from 'node:fs/promises'
const fileId = process.env.FILE_ID // the id an upload returned
const res = await fetch(`https://api.cruxy.ai/api/v1/files/${fileId}/content`, {
headers: { Authorization: `Bearer ${process.env.CRUXY_API_KEY}` },
})
if (!res.ok) throw new Error(`download failed: ${res.status}`)
await writeFile('report-copy.pdf', Buffer.from(await res.arrayBuffer()))import { Cruxy } from '@cruxy/api'
const cruxy = new Cruxy({ bearerAuth: process.env.CRUXY_API_KEY })
const { result: files } = await cruxy.files.listFiles({ limit: 20 })
for (const file of files.data) {
console.log(file.id, file.filename, file.bytes)
}A file that belongs to another user, or to another of your own organizations,
answers 404 file_not_found on every one of these calls, the same as an id
that never existed.
Delete a file
DELETE /api/v1/files/{id} deletes the file and its content, and answers
200 with deleted: true. A repeat delete is 404 file_not_found.
Limits
Your plan sets how many files and images you may upload a month, the largest
single file, and a storage pool. An upload past one of them is refused before
a byte is stored: 429 file_limit_reached or image_limit_reached, or
413 payload_too_large or storage_quota_exceeded.
Plan limits has each plan's
numbers, and GET /api/v1/limits reports yours as files, images,
storage, and plan_limits.
Next steps
- Vaults: hold files where every member of a vault can read them.
- Chat: the request a file is attached to.
- Conversations: keep a message's files with the stored conversation.
- Errors and retries: the error envelope and what to retry.