Statistics API
For the dashboard view, see Understand library statistics.
GET /api/v1/statistics returns statistics for the authenticated account's entire personal library. It accepts the same session cookie, X-API-Key, or OAuth bearer credentials as the file API. The response schema is available in the OpenAPI document at /api/docs/json.
curl 'https://files.example.com/api/v1/statistics?topLimit=5' \
-H "X-API-Key: ${CHIBISAFE_API_KEY}"
The MCP tool statistics_get calls this endpoint and returns the same response as text and structured data. Its OAuth grant requires all three scopes: files:read, folders:read, and tags:read.
{
"name": "statistics_get",
"arguments": { "query": { "topLimit": 5 } }
}
topLimit is an integer from 1 through 20, defaulting to 5. It limits each of largestFiles and smallestFiles. It does not limit the inventory used for any calculation. No pagination or file downloads are required.
Response fields
generatedAt,scope, andbasisidentify when the statistics were calculated and their coverage. Scope is alwayspersonal, and basis is alwayscurrent_inventory.summarycontains file count, total bytes, mean bytes per file with metadata, counts with and without metadata, and quarantine count. The mean isnullwhen there are no known file sizes.byCategory,byMimeType, andbyExtensioncontainkey,count, andbytes. Categories follow MIME prefixes:image,video,audio,text,application, orother. MIME values are trimmed and lowercased; missing or blank values becomeapplication/octet-stream. Extensions use the final suffix of the original filename, lowercased without the dot. Files without metadata use the stored filename. An empty key means no extension, including dotfiles such as.env. Breakdowns sort by count descending, then key ascending.uploadscontainsbyDayandbyMonth, each withperiod,count, andbytes, in chronological order. Periods use UTC and omit dates without files.firstUploadAtandlatestUploadAtare timestamps, ornullfor an empty library.busiestDayis the earliest day with the highest count, ornullfor an empty library.largestFilesandsmallestFilescontain UUID, stored filename, original filename, MIME type, bytes insize, upload timestamp, and quarantine flag. Files without metadata are excluded. Ties sort by file ID ascending. No storage paths, uploader IPs, or public media URLs are returned.duplicatescontainsfilesWithHash, duplicategroups,redundantFiles, andredundantBytes. Blank hashes are excluded. Each group contains at least two files with the same stored hash. Redundant counts exclude one copy per group; redundant bytes exclude the largest copy. Current uploads use BLAKE3. The endpoint compares stored hashes without reading file contents.mediacounts images and videos, files with and without positive dimensions, and orientation. A width-to-height ratio from 0.95 through 1.05 isnearSquare; larger ratios are landscape, and smaller ratios are portrait. Non-media dimensions are excluded.organizationcontains total, populated, and empty counts for owned folders and tags, plus distinct owned files in those folders or with those tags. A collection is populated when it directly contains an owned file. Shared folders owned by someone else and descendant tag memberships are excluded. Multiple memberships do not multiply the file counts.sourcescounts files with a nonblanksource, files with a nonblank creator name, and files with any source metadata. Source metadata includes reference, creator name, creator profile URL, title, notes, and original publication date.processingcontains a count for every status:unknown,pending,completed,failed, andskipped. Files without metadata count asunknown.
Inventory coverage
Every query is restricted to the authenticated account, including for administrators. Quarantined files are included because they remain in the library and consume storage. Files without metadata contribute to file counts and upload activity, but contribute zero known bytes. Sizes are bytes without unit conversion or rounding.
The server computes the aggregates in SQLite within one read transaction on a cache miss. REST and MCP share the existing API response cache, including its configured backend and expiry. Cache keys include the account, topLimit, file/folder/tag revisions, and the SQLite change token. Database writes invalidate cached statistics, including metadata and membership changes. generatedAt records when the cached statistics were computed.
REST responses use Cache-Control: private, max-age=0, must-revalidate and support ETag validation. Authentication and OAuth scope checks run before cache access. MCP returns the same cached data through its transport, whose responses remain no-store.
These values describe files still in the library. They do not include deleted files, past storage snapshots, download counts, or bandwidth. Upload timelines show the upload dates and sizes of surviving files; they are not historical storage-growth charts. Duplicate bytes describe redundant inventory, not a measurement of physical disk space that deletion would free.