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"

The 201 describes the stored file:

FieldMeaning
idThe id you name in file_ids and in every other file call.
filenameThe name the upload carried. The content is never addressed by it.
bytesThe size of the content.
content_typeThe media type the gateway detected from the content's first bytes. The Content-Type you declared on the part is ignored.
purposeThe label you sent: a short token of letters, digits, ., _, and -. It defaults to general.
expires_atWhen the file stops existing, or null for a file kept until you delete it.
text_status, text_tokensFor 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_in gives 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 requires Cruxy-Version: 2026-10-07 or later; without the pin, or with a value out of range, the upload is 400 invalid_request and nothing is stored.
  • purpose=chat_attachment marks 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_statusMeaning
extractedChat can read the document. text_tokens is the size of its text, by a characters-over-four estimate.
no_textNo text was found, as in a scanned PDF.
encryptedThe document needs a password.
corruptThe document is damaged, or uses a feature the reader does not support.
too_longThe text is over 1 MiB and is not kept. text_tokens says how much there was.
too_many_pages, too_bigThe document is over the reader's bounds: 500 pages, or 64 MiB.
failedReading ran out of time or memory.
busyEvery 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\"]
      }
    ]
  }"

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_vision in GET /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_ids is valid on user messages only, on POST /api/v1/chat and POST /api/v2/chat. POST /v1/chat/completions and POST /api/v1/tokens/count refuse 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_omitted with a reason, such as not_found, over_budget, context_window, or no_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:

StatuscodeWhen
404file_not_foundAn id that is not a file of yours.
400file_not_textA file that is not text, a document whose text could not be read, or an image that does not open.
400file_too_largeA 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.
400image_not_supportedAn 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.pdf

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.

Was this page helpful?