---
title: "Drives, folders, and files API"
description: "Organize drives and folders, read and write files, follow changes, and give sandboxes access."
canonical_url: "https://docs.flashdrive.space/reference/content-api"
---
# 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](https://docs.flashdrive.space/reference/uploads-api).

Use a [workspace API key](https://docs.flashdrive.space/platform/api-keys) 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](#sandbox-tokens) 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](https://docs.flashdrive.space/reference/authentication) for request headers and response formats, and [errors and recovery](https://docs.flashdrive.space/reference/errors) for failed requests.

## Create a drive

```bash
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).

```json
{
  "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}`):

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        id
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      The file's UUID (<code>
        document_id
      </code>
      
       in routes).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        external_id
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Your 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.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filename
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      The file's name.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        source_format
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      The upload format: <code>
        pdf
      </code>
      
      , <code>
        docx
      </code>
      
      , <code>
        txt
      </code>
      
      , <code>
        md
      </code>
      
       or <code>
        file
      </code>
      
      ; <code>
        text
      </code>
      
       for text records added as JSON.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        source_bytes
      </code>
    </td>
    
    <td>
      integer, string or null
    </td>
    
    <td>
      Size of the original file.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        text_status
      </code>
    </td>
    
    <td>
      <code>
        text
      </code>
      
      , <code>
        none
      </code>
      
      , <code>
        processing
      </code>
    </td>
    
    <td>
      Whether the file's text can be read with the text route.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        text_status_reason
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      Why there is no text: <code>
        no_text_layer
      </code>
      
       (a PDF or DOCX without text), <code>
        not_text_format
      </code>
      
       (a file stored as format <code>
        file
      </code>
      
      ), <code>
        extraction_failed
      </code>
      
       or <code>
        too_large_to_index
      </code>
      
       (over the <a href="https://docs.flashdrive.space/reference/limits#reading-and-writing-files">
        text-reading limits
      </a>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        latest_revision
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      The current revision. Its strong <code>
        ETag
      </code>
      
       (such as <code>
        "3"
      </code>
      
      ) guards the next change.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        content_revision
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      The revision of the file's current bytes. A read of the original accepts any revision from this one to <code>
        latest_revision
      </code>
      
       in <code>
        If-Match
      </code>
      
      . A replacement, move, rename or deletion needs <code>
        latest_revision
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_id
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      The folder, or null at the top level.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        metadata
      </code>
    </td>
    
    <td>
      object
    </td>
    
    <td>
      Your labels, plus <code>
        media.*
      </code>
      
       facts the service reads from media files.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        operation_id
      </code>
      
      , <code>
        operation_state
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      The processing operation for the current revision.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        kind
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      <code>
        pdf
      </code>
      
      , <code>
        document
      </code>
      
      , <code>
        presentation
      </code>
      
      , <code>
        spreadsheet
      </code>
      
      , <code>
        image
      </code>
      
      , <code>
        video
      </code>
      
      , <code>
        audio
      </code>
      
       or <code>
        other
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        created_at
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      When the file was first added.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        updated_at
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      When the current revision was accepted (last modified).
    </td>
  </tr>
</tbody>
</table>

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**:

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        document_count
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      Files in the drive, not counting the trash.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        source_bytes
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      Bytes of those files.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        deleted_document_count
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      Files in the trash that have not been removed yet.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        deleted_source_bytes
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      Bytes of the files in the trash.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stored_bytes
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      <code>
        source_bytes
      </code>
      
       plus <code>
        deleted_source_bytes
      </code>
      
      : what the drive holds towards its <a href="https://docs.flashdrive.space/reference/limits#drive-limits">
        size limit
      </a>
      
      .
    </td>
  </tr>
</tbody>
</table>

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.

<table>
<thead>
  <tr>
    <th>
      Query
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        parent_folder_id
      </code>
    </td>
    
    <td>
      The folder to list; omit for the drive's top level.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        sort
      </code>
    </td>
    
    <td>
      <code>
        id
      </code>
      
       (default) or <code>
        name
      </code>
      
       (case-insensitive).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        order
      </code>
    </td>
    
    <td>
      <code>
        asc
      </code>
      
       (default) or <code>
        desc
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        limit
      </code>
      
      , <code>
        cursor
      </code>
    </td>
    
    <td>
      1 to 100, default 50.
    </td>
  </tr>
</tbody>
</table>

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`.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        name
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      1 to 120 characters.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        parent_folder_id
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      The parent folder; null or omitted for the top level.
    </td>
  </tr>
</tbody>
</table>

**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`.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        name
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      1 to 120 characters.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        parent_folder_id
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      The new parent; null moves the folder to the top level.
    </td>
  </tr>
</tbody>
</table>

**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.

<table>
<thead>
  <tr>
    <th>
      Query
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        pattern
      </code>
    </td>
    
    <td>
      Optional glob, 1 to 500 characters. <code>
        *
      </code>
      
       and <code>
        ?
      </code>
      
       stay within a folder, <code>
        **
      </code>
      
       crosses folders, <code>
        [a-z]
      </code>
      
       and <code>
        {a,b}
      </code>
      
       work. A pattern without <code>
        /
      </code>
      
       matches file names at any depth.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_id
      </code>
    </td>
    
    <td>
      Optional folder ID, or <code>
        root
      </code>
      
       for files at the top level.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        limit
      </code>
      
      , <code>
        cursor
      </code>
    </td>
    
    <td>
      1 to 100, default 50. Send <code>
        next_cursor
      </code>
      
       back with the same other parameters.
    </td>
  </tr>
</tbody>
</table>

**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](#resources).

### 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](#resources), 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.

<table>
<thead>
  <tr>
    <th>
      Query
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        start_line
      </code>
      
      , <code>
        line_count
      </code>
    </td>
    
    <td>
      Read by lines: the first line (from 1) and how many, up to 2,000. The byte limit may end a page sooner.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        offset
      </code>
      
      , <code>
        length
      </code>
    </td>
    
    <td>
      Read by bytes: the first byte (from 0) of the UTF-8 text and how many, up to 32,768.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        revision
      </code>
    </td>
    
    <td>
      Optional. Answer 412 <code>
        stale_version
      </code>
      
       if the file's latest revision is different.
    </td>
  </tr>
</tbody>
</table>

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`.

<table>
<thead>
  <tr>
    <th>
      Header or query
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        Range
      </code>
    </td>
    
    <td>
      One byte range: <code>
        bytes=a-b
      </code>
      
      , <code>
        bytes=a-
      </code>
      
       or <code>
        bytes=-n
      </code>
      
      . Answers 206 with <code>
        Content-Range
      </code>
      
      . A range that starts at or past the end returns 400 <code>
        invalid_json
      </code>
      
       with <code>
        details.field
      </code>
      
       <code>
        range
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        If-Range
      </code>
    </td>
    
    <td>
      Serve the range only while this ETag still matches; otherwise the whole file.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        If-Match
      </code>
    </td>
    
    <td>
      Answer 412 <code>
        stale_version
      </code>
      
       unless the tag names a revision from <code>
        content_revision
      </code>
      
       to <code>
        latest_revision
      </code>
      
      , so a reader never mixes two versions of the bytes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        disposition
      </code>
    </td>
    
    <td>
      <code>
        inline
      </code>
      
       shows images, audio, video, PDF and plain text in place; anything else is an attachment.
    </td>
  </tr>
</tbody>
</table>

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

### Make a signed link

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.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        ttl_seconds
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      60 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 <code>
        invalid_expiry
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        disposition
      </code>
    </td>
    
    <td>
      <code>
        inline
      </code>
      
      , <code>
        attachment
      </code>
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      <code>
        attachment
      </code>
      
       (default) downloads the file; <code>
        inline
      </code>
      
       shows passive types in place.
    </td>
  </tr>
</tbody>
</table>

**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`.

```json
{
  "expected_revision": "7",
  "edits": [
    {"old": "Refunds within 30 days.", "new": "Refunds within 45 days."}
  ]
}
```

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        expected_revision
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      The <code>
        latest_revision
      </code>
      
       you read.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        edits
      </code>
    </td>
    
    <td>
      array
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      1 to 100 edits, applied in order. Each <code>
        old
      </code>
      
       (non-empty) must occur exactly once in the text as the earlier edits left it; <code>
        new
      </code>
      
       replaces it.
    </td>
  </tr>
</tbody>
</table>

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`.

<table>
<thead>
  <tr>
    <th>
      Query
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        offset
      </code>
    </td>
    
    <td>
      Write at this byte. At most the current size: a write cannot leave a gap.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        append=true
      </code>
    </td>
    
    <td>
      Write at the end of the file. Give <code>
        offset
      </code>
      
       or <code>
        append
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        truncate
      </code>
    </td>
    
    <td>
      Optional. Cut the file to this many bytes first; at most the current size.
    </td>
  </tr>
</tbody>
</table>

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](https://docs.flashdrive.space/reference/limits) (413 `file_too_large`).

```bash
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`.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        folder_id
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      The destination folder; null for the top level.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        filename
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      At most 255 UTF-8 bytes.
    </td>
  </tr>
</tbody>
</table>

**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](https://docs.flashdrive.space/reference/uploads-api#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`.

```bash
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"}]}'
```

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        documents
      </code>
    </td>
    
    <td>
      array
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      1 to 1,000 entries, each file once, in a body of at most 262,144 bytes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        documents[].id
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      The file's ID.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        documents[].expected_revision
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      The revision you read, as a decimal string: what <code>
        If-Match
      </code>
      
       is to a single delete.
    </td>
  </tr>
</tbody>
</table>

**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](#delete-a-file). Files deleted by one request share its `operation_id`. Until they are removed they count towards the drive's [usage](#get-v2drivesdrive_idusage).
- 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](#delete-a-file).
- 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](https://docs.flashdrive.space/cli/mount-and-sync).

To resolve a conflict copy, compare it with the original. Merge the changes into the original (an [edit](#edit-text-in-place), a [byte write](#write-bytes-at-an-offset) or a [replacement upload](https://docs.flashdrive.space/reference/uploads-api#replace-a-specific-revision) against the original's current revision), then [delete](#delete-a-file) the copy. To keep both, [rename](#move-or-rename-a-file) 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.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        external_id
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      Your 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 <code>
        external_id
      </code>
      
      , the whole request returns 428 <code>
        precondition_required
      </code>
      
      ; replace that record with <code>
        PUT
      </code>
      
       instead.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        text
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      At most 2,000,000 UTF-8 bytes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        metadata
      </code>
    </td>
    
    <td>
      object
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      Flat labels: at most 64 fields and 8,000 bytes; string, number, boolean or null values.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_id
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      The folder.
    </td>
  </tr>
</tbody>
</table>

**202**: `operation_id` and `documents` (each with `id` and `revision`). Follow the [operation](https://docs.flashdrive.space/reference/uploads-api#get-v2workspacesworkspace_idoperationsoperation_id) 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](https://docs.flashdrive.space/reference/uploads-api#replace-a-specific-revision) 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:

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        sequence
      </code>
    </td>
    
    <td>
      The drive's change sequence, as a decimal string.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        kind
      </code>
    </td>
    
    <td>
      <code>
        upsert
      </code>
      
       (the file was added or changed, or moved into your folder) or <code>
        delete
      </code>
      
       (deleted, or moved out of your folder).
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        document_id
      </code>
      
      , <code>
        revision
      </code>
    </td>
    
    <td>
      The file and its revision.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        external_id
      </code>
      
      , <code>
        folder_id
      </code>
      
      , <code>
        filename
      </code>
    </td>
    
    <td>
      The file's key, folder and name; can be null on a <code>
        delete
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        operation_id
      </code>
      
      , <code>
        operation_state
      </code>
    </td>
    
    <td>
      The processing operation; the state is null on a <code>
        delete
      </code>
      
      .
    </td>
  </tr>
</tbody>
</table>

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](https://docs.flashdrive.space/cli/sandboxes) for the setup.

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

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Presence
    </th>
    
    <th>
      Guidance
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        access
      </code>
    </td>
    
    <td>
      <code>
        read
      </code>
      
      , <code>
        read_write
      </code>
    </td>
    
    <td>
      Required
    </td>
    
    <td>
      What the sandbox can do.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_id
      </code>
    </td>
    
    <td>
      string or null
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      Limit the token to this folder and below; omit for the whole drive.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        ttl_seconds
      </code>
    </td>
    
    <td>
      integer
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      300 to 43,200 seconds (5 minutes to 12 hours); 3,600 when omitted.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        name
      </code>
    </td>
    
    <td>
      string
    </td>
    
    <td>
      Optional
    </td>
    
    <td>
      1 to 120 characters.
    </td>
  </tr>
</tbody>
</table>

**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`.


## Sitemap

See the full [sitemap](https://docs.flashdrive.space/sitemap.md) for all pages.
