Skip to main content

Files

/v1/files stores a file so later requests can name it by file_id instead of sending its bytes each time. Upload a PDF once and ask several models about it, or upload an image and refer to it in a multi-turn conversation.

It speaks OpenAI's Files API. A request carrying the anthropic-version header, which the Anthropic SDKs always send, gets Anthropic's Files API instead. Both read and write the same files.

Endpoints​

MethodPathWhat it does
POST/v1/filesUpload a file
GET/v1/filesList your files
GET/v1/files/{file_id}Retrieve a file's metadata
GET/v1/files/{file_id}/contentDownload a file's bytes
DELETE/v1/files/{file_id}Delete a file

Quick example​

Upload a PDF, then ask about it.

import os

from openai import OpenAI

client = OpenAI(base_url="https://api.mindshub.ai/v1", api_key=os.environ["MINDSHUB_API_KEY"])

with open("report.pdf", "rb") as f:
uploaded = client.files.create(file=f, purpose="user_data")

response = client.responses.create(
model="mindshub_air",
input=[
{
"role": "user",
"content": [
{"type": "input_file", "file_id": uploaded.id},
{"type": "input_text", "text": "Summarize this report in three bullet points."},
],
}
],
)
print(response.output_text)

Uploading​

Send the file as multipart/form-data with a purpose. The purpose decides what the file is for, which types it takes, and how large it can be.

purposeForTypesSize limit
user_dataDocuments and images you refer to in a requestPDF, plain text, Markdown, CSV, JSON, PNG, JPEG, GIF, WebP50 MB
visionImages you refer to in a requestPNG, JPEG, GIF, WebP50 MB
batchInput to a batch job.jsonl200 MB

The type comes from the upload's Content-Type. When a client sends application/octet-stream, as many do, the file extension decides instead.

Expiry​

By default a batch file expires 30 days after upload and every other file is kept until you delete it. To set your own expiry, send both form fields:

FieldValue
expires_after[anchor]created_at
expires_after[seconds]3600 (1 hour) to 2592000 (30 days)

A file past its expiry reads as deleted everywhere at once: it no longer lists, and a request that names it gets a 404.

The file object​

{
"id": "file-0193a6f2c1d47e8b9a2f5c6d7e8f9a0b",
"object": "file",
"bytes": 482113,
"created_at": 1764063722,
"filename": "report.pdf",
"purpose": "user_data",
"status": "processed",
"expires_at": null
}
FieldMeaning
idPass it as file_id in a request.
bytesSize in bytes.
created_at, expires_atUnix seconds. expires_at is null for a file that never expires.
purposeWhat it was uploaded as. batch_output marks a batch job's results.
statusAlways processed. A file is usable as soon as the upload returns.

Using a file in a request​

Name the file in a content part. Each API uses its own part shape:

APIDocumentImage
Chat Completions{"type": "file", "file": {"file_id": "…"}}, PDF only—
Responses{"type": "input_file", "file_id": "…"}{"type": "input_image", "file_id": "…"}
Messages{"type": "document", "source": {"type": "file", "file_id": "…"}}{"type": "image", "source": {"type": "file", "file_id": "…"}}
completion = client.chat.completions.create(
model="mindshub_air",
messages=[
{
"role": "user",
"content": [
{"type": "file", "file": {"file_id": "file-0193a6f2c1d47e8b9a2f5c6d7e8f9a0b"}},
{"type": "text", "text": "What is the total on page 2?"},
],
}
],
)

The file's content is sent to whichever model serves the request, so any model that reads that type can use it. A model that cannot read the type answers 400 with file_type_not_supported.

Limits per request:

  • At most 100 files.
  • At most 50 MB of files in total. A file named twice counts twice.
  • Only user_data and vision files can be used as inputs. A batch file is for batch jobs only.

Listing, downloading and deleting​

  • List: newest first. Filter with purpose, and page with after set to the previous page's last_id while has_more is true. The SDKs page for you.
  • Download: GET /v1/files/{file_id}/content returns the bytes with the file's original type and name. A batch job's output file is held, with a 402, while your organization owes for the batch's usage. It opens once the balance is back to zero.
  • Delete: hard. The bytes and the metadata are both gone, and a request that names the file afterwards gets a 404.

Who sees what​

A file is visible only to the user who uploaded it, even within the same organization. Anyone else's request for it gets a 404, the same as for an id that never existed.

Anthropic clients​

A request with the anthropic-version header gets Anthropic's Files API shapes: the file object carries type, mime_type and size_bytes, times are RFC 3339 strings, and lists page with page and next_page. Anthropic has no purposes, so every upload is stored as user_data, and its list shows only user_data and vision files. Set expiry with expires_in_seconds, from 3600 to 7776000 (90 days).

Upload with the Anthropic SDK, then name the file in a document block:

import os

import anthropic

client = anthropic.Anthropic(base_url="https://api.mindshub.ai", auth_token=os.environ["MINDSHUB_API_KEY"])

with open("report.pdf", "rb") as f:
uploaded = client.files.upload(file=("report.pdf", f, "application/pdf"))

message = client.messages.create(
model="sonnet",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{"type": "document", "source": {"type": "file", "file_id": uploaded.id}},
{"type": "text", "text": "Summarize this report in three bullet points."},
],
}
],
)
print(message.content[0].text)

Older SDK releases upload through client.beta.files and send the files-api-2025-04-14 beta header. That works too: lists then page with before_id and after_id instead of page.

Errors​

All errors use the OpenAI error envelope, {"error": {"message", "type", "param", "code"}}, or Anthropic's with anthropic-version.

StatuscodeWhen
400invalid_valueAn unknown purpose, a bad expiry, or a bad paging parameter.
400unsupported_file_typeThe type is not accepted for this purpose.
400invalid_fileA batch upload that is not .jsonl, or a request that uses a batch file as input.
401Missing or invalid API key.
402wallet_negativeDownloading a batch's output while your organization owes for it.
404file_not_foundNo such file, or it expired, was deleted, or belongs to someone else.
413file_too_largeLarger than the purpose's limit.
503files_api_unavailableThe Files API is temporarily unavailable. Retry.

See Errors for the shared envelope and retry guidance.