Open docs
Reference

Drives, folders, and files API

Organize drives and folders, read and write files, follow changes, and give sandboxes access.

This page covers the routes for drives, folders and files: reading and streaming original files, editing them in place, the change feed, and sandbox tokens. To upload files, see the uploads API.

Use a workspace API key with permission search to read, or read_write to add, change and delete. A signed-in user's access token works too; the user needs a workspace role that allows the action (a viewer reads, an editor or admin also writes). A sandbox token works on its one drive or folder. IDs must belong to the workspace the credential can reach; anything else returns 404 not_found.

See authentication for request headers and response formats, and errors and recovery for failed requests.

Create a drive

curl -X POST "https://api.flashdrive.space/v1/workspaces/$WORKSPACE_ID/drives" \
  -H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
  -H "Flashdrive-Client: my-app/1.0.0" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: create-handbooks-1" \
  -d '{"name":"Handbooks"}'

The 201 response is the new drive. Its status starts as creating; read the drive again until it is ready before you upload to it (failed means setup did not finish). Keep id for later requests, and the drive's ETag for changes.

Resources

Drive (GET /v1/drives/{drive_id}): id, name (1 to 120 characters), version, status (creating, ready or failed) and document_count (the number of files, as a decimal string), with the drive's ETag header.

Folder: id, name (1 to 120 characters), parent_folder_id (null at the drive's top level), version, created_at (null for folders made before dates were recorded), path (folder names joined by /) and depth (1 at the top level, at most 64).

{
  "id": "FOLDER_UUID",
  "name": "Policies",
  "parent_folder_id": null,
  "version": "1",
  "created_at": "2026-11-09T10:00:00Z",
  "path": "Policies",
  "depth": 1
}

File (GET /v1/drives/{drive_id}/documents/{document_id}):

FieldTypeMeaning
idstringThe file's UUID (document_id in routes).
external_idstringYour stable key for the file within the drive, at most 1,024 UTF-8 bytes. Uploads usually set it to the file's relative path.
filenamestring or nullThe file's name.
source_formatstring or nullThe upload format: pdf, docx, txt, md or file; text for text records added as JSON.
source_bytesinteger, string or nullSize of the original file.
text_statustext, none, processingWhether the file's text can be read with the text route.
text_status_reasonstring or nullWhy there is no text: no_text_layer (a PDF or DOCX without text), not_text_format (a file stored as format file), extraction_failed or too_large_to_index (over the text-reading limits).
latest_revisionstringThe current revision. Its strong ETag (such as "3") guards the next change.
content_revisionstringThe revision of the file's current bytes. A read of the original accepts any revision from this one to latest_revision in If-Match. A replacement, move, rename or deletion needs latest_revision.
folder_idstring or nullThe folder, or null at the top level.
metadataobjectYour labels, plus media.* facts the service reads from media files.
operation_id, operation_statestringThe processing operation for the current revision.
kindstring or nullpdf, document, presentation, spreadsheet, image, video, audio or other.
created_atstring or nullWhen the file was first added.
updated_atstring or nullWhen the current revision was accepted (last modified).

Responses can also carry fields not listed here; ignore fields you do not use.

Drives

GET /v1/workspaces/{workspace_id}/drives

List drives. Query: limit (1 to 100, default 50), cursor. Each entry has id, name, version and etag.

POST /v1/workspaces/{workspace_id}/drives

Create a drive. Requires Idempotency-Key. Body: name (required, 1 to 120 characters). 201: the new drive.

GET /v1/drives/{drive_id}

Read a drive. 200: the drive, with its ETag header.

PATCH /v1/drives/{drive_id}

Rename a drive. Requires If-Match. Body: name (1 to 120 characters). 200: the updated drive.

DELETE /v1/drives/{drive_id}

Delete a drive. Requires Idempotency-Key and If-Match. 204 with no body.

  • Without a body, the drive must be empty; otherwise the request returns 409 drive_not_empty.
  • A signed-in person (not an API key or MCP connection) can permanently delete a drive with everything in it by sending {"delete_contents": true, "confirm_name": "<the drive's exact name>"}. Access closes at once. A name that does not match returns 400 invalid_name. Where this option is not offered, the request returns 404 not_found.
  • A drive with work in progress returns 409 drive_busy: wait, then retry with the same key.
  • The workspace's default drive returns 409 default_drive_in_use: choose another default first.

GET /v1/drives/{drive_id}/usage

Read how many files and bytes a drive holds. 200:

FieldTypeMeaning
document_countintegerFiles in the drive, not counting the trash.
source_bytesintegerBytes of those files.
deleted_document_countintegerFiles in the trash that have not been removed yet.
deleted_source_bytesintegerBytes of the files in the trash.
stored_bytesintegersource_bytes plus deleted_source_bytes: what the drive holds towards its size limit.

Every byte count is a whole number of bytes of original file content. Storage is billed in decimal gigabytes: 1 GB is 1,000,000,000 bytes. A deleted file stays in the deleted fields and in stored_bytes until its hour in the trash has passed and it is removed, which can take a little longer than the hour.

A workspace API key or a signed-in member who can read the drive can read its usage. A sandbox token, and a key limited to one drive or to imports, cannot (403 forbidden). A drive that does not support this yet returns 409 not_supported_on_this_drive.

POST /v1/drives/{drive_id}/move

Move a drive to another workspace of the same organization. Requires Idempotency-Key; If-Match is optional. Body: workspace_id (required). Only a signed-in admin of both workspaces can move a drive; API keys and MCP connections cannot. Files are not copied: the old workspace's members and keys lose access, and the new workspace's gain it. A workspace's default drive, or a drive another feature depends on, returns 409 relationship_conflict.

200: id, workspace_id, previous_workspace_id and version.

GET /v1/workspaces/{workspace_id}/default-drive

Read the workspace's default drive: default_drive_id and version.

PUT /v1/workspaces/{workspace_id}/default-drive

Choose the default drive. Requires Idempotency-Key and If-Match. Body: drive_id (required). 200: default_drive_id and version. A drive that is not active in this workspace returns 409 default_drive_unavailable.

Folders

GET /v1/drives/{drive_id}/folders

List the folders directly inside one folder.

QueryMeaning
parent_folder_idThe folder to list; omit for the drive's top level.
sortid (default) or name (case-insensitive).
orderasc (default) or desc.
limit, cursor1 to 100, default 50.

Each entry has id, name, parent_folder_id, version, etag and created_at, and may carry folder_count and file_count (each counted up to 1,000), item_count (up to 2,000) and counts_capped (true when a count stopped at its cap).

POST /v1/drives/{drive_id}/folders

Create a folder. Requires Idempotency-Key.

FieldTypePresenceGuidance
namestringRequired1 to 120 characters.
parent_folder_idstring or nullOptionalThe parent folder; null or omitted for the top level.

201: the folder. A sibling folder with the same name returns 409 duplicate_name. Folders nest at most 64 levels and a folder path holds at most 1,024 bytes; deeper returns 400 folder_too_deep.

POST /v1/drives/{drive_id}/folders/ensure

Create a folder tree in one call. Requires Idempotency-Key. Body: {"paths": ["reports/2026/q3"]}, at most 500 paths of at most 64 names each (5,000 names in all). Missing folders are created and existing ones reused. 200: folders, each with path and id.

GET /v1/drives/{drive_id}/folders/{folder_id}

Read a folder. 200: the folder, with its ETag header.

PATCH /v1/drives/{drive_id}/folders/{folder_id}

Rename a folder, move it under another folder of the same drive, or both. Its files and subfolders go with it. Requires If-Match.

FieldTypePresenceGuidance
namestringOptional1 to 120 characters.
parent_folder_idstring or nullOptionalThe new parent; null moves the folder to the top level.

200: the folder. A folder cannot move into itself or one of its subfolders (409 folder_cycle), past 64 levels (400 folder_too_deep), or onto a sibling's name (409 duplicate_name).

GET /v1/drives/{drive_id}/folders/{folder_id}/summary

Count what is in a folder and everything below it, for example before deleting it. 200: folders (counting this one), documents (files), bytes (size of the files counted) and capped (true when a count stopped at 10,000; the folder holds more).

DELETE /v1/drives/{drive_id}/folders/{folder_id}

Delete a folder. Requires Idempotency-Key and If-Match.

  • An empty folder: 204 with no body. A folder that is not empty returns 409 folder_not_empty.
  • With ?recursive=true, the folder, its subfolders and every file in them: 202 with operation_id, folders_total and documents_total. The folders disappear at once; delete the files with the step route below.

POST /v1/drives/{drive_id}/folder-deletions/{deletion_id}/step

Delete the next batch of up to 200 files of a recursive folder deletion. deletion_id is the operation_id from the 202 above. Send {} with a new Idempotency-Key each time. 200: operation_id, state (running or finished), folders_total, documents_total and documents_deleted. Repeat until state is finished.

Find files

GET /v1/drives/{drive_id}/files

List files by path, or find them with a glob pattern.

QueryMeaning
patternOptional glob, 1 to 500 characters. * and ? stay within a folder, ** crosses folders, [a-z] and {a,b} work. A pattern without / matches file names at any depth.
folder_idOptional folder ID, or root for files at the top level.
limit, cursor1 to 100, default 50. Send next_cursor back with the same other parameters.

200: data, next_cursor and complete. Each entry has document_id, path (the file's external_id), filename, folder_id, format, size_bytes (of the original file), revision and searchable (whether processing has finished). Follow next_cursor until it is null; complete: false means the call stopped before covering the whole drive, and a page can be empty while a cursor remains.

To find conflict and other recovery copies, use GET /v1/drives/{drive_id}/recovery-files.

GET /v1/drives/{drive_id}/documents

List files with their full details. Query: folder_id (omit for all files, root for files at the top level), limit, cursor. Each entry has the file fields.

GET /v1/workspaces/{workspace_id}/documents

List files of one kind across the workspace's drives you can read, newest first. Query: kind (required: pdf, document, presentation, spreadsheet, image, video, audio or other), limit, cursor. Each entry has id, drive_id, drive_name, folder_id, external_id, filename, source_format, source_bytes, kind, latest_revision, metadata, created_at and updated_at.

GET /v1/drives/{drive_id}/documents/{document_id}

Read one file. 200: the file fields, with a strong ETag for latest_revision.

Read files

Read text by lines or bytes

GET /v1/drives/{drive_id}/documents/{document_id}/text reads a file's text. It works for files whose text_status is text: TXT, Markdown, and the text of PDF and DOCX files.

QueryMeaning
start_line, line_countRead by lines: the first line (from 1) and how many, up to 2,000. The byte limit may end a page sooner.
offset, lengthRead by bytes: the first byte (from 0) of the UTF-8 text and how many, up to 32,768.
revisionOptional. Answer 412 stale_version if the file's latest revision is different.

Without parameters, the route returns the first lines. A line read answers mode: "lines" with text, start_line, end_line, next_line and total_lines (null when unknown); a line longer than the byte limit is cut, with line_truncated: true and next_offset where it continues. A byte read answers mode: "bytes" with text, offset (moved forward past a split character), length, next_offset and total_bytes. Both carry document_id and revision.

Read or stream the original file

GET /v1/drives/{drive_id}/documents/{document_id}/source returns the file's current original bytes. Files added as JSON text records have no original and return 404 source_unavailable.

Header or queryMeaning
RangeOne byte range: bytes=a-b, bytes=a- or bytes=-n. Answers 206 with Content-Range. A range that starts at or past the end returns 400 invalid_json with details.field range.
If-RangeServe the range only while this ETag still matches; otherwise the whole file.
If-MatchAnswer 412 stale_version unless the tag names a revision from content_revision to latest_revision, so a reader never mixes two versions of the bytes.
dispositioninline shows images, audio, video, PDF and plain text in place; anything else is an attachment.

HEAD on the same route returns the size and ETag without the body.

For a program that cannot send an Authorization header, such as ffmpeg, a media player or curl in a sandbox, POST /v1/drives/{drive_id}/documents/{document_id}/source/link makes a short-lived URL.

FieldTypePresenceGuidance
ttl_secondsintegerOptional60 to 3,600 seconds; 900 when omitted. A link made from a CLI sign-in lasts at most 300 seconds. Outside the range returns 400 invalid_expiry.
dispositioninline, attachmentOptionalattachment (default) downloads the file; inline shows passive types in place.

201: url, method (GET), expires_at, size_bytes and etag. The URL answers GET and HEAD, with Range, for this one file and the version current when the link was made. After the file changes, it returns 412 stale_version: make a new link. Treat a link like a password. A sandbox token cannot make links.

Change files

Every change to a file checks the revision you read, so nothing is overwritten by accident. If the file changed since, the change is refused with 412 stale_version and nothing is written. Read the file again, then decide whether your change still applies.

To replace a text record, or to move, rename or delete a file, send the revision in If-Match:

  • If-Match holds one entity tag: the file's ETag as you read it, which is its latest_revision in quotation marks, such as "7". A weak tag (W/"7") names the same revision.
  • Without If-Match, the request returns 428 precondition_required.
  • Any other value, such as *, a list of tags or a tag that is not a revision, returns 412 stale_version, as an older revision does.

A text edit and a replacement upload carry the revision in the body, as expected_revision. Changing a folder works the same way with the folder's ETag.

A new file needs an external_id that the drive does not have yet. Adding a text record or preparing an upload with an external_id that already exists returns 428 precondition_required and changes nothing. To change the existing file, read it, then replace that revision.

Edit text in place

POST /v1/drives/{drive_id}/documents/{document_id}/edits replaces exact pieces of text in a TXT or Markdown file, or a file stored as format file whose bytes are UTF-8 text. Requires Idempotency-Key.

{
  "expected_revision": "7",
  "edits": [
    {"old": "Refunds within 30 days.", "new": "Refunds within 45 days."}
  ]
}
FieldTypePresenceGuidance
expected_revisionstringRequiredThe latest_revision you read.
editsarrayRequired1 to 100 edits, applied in order. Each old (non-empty) must occur exactly once in the text as the earlier edits left it; new replaces it.

All edits apply or none do. 202: the edit's upload_id, operation_id, base_revision, size_bytes, sha256 and replacements, plus committed_revision once known. An old that does not occur returns 409 edit_text_not_found; one that occurs more than once returns 409 edit_text_not_unique. A file that is not UTF-8 text returns 400 edit_not_text, and one larger than 8 MiB returns 413 edit_too_large: write it by bytes or upload a new version. A retry with the same key and body replays the first answer.

Write bytes at an offset

PATCH /v1/drives/{drive_id}/documents/{document_id}/source writes the request body into the file's original as a new version. Send Content-Type: application/octet-stream, Content-Length, an Idempotency-Key, and the file's ETag in If-Match.

QueryMeaning
offsetWrite at this byte. At most the current size: a write cannot leave a gap.
append=trueWrite at the end of the file. Give offset or append.
truncateOptional. Cut the file to this many bytes first; at most the current size.

A request body holds at most 64 MiB (413 body_too_large); send larger edits as several requests. The result still counts toward the file size limit (413 file_too_large).

curl -X PATCH "https://api.flashdrive.space/v1/drives/$DRIVE_ID/documents/$DOCUMENT_ID/source?append=true" \
  -H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
  -H "Flashdrive-Client: my-app/1.0.0" \
  -H "Content-Type: application/octet-stream" \
  -H "Idempotency-Key: log-append-1" \
  -H "If-Match: $DOCUMENT_ETAG" \
  --data-binary @new-lines.log

202: upload_id, operation_id, base_revision, offset, size_bytes and sha256, plus committed_revision once known. Retrying with the same key and bytes replays the write; the same key with other bytes returns 409 idempotency_conflict.

Move or rename a file

PATCH /v1/drives/{drive_id}/documents/{document_id} with the file's ETag in If-Match.

FieldTypePresenceGuidance
folder_idstring or nullOptionalThe destination folder; null for the top level.
filenamestringOptionalAt most 255 UTF-8 bytes.

202: operation_id and documents[].revision (the new revision), or 200 with the current revision when nothing changes. A name another file in the destination folder already has returns 409 duplicate_name. The file keeps its external_id.

Replace a file

To replace an uploaded file with new bytes, upload the new version naming its document_id and expected_revision. See replace a specific revision.

Delete a file

DELETE /v1/drives/{drive_id}/documents/{document_id} with Idempotency-Key and the file's ETag in If-Match (428 precondition_required without it). 202: operation_id and documents[].revision. The file moves to trash for one hour before final deletion. Storage reclamation is asynchronous.

Delete many files

POST /v1/drives/{drive_id}/documents/delete deletes up to 1,000 files in one request. Requires Idempotency-Key.

curl -X POST "https://api.flashdrive.space/v1/drives/$DRIVE_ID/documents/delete" \
  -H "Authorization: Bearer $FLASHDRIVE_API_KEY" \
  -H "Flashdrive-Client: my-app/1.0.0" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: clear-drafts-1" \
  -d '{"documents":[{"id":"DOCUMENT_UUID","expected_revision":"3"}]}'
FieldTypePresenceGuidance
documentsarrayRequired1 to 1,000 entries, each file once, in a body of at most 262,144 bytes.
documents[].idstringRequiredThe file's ID.
documents[].expected_revisionstringRequiredThe revision you read, as a decimal string: what If-Match is to a single delete.

202: operation_id, documents (each file's id and the revision the delete left it at), usage and the drive's sequence.

  • The files are deleted together or not at all. If any entry names a file that does not exist, is already deleted or is in another drive, the request returns 404 not_found; if any entry's revision is not the file's, it returns 412 stale_version. In both cases nothing is deleted. Read the files again, correct the list and send it with a new key.
  • Every file goes to the trash and can be restored for one hour, like a single deleted file. Files deleted by one request share its operation_id. Until they are removed they count towards the drive's usage.
  • Sending the same body again with the same Idempotency-Key returns the first answer and deletes nothing more, even if the files were restored in between. The same key with a different body returns 409 idempotency_conflict.
  • More than 1,000 entries, or none, returns 400 invalid_batch_size, with the drive's limit in details.max_items. An entry listed twice returns 400 invalid_json.
  • A sandbox token cannot use this route (403 forbidden); it deletes files one at a time.
  • A drive that does not support this yet returns 409 not_supported_on_this_drive. Delete its files one at a time.

Conflict copies

When two edits meet, nothing is overwritten. The API refuses the later write with 412 stale_version. A mounted drive and flashdrive push handle that refusal for you: your version is kept beside the file as a recovery copy such as name (conflict 20261114T010203Z a1b2c3d4).ext, and the drive's version stays at the original name. Find them with the recovery tool (or GET /v1/drives/{drive_id}/recovery-files). See mount and sync.

To resolve a conflict copy, compare it with the original. Merge the changes into the original (an edit, a byte write or a replacement upload against the original's current revision), then delete the copy. To keep both, rename the copy.

Text records

You can also add text without a file. Text records have no original bytes; they are read with the text route.

POST /v1/drives/{drive_id}/documents

Add text records. Requires Idempotency-Key. The body is JSON with a documents array, or NDJSON (Content-Type: application/x-ndjson) with one record object per line. A request holds 1 to 1,000 records and at most 10,000,000 bytes.

FieldTypePresenceGuidance
external_idstringRequiredYour stable key, at most 1,024 UTF-8 bytes; distinct within the request and new to the drive. If the drive already has any record's external_id, the whole request returns 428 precondition_required; replace that record with PUT instead.
textstringRequiredAt most 2,000,000 UTF-8 bytes.
metadataobjectOptionalFlat labels: at most 64 fields and 8,000 bytes; string, number, boolean or null values.
folder_idstring or nullOptionalThe folder.

202: operation_id and documents (each with id and revision). Follow the operation until it finishes.

The optional X-Ingestion-Mode header takes atomic (the default: the whole request is applied together) or progressive (records are processed in groups, in request order, where your organization has it enabled). Use the same mode when you retry.

PUT /v1/drives/{drive_id}/documents/{document_id}

Replace a text record. Requires Idempotency-Key and If-Match with the ETag you read. Body: text (required), metadata and folder_id. Metadata replaces the earlier labels, and an omitted folder puts the record at the top level. 202: operation_id and documents.

Use PUT only for text records. On an uploaded file it would drop the original bytes and name; replace an uploaded file with an upload instead.

Follow changes

GET /v1/drives/{drive_id}/changes lists what changed in a drive since a cursor, so a sync job or a sandbox can keep up without listing the whole drive again.

  1. Call it without cursor. It returns no changes and a cursor for the drive's current position.
  2. List the drive, then call again with the saved cursor. Optional limit is 1 to 1,000 (default 500).
  3. Apply each change in order, save the new cursor, and call again while has_more is true. Save the cursor even when there were no changes.

Each change has:

FieldMeaning
sequenceThe drive's change sequence, as a decimal string.
kindupsert (the file was added or changed, or moved into your folder) or delete (deleted, or moved out of your folder).
document_id, revisionThe file and its revision.
external_id, folder_id, filenameThe file's key, folder and name; can be null on a delete.
operation_id, operation_stateThe processing operation; the state is null on a delete.

A change may repeat, but none is lost. A cursor works only for the drive and the token scope that made it; another returns 400 invalid_cursor.

Add version=2 to every call to follow the drive's version 2 feed, which also answers the drive's current sequence. A sandbox token limited to a folder must use it: without it, the call returns 410 api_version_retired. The CLI and the Python SDK use it on their own. In that feed, a file that moved out of the folder appears as a delete with only document_id and revision, and folder entries (a kind beginning folder_) may appear. A cursor that cannot be continued returns 410 cursor_reset: start again without a cursor and list the drive or folder.

Sandbox tokens

A sandbox token gives a cloud sandbox, container or job access to one drive (optionally one folder and its subfolders), read or read-write, for a limited time. Use it as the sandbox's API key, for example in FLASHDRIVE_API_KEY. The token is returned once: never print or log it, and revoke it when the job ends. See sandboxes for the setup.

POST /v1/drives/{drive_id}/sandbox-tokens

FieldTypePresenceGuidance
accessread, read_writeRequiredWhat the sandbox can do.
folder_idstring or nullOptionalLimit the token to this folder and below; omit for the whole drive.
ttl_secondsintegerOptional300 to 43,200 seconds (5 minutes to 12 hours); 3,600 when omitted.
namestringOptional1 to 120 characters.

201: the token's details and token, the secret.

Token details: id, name, display_prefix, workspace_id, drive_id, folder_id, access, minted_by (kind user or key, its id, and for a key the user_id who made it), created_at, expires_at, revoked_at and state (live, ended or revoked).

GET /v1/workspaces/{workspace_id}/sandbox-tokens

List tokens, newest first, without secrets. Query: drive_id, state (live, the default, or recent to include tokens that ended or were revoked in the last 30 days), limit (1 to 100, default 50) and cursor.

POST /v1/workspaces/{workspace_id}/sandbox-tokens/{token_id}/extend

Give a live token a new time limit counted from now. Body: ttl_seconds (300 to 43,200; 3,600 when omitted). 200: the token's details.

DELETE /v1/workspaces/{workspace_id}/sandbox-tokens/{token_id}

Revoke a token at once. The sandbox's next request is refused. 200: the token's details.

Rules

  • Make tokens with a workspace API key or as a signed-in user. A read_write token needs a read_write key, or an editor or admin role.
  • A token never lasts longer than the API key that made it, and ends when that key or sign-in ends or its person loses access to the workspace.
  • A token cannot make links or other tokens, and it can call only a fixed set of drive, folder, file, upload, operation and change-feed routes on its own drive. Other routes refuse it.
  • A read_write token cannot write agent instruction files or folders, in any letter case: AGENTS.md, CLAUDE.md, GEMINI.md, SKILL.md, .cursorrules, .windsurfrules, copilot-instructions.md, .github, .claude, .codex, .cursor, .vscode and .agents.
  • Past the workspace's token limits, the API returns 429 auth_rate_limited with Retry-After.
Copyright © 2026