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
| Method | Path | What it does |
|---|---|---|
POST | /v1/files | Upload a file |
GET | /v1/files | List your files |
GET | /v1/files/{file_id} | Retrieve a file's metadata |
GET | /v1/files/{file_id}/content | Download a file's bytes |
DELETE | /v1/files/{file_id} | Delete a file |
Quick example
Upload a PDF, then ask about it.
- Python
- TypeScript
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)
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.mindshub.ai/v1", apiKey: process.env.MINDSHUB_API_KEY });
const uploaded = await client.files.create({ file: fs.createReadStream("report.pdf"), purpose: "user_data" });
const response = await 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." },
],
},
],
});
console.log(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.
purpose | For | Types | Size limit |
|---|---|---|---|
user_data | Documents and images you refer to in a request | PDF, plain text, Markdown, CSV, JSON, PNG, JPEG, GIF, WebP | 50 MB |
vision | Images you refer to in a request | PNG, JPEG, GIF, WebP | 50 MB |
batch | Input to a batch job | .jsonl | 200 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:
| Field | Value |
|---|---|
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
}
| Field | Meaning |
|---|---|
id | Pass it as file_id in a request. |
bytes | Size in bytes. |
created_at, expires_at | Unix seconds. expires_at is null for a file that never expires. |
purpose | What it was uploaded as. batch_output marks a batch job's results. |
status | Always 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:
| API | Document | Image |
|---|---|---|
| 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": "…"}} |
- Chat Completions
- Responses
- Messages
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?"},
],
}
],
)
response = client.responses.create(
model="mindshub_air",
input=[
{
"role": "user",
"content": [
{"type": "input_image", "file_id": "file-0193a6f2c1d47e8b9a2f5c6d7e8f9a0b"},
{"type": "input_text", "text": "What is in this picture?"},
],
}
],
)
import os
import anthropic
claude = anthropic.Anthropic(base_url="https://api.mindshub.ai", auth_token=os.environ["MINDSHUB_API_KEY"])
message = claude.messages.create(
model="sonnet",
max_tokens=1024,
messages=[
{
"role": "user",
"content": [
{"type": "document", "source": {"type": "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_dataandvisionfiles can be used as inputs. Abatchfile is for batch jobs only.
Listing, downloading and deleting
- List: newest first. Filter with
purpose, and page withafterset to the previous page'slast_idwhilehas_moreistrue. The SDKs page for you. - Download:
GET /v1/files/{file_id}/contentreturns the bytes with the file's original type and name. A batch job's output file is held, with a402, 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:
- Python
- TypeScript
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)
import { createReadStream } from "node:fs";
import Anthropic, { toFile } from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://api.mindshub.ai", authToken: process.env.MINDSHUB_API_KEY });
const uploaded = await client.files.upload({
file: await toFile(createReadStream("report.pdf"), "report.pdf", { type: "application/pdf" }),
});
const message = await 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." },
],
},
],
});
console.log(message.content[0].type === "text" ? 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.
| Status | code | When |
|---|---|---|
400 | invalid_value | An unknown purpose, a bad expiry, or a bad paging parameter. |
400 | unsupported_file_type | The type is not accepted for this purpose. |
400 | invalid_file | A batch upload that is not .jsonl, or a request that uses a batch file as input. |
401 | Missing or invalid API key. | |
402 | wallet_negative | Downloading a batch's output while your organization owes for it. |
404 | file_not_found | No such file, or it expired, was deleted, or belongs to someone else. |
413 | file_too_large | Larger than the purpose's limit. |
503 | files_api_unavailable | The Files API is temporarily unavailable. Retry. |
See Errors for the shared envelope and retry guidance.