{
  "openapi": "3.1.0",
  "info": {
    "title": "vylk HTTP API",
    "version": "3.1.3",
    "description": "The vylk server has an HTTP API. The vylk web app uses it, and you can use it to build your own client. Send requests to your own server, for example `http://localhost:8080`. The API has no version prefix. Test your client against each vylk release that you support."
  },
  "servers": [
    {
      "url": "/",
      "description": "Your VYLK instance"
    }
  ],
  "security": [
    {
      "session": []
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "Sign in, sign out, and check a session."
    },
    {
      "name": "Devices",
      "description": "List signed-in devices and sign them out."
    },
    {
      "name": "Notes",
      "description": "Read, save, and delete single notes, and search a plaintext vault."
    },
    {
      "name": "Sync",
      "description": "Pull changes, fetch notes in batches, push queued edits, and receive change events."
    },
    {
      "name": "Preferences",
      "description": "Read and replace the preferences that every device shares."
    },
    {
      "name": "Encryption",
      "description": "Read the vault status and keys, change credentials, and reset an encrypted vault."
    },
    {
      "name": "Migration",
      "description": "Convert a plaintext vault to an encrypted vault. The routes run in the order listed."
    },
    {
      "name": "AI",
      "description": "Configure AI providers and edit notes with AI. Every route needs the `aiEnabled` preference. The [client protocol](client-protocol.md#byok-ai) describes the request flow and its limits."
    }
  ],
  "paths": {
    "/api/login": {
      "post": {
        "operationId": "login",
        "tags": [
          "Authentication"
        ],
        "summary": "Sign in",
        "description": "Creates a session for this device. Call `GET /api/vault/bootstrap` first to learn the vault mode. When `mode` is `legacy` or `preparing`, send `password`. When `mode` is `encrypted` or `cleaning`, omit `password` and send `proof` or `recovery_proof`. If you send both proofs, the server checks only `recovery_proof`. The body limit is 16 KiB.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Login"
              },
              "example": {
                "password": "your-server-password"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in. The response sets the `session` and `vylk-device` cookies.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResult"
                },
                "example": {
                  "instance_id": "95e9c24f3f492f0b776fa9f58b5837f0",
                  "ok": true,
                  "revision": "3a7403423c47610d",
                  "version": "3.1.2"
                }
              }
            },
            "headers": {
              "Set-Cookie": {
                "description": "Two cookies: `session` and `vylk-device`. Store both.",
                "schema": {
                  "type": "string"
                },
                "example": [
                  "vylk-device=96bfb40c6de6030d4179116bd0231d99; Path=/; Max-Age=31536000; HttpOnly; SameSite=Lax",
                  "session=3fae6c640760d12fcd77c5f3d25f02fb; Path=/; Max-Age=15552000; HttpOnly; SameSite=Lax"
                ]
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_credentials": {
                    "summary": "The password or proof is wrong.",
                    "value": {
                      "code": "invalid_credentials",
                      "error": "wrong password"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "login_rate_limited": {
                    "summary": "Too many failed attempts from this client address. Wait for the number of seconds in `retry_after`.",
                    "value": {
                      "error": "too many login attempts",
                      "code": "login_rate_limited",
                      "retry_after": 60
                    }
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before the next attempt.",
                "schema": {
                  "type": "string"
                },
                "example": "60"
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "create_session_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not create session",
                      "code": "create_session_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/logout": {
      "post": {
        "operationId": "logout",
        "tags": [
          "Authentication"
        ],
        "summary": "Sign out",
        "description": "Signs out this device. The server revokes every session that shares this device's `vylk-device` cookie, so other tabs of the same browser profile sign out too. The response clears the `session` cookie even when the session is missing or expired. Sign-out does not upload pending edits. Keep them on the client.",
        "security": [],
        "responses": {
          "204": {
            "description": "Signed out. The response has no body.",
            "headers": {
              "Set-Cookie": {
                "description": "Expires the `session` cookie.",
                "schema": {
                  "type": "string"
                },
                "example": "session=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax"
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "logout_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not sign out device",
                      "code": "logout_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/check": {
      "get": {
        "operationId": "checkSession",
        "tags": [
          "Authentication"
        ],
        "summary": "Get the session status",
        "description": "Returns the server identity and vault state for a valid session. Before you resume sync, compare `instance_id`, `vault_mode`, and `vault_epoch` with the values that you stored. `revision` identifies the build of the web app, not a note revision.",
        "responses": {
          "200": {
            "description": "The session is valid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckResult"
                },
                "example": {
                  "instance_id": "95e9c24f3f492f0b776fa9f58b5837f0",
                  "ok": true,
                  "revision": "3a7403423c47610d",
                  "vault_epoch": 0,
                  "vault_mode": "legacy",
                  "version": "3.1.2"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_status_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read vault status",
                      "code": "vault_status_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/devices": {
      "get": {
        "operationId": "listDevices",
        "tags": [
          "Devices"
        ],
        "summary": "List devices",
        "description": "Lists the devices that have an active session, most recently active first. All tabs of one browser profile share a `vylk-device` cookie and appear as one device. The server updates `last_seen_at` at most every few minutes, so the value is approximate.",
        "responses": {
          "200": {
            "description": "The active devices.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "devices"
                  ],
                  "properties": {
                    "devices": {
                      "type": "array",
                      "description": "Active devices.",
                      "items": {
                        "$ref": "#/components/schemas/Device"
                      }
                    }
                  }
                },
                "example": {
                  "devices": [
                    {
                      "id": "96bfb40c6de6030d4179116bd0231d99",
                      "name": "Chrome on Linux",
                      "last_seen_at": "2026-11-22T02:41:08Z",
                      "current": true
                    },
                    {
                      "id": "bab973f17508af32c70e314d45d17307",
                      "name": "Chrome on Android",
                      "last_seen_at": "2026-11-22T02:41:08Z",
                      "current": false
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "devices_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not load devices",
                      "code": "devices_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/devices/{id}": {
      "delete": {
        "operationId": "revokeDevice",
        "tags": [
          "Devices"
        ],
        "summary": "Sign out a device",
        "description": "Revokes every session of a device. The request succeeds for a well-formed ID that matches no device. Revocation cannot delete notes or keys that the device already stores. An offline device learns about the revocation when it reconnects.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Device ID from `GET /api/devices`. This is not the sync queue `device_id`.",
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{32}$"
            },
            "example": "bab973f17508af32c70e314d45d17307"
          }
        ],
        "responses": {
          "204": {
            "description": "The device is signed out. The response has no body."
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_device": {
                    "summary": "`id` is not 32 lowercase hexadecimal characters.",
                    "value": {
                      "code": "invalid_device",
                      "error": "invalid device"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "device_signout_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not sign out device",
                      "code": "device_signout_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/notes": {
      "get": {
        "operationId": "listNotes",
        "tags": [
          "Notes"
        ],
        "summary": "List notes",
        "description": "Lists note summaries without note content, most recently updated first. Without `limit`, the response is an array of every note. With `limit`, the response is one page, and `nextCursor` points to the next page. In a plaintext vault, `nextCursor` is absent on the last page. In an encrypted vault, it is an empty string. In an encrypted vault, each summary holds an encrypted `summary` envelope in place of `title`, `tags`, and `filename`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Page size. In a plaintext vault, the range is 1 to 100 and an empty value means no limit. In an encrypted vault, the range is 1 to 500 and an empty value is an error.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            },
            "example": 1
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "`nextCursor` from the previous page. Treat the value as opaque.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tag",
            "in": "query",
            "description": "Returns only notes with this exact tag. Plaintext vault only.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The note summaries.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "title": "Without limit",
                      "type": "array",
                      "description": "Every note.",
                      "items": {
                        "$ref": "#/components/schemas/NoteSummary"
                      }
                    },
                    {
                      "$ref": "#/components/schemas/NotesPage",
                      "title": "With limit"
                    }
                  ]
                },
                "example": {
                  "notes": [
                    {
                      "id": "trip-notes",
                      "title": "Trip notes",
                      "filename": "trip-notes.md",
                      "tags": "travel",
                      "pinned": false,
                      "created_at": "2026-11-22T02:41:07Z",
                      "updated_at": "2026-11-22T02:41:07Z",
                      "revision": 2
                    }
                  ],
                  "nextCursor": "MjAyNi0xMS0yMlQwMjo0MTowN1oAdHJpcC1ub3Rlcw"
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_page_limit": {
                    "summary": "`limit` is not an integer in the allowed range.",
                    "value": {
                      "error": "invalid page limit",
                      "code": "invalid_page_limit"
                    }
                  },
                  "invalid_cursor": {
                    "summary": "`cursor` is not a value from a previous page.",
                    "value": {
                      "error": "invalid cursor",
                      "code": "invalid_cursor"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "client_search_required": {
                    "summary": "The vault is encrypted. Decrypt the note summaries and search or filter them on the client.",
                    "value": {
                      "error": "filter tags on this device",
                      "code": "client_search_required"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "list_notes_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not list notes",
                      "code": "list_notes_failed"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "saveNote",
        "tags": [
          "Notes"
        ],
        "summary": "Save a note",
        "description": "Creates a note or replaces a note completely. Send the whole note each time, not a change. To update a note, send its `id` and the `base_revision` that you last read. To create a note with an ID that you chose, send `base_revision` 0. In a plaintext vault, you can omit `id`, and the server generates one. In an encrypted vault, you must send `id`, `base_revision`, `epoch`, `summary`, and `body`. The response returns the note summary without its content. A new note also returns status 200. The body limit is 4 MiB in a plaintext vault and 8 MiB in an encrypted vault. Clients that queue offline edits use `POST /api/sync/push` instead.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/SaveNote"
                  },
                  {
                    "$ref": "#/components/schemas/SaveEncryptedNote"
                  }
                ]
              },
              "example": {
                "id": "trip-notes",
                "base_revision": 1,
                "title": "Trip notes",
                "tags": "travel",
                "content": "# Trip notes\n\nBook the train. Pack light.\n"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The note is saved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoteSummary"
                },
                "example": {
                  "id": "trip-notes",
                  "title": "Trip notes",
                  "filename": "trip-notes.md",
                  "tags": "travel",
                  "pinned": false,
                  "created_at": "2026-11-22T02:41:07Z",
                  "updated_at": "2026-11-22T02:41:07Z",
                  "revision": 2
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "base_revision_required": {
                    "summary": "`id` is present and `base_revision` is missing. Plaintext vault only.",
                    "value": {
                      "code": "base_revision_required",
                      "error": "base_revision is required for an existing note"
                    }
                  },
                  "invalid_note_id": {
                    "summary": "`id` does not match `^[A-Za-z0-9_-]{1,64}$`. Plaintext vault only.",
                    "value": {
                      "error": "invalid note id",
                      "code": "invalid_note_id"
                    }
                  },
                  "note_metadata_too_long": {
                    "summary": "`title` exceeds 512 bytes or `tags` exceeds 4096 bytes. Plaintext vault only.",
                    "value": {
                      "error": "title or tags are too long",
                      "code": "note_metadata_too_long"
                    }
                  },
                  "invalid_encrypted_note": {
                    "summary": "A required field is missing or an envelope is malformed. Encrypted vault only.",
                    "value": {
                      "error": "invalid encrypted note",
                      "code": "invalid_encrypted_note"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_revision_conflict": {
                    "summary": "`base_revision` is not the current revision. In a plaintext vault, `current_revision` holds the current revision.",
                    "value": {
                      "code": "note_revision_conflict",
                      "current_revision": 2,
                      "error": "note changed on another device",
                      "note_id": "trip-notes"
                    }
                  },
                  "stale_vault_epoch": {
                    "summary": "`epoch` is not the current vault epoch. Read `GET /api/vault/keys` again. Encrypted vault only.",
                    "value": {
                      "code": "stale_vault_epoch",
                      "error": "refresh vault keys before saving"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_in_progress": {
                    "summary": "Encryption setup is converting notes. Note writes are paused until it finishes.",
                    "value": {
                      "error": "note writes are paused for encryption",
                      "code": "vault_migration_in_progress"
                    }
                  },
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_file_recovery_blocked": {
                    "summary": "An interrupted file operation needs recovery before this note can change. Keep the change and retry later.",
                    "value": {
                      "error": "note file recovery requires attention",
                      "code": "note_file_recovery_blocked",
                      "note_id": "trip-notes"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "save_note_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "write failed",
                      "code": "save_note_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/notes/{id}": {
      "get": {
        "operationId": "getNote",
        "tags": [
          "Notes"
        ],
        "summary": "Get a note",
        "description": "Returns one note with its content. In an encrypted vault, the note holds `summary` and `body` envelopes in place of `title`, `tags`, `filename`, and `content`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/NoteID"
          },
          {
            "$ref": "#/components/parameters/VaultProtocol"
          }
        ],
        "responses": {
          "200": {
            "description": "The note.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompleteNote"
                },
                "example": {
                  "id": "trip-notes",
                  "title": "Trip notes",
                  "filename": "trip-notes.md",
                  "tags": "travel",
                  "pinned": false,
                  "created_at": "2026-11-22T02:41:07Z",
                  "updated_at": "2026-11-22T02:41:07Z",
                  "revision": 2,
                  "content": "# Trip notes\n\nBook the train. Pack light.\n"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_not_found": {
                    "summary": "No note has this ID.",
                    "value": {
                      "code": "note_not_found",
                      "error": "not found"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "load_note_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not load note",
                      "code": "load_note_failed"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteNote",
        "tags": [
          "Notes"
        ],
        "summary": "Delete a note",
        "description": "Deletes a note at a known revision. A second identical request returns 404 or 409. It does not succeed again. Clients that queue offline edits use a `note.delete` operation in `POST /api/sync/push` instead.",
        "parameters": [
          {
            "$ref": "#/components/parameters/NoteID"
          },
          {
            "$ref": "#/components/parameters/VaultProtocol"
          },
          {
            "name": "base_revision",
            "in": "query",
            "description": "The revision that you last read.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 1
            },
            "required": true,
            "example": 1
          }
        ],
        "responses": {
          "204": {
            "description": "The note is deleted. The response has no body."
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "base_revision_required": {
                    "summary": "`base_revision` is missing.",
                    "value": {
                      "code": "base_revision_required",
                      "error": "base_revision is required for deletion"
                    }
                  },
                  "invalid_note_revision": {
                    "summary": "`base_revision` is not a positive integer.",
                    "value": {
                      "error": "invalid note revision",
                      "code": "invalid_note_revision"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_not_found": {
                    "summary": "No note has this ID.",
                    "value": {
                      "error": "not found",
                      "code": "note_not_found"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_revision_conflict": {
                    "summary": "`base_revision` is not the current revision. In a plaintext vault, `current_revision` holds the current revision.",
                    "value": {
                      "code": "note_revision_conflict",
                      "current_revision": 1,
                      "error": "note changed on another device",
                      "note_id": "32366a862b3447c4551e8bc031bcdbad"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_in_progress": {
                    "summary": "Encryption setup is converting notes. Note writes are paused until it finishes.",
                    "value": {
                      "error": "note writes are paused for encryption",
                      "code": "vault_migration_in_progress"
                    }
                  },
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  },
                  "vault_unavailable": {
                    "summary": "The encrypted vault is not ready. Encrypted vault only.",
                    "value": {
                      "error": "encrypted vault is unavailable",
                      "code": "vault_unavailable"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_file_recovery_blocked": {
                    "summary": "An interrupted file operation needs recovery before this note can change. Keep the change and retry later.",
                    "value": {
                      "error": "note file recovery requires attention",
                      "code": "note_file_recovery_blocked",
                      "note_id": "trip-notes"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "delete_note_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "delete failed",
                      "code": "delete_note_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "operationId": "searchNotes",
        "tags": [
          "Notes"
        ],
        "summary": "Search notes",
        "description": "Searches note titles and tags, not note content. Plaintext vault only. The server splits `q` at white space, uses the first eight words, and matches notes that contain every word as a prefix. The response holds at most 50 summaries, best match first. An empty `q` returns an empty array. A query without matches returns `null`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          },
          {
            "name": "q",
            "in": "query",
            "description": "Search text, at most 256 bytes.",
            "schema": {
              "type": "string"
            },
            "example": "trip"
          }
        ],
        "responses": {
          "200": {
            "description": "The matching note summaries, or `null`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": [
                    "array",
                    "null"
                  ],
                  "items": {
                    "$ref": "#/components/schemas/PlainNote"
                  }
                },
                "example": [
                  {
                    "id": "trip-notes",
                    "title": "Trip notes",
                    "filename": "trip-notes.md",
                    "tags": "travel",
                    "pinned": false,
                    "created_at": "2026-11-22T02:41:07Z",
                    "updated_at": "2026-11-22T02:41:07Z",
                    "revision": 2
                  }
                ]
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "search_query_too_long": {
                    "summary": "`q` exceeds 256 bytes after the server trims white space.",
                    "value": {
                      "error": "search query is too long",
                      "code": "search_query_too_long"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "client_search_required": {
                    "summary": "The vault is encrypted. Decrypt the note summaries and search or filter them on the client.",
                    "value": {
                      "error": "search encrypted notes on this device",
                      "code": "client_search_required"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "search_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not search notes",
                      "code": "search_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/tags": {
      "get": {
        "operationId": "listTags",
        "tags": [
          "Notes"
        ],
        "summary": "List tags",
        "description": "Lists every tag in use, sorted without regard to case. Plaintext vault only.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          }
        ],
        "responses": {
          "200": {
            "description": "The tags.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "example": [
                  "errands",
                  "home",
                  "travel"
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "client_search_required": {
                    "summary": "The vault is encrypted. Decrypt the note summaries and search or filter them on the client.",
                    "value": {
                      "error": "search encrypted notes on this device",
                      "code": "client_search_required"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "list_tags_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not list tags",
                      "code": "list_tags_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sync": {
      "get": {
        "operationId": "pullChanges",
        "tags": [
          "Sync"
        ],
        "summary": "List changes",
        "description": "Returns the note changes after sequence `since`, oldest first. Each change names a note and its new revision. A change with `deleted` true is a deletion. Save `nextSequence` only after you apply the changes locally, and pass it as `since` in the next request. While `hasMore` is true, request the next page. When `resetRequired` is true, the server no longer has the changes after `since`. Rebuild your copy from `GET /api/notes`, and keep your pending edits. The [client protocol](client-protocol.md) describes the full sync procedure.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          },
          {
            "name": "since",
            "in": "query",
            "description": "Sequence of the last change that you applied. The response starts after it.",
            "schema": {
              "type": "integer",
              "format": "int64",
              "minimum": 0,
              "default": 0
            },
            "example": 0
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of changes.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            },
            "example": 100
          }
        ],
        "responses": {
          "200": {
            "description": "A page of changes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangesPage"
                },
                "example": {
                  "changes": [
                    {
                      "sequence": 1,
                      "note_id": "32366a862b3447c4551e8bc031bcdbad",
                      "revision": 1,
                      "deleted": false,
                      "changed_at": "2026-11-22T02:41:07Z"
                    },
                    {
                      "sequence": 2,
                      "note_id": "trip-notes",
                      "revision": 1,
                      "deleted": false,
                      "changed_at": "2026-11-22T02:41:07Z"
                    },
                    {
                      "sequence": 3,
                      "note_id": "trip-notes",
                      "revision": 2,
                      "deleted": false,
                      "changed_at": "2026-11-22T02:41:07Z"
                    }
                  ],
                  "nextSequence": 3,
                  "hasMore": false,
                  "instance_id": "95e9c24f3f492f0b776fa9f58b5837f0"
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_sync_sequence": {
                    "summary": "`since` is not a non-negative integer.",
                    "value": {
                      "error": "invalid sync sequence",
                      "code": "invalid_sync_sequence"
                    }
                  },
                  "invalid_page_limit": {
                    "summary": "`limit` is not an integer from 1 to 500.",
                    "value": {
                      "error": "invalid page limit",
                      "code": "invalid_page_limit"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "list_sync_changes_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not list sync changes",
                      "code": "list_sync_changes_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sync/notes": {
      "get": {
        "operationId": "fetchChangedNotes",
        "tags": [
          "Sync"
        ],
        "summary": "Get notes by ID",
        "description": "Returns up to 25 complete notes. The server counts IDs before it removes duplicates. IDs that match no note appear in `missing`. A returned note can have a newer revision than the change that you are applying. Do not let it replace a pending local edit.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          },
          {
            "name": "ids",
            "in": "query",
            "description": "Comma-separated note IDs, without spaces. An empty value returns empty arrays.",
            "schema": {
              "type": "string"
            },
            "example": "trip-notes,deleted-note"
          }
        ],
        "responses": {
          "200": {
            "description": "The notes that exist and the IDs that do not.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "notes",
                    "missing"
                  ],
                  "properties": {
                    "notes": {
                      "type": "array",
                      "description": "Complete notes.",
                      "items": {
                        "$ref": "#/components/schemas/CompleteNote"
                      }
                    },
                    "missing": {
                      "type": "array",
                      "description": "Requested IDs that match no note.",
                      "items": {
                        "$ref": "#/components/schemas/ID"
                      }
                    }
                  }
                },
                "example": {
                  "missing": [
                    "deleted-note"
                  ],
                  "notes": [
                    {
                      "id": "trip-notes",
                      "title": "Trip notes",
                      "filename": "trip-notes.md",
                      "tags": "travel",
                      "pinned": false,
                      "created_at": "2026-11-22T02:41:07Z",
                      "updated_at": "2026-11-22T02:41:07Z",
                      "revision": 2,
                      "content": "# Trip notes\n\nBook the train. Pack light.\n"
                    },
                    {
                      "id": "32366a862b3447c4551e8bc031bcdbad",
                      "title": "Groceries",
                      "filename": "32366a862b3447c4551e8bc031bcdbad.md",
                      "tags": "home,errands",
                      "pinned": false,
                      "created_at": "2026-11-22T02:41:07Z",
                      "updated_at": "2026-11-22T02:41:07Z",
                      "revision": 1,
                      "content": "- Milk\n- Eggs\n"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "too_many_note_ids": {
                    "summary": "`ids` holds more than 25 IDs.",
                    "value": {
                      "error": "too many note ids",
                      "code": "too_many_note_ids"
                    }
                  },
                  "invalid_note_id": {
                    "summary": "An ID does not match `^[A-Za-z0-9_-]{1,64}$`.",
                    "value": {
                      "error": "invalid note id",
                      "code": "invalid_note_id"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "load_notes_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not load notes",
                      "code": "load_notes_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sync/push": {
      "post": {
        "operationId": "pushOperations",
        "tags": [
          "Sync"
        ],
        "summary": "Push operations",
        "description": "Applies queued offline edits in order. Each client queue has its own `device_id`. Its `client_sequence` numbers start at 1 and have no gaps. Retry a failed request with the same operations, sequence numbers, and `op_id` values. The server acknowledges operations that it already applied without applying them again. A status of 200 does not mean that every operation applied. Read the `status` of each acknowledgement. A conflict also uses its sequence number. Send an empty `operations` array to read `expected_sequence`. The request holds at most 100 operations. The body limit is 4 MiB in a plaintext vault and 8 MiB in an encrypted vault. Saves carry the complete note. The server does not merge text. The [client protocol](client-protocol.md) describes queue handling.",
        "parameters": [
          {
            "$ref": "#/components/parameters/VaultProtocol"
          },
          {
            "name": "X-Vylk-Instance-ID",
            "in": "header",
            "description": "The `instance_id` that you stored. When it does not match the server, the request fails with 409 before any write. Send this header from every client that queues edits.",
            "schema": {
              "type": "string"
            },
            "example": "95e9c24f3f492f0b776fa9f58b5837f0"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "anyOf": [
                  {
                    "$ref": "#/components/schemas/PushRequest"
                  },
                  {
                    "$ref": "#/components/schemas/EncryptedPushRequest"
                  }
                ]
              },
              "example": {
                "device_id": "laptop-queue-1",
                "operations": [
                  {
                    "client_sequence": 1,
                    "op_id": "op-1",
                    "type": "note.save",
                    "note_id": "reading-list",
                    "base_revision": 0,
                    "title": "Reading list",
                    "tags": "books",
                    "content": "- Dune\n"
                  },
                  {
                    "client_sequence": 2,
                    "op_id": "op-2",
                    "type": "note.pin",
                    "note_id": "reading-list",
                    "base_revision": 1,
                    "pinned": true
                  },
                  {
                    "client_sequence": 3,
                    "op_id": "op-3",
                    "type": "note.save",
                    "note_id": "trip-notes",
                    "base_revision": 1,
                    "title": "Trip notes",
                    "tags": "travel",
                    "content": "stale\n"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The server processed the operations. Read each acknowledgement.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PushResult"
                },
                "example": {
                  "acknowledged": [
                    {
                      "client_sequence": 1,
                      "op_id": "op-1",
                      "status": "applied",
                      "revision": 1
                    },
                    {
                      "client_sequence": 2,
                      "op_id": "op-2",
                      "status": "applied",
                      "revision": 2,
                      "pin_order": 1
                    },
                    {
                      "client_sequence": 3,
                      "op_id": "op-3",
                      "status": "conflict",
                      "current_revision": 2
                    }
                  ],
                  "expected_sequence": 4
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_sync_request": {
                    "summary": "`device_id` is invalid or `operations` holds more than 100 items.",
                    "value": {
                      "error": "invalid sync request",
                      "code": "invalid_sync_request"
                    }
                  },
                  "invalid_sync_operation": {
                    "summary": "An operation is invalid. Do not retry it. Plaintext vault only.",
                    "value": {
                      "error": "invalid note save operation",
                      "code": "invalid_sync_operation",
                      "permanent": true,
                      "operation_index": 0,
                      "client_sequence": 1,
                      "op_id": "op-1"
                    }
                  },
                  "invalid_encrypted_operation": {
                    "summary": "An operation is invalid or holds a plaintext field. Encrypted vault only.",
                    "value": {
                      "error": "invalid encrypted sync operation",
                      "code": "invalid_encrypted_operation"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/PushResult"
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                },
                "examples": {
                  "sequence_gap": {
                    "summary": "The first `client_sequence` is not `expected_sequence`. The body is a push result. `acknowledged` can hold operations that the server applied earlier.",
                    "value": {
                      "acknowledged": [],
                      "expected_sequence": 4
                    }
                  },
                  "server_instance_changed": {
                    "summary": "`X-Vylk-Instance-ID` does not match the server. The database changed. Do not resend the queue without a decision from the user.",
                    "value": {
                      "code": "server_instance_changed",
                      "error": "The server database changed. Sync is paused to protect your unsynced edits. Restore the previous database and notes directory, then choose Retry."
                    }
                  },
                  "invalid_replayed_operation": {
                    "summary": "A retried `client_sequence` arrived with a different `op_id` or type.",
                    "value": {
                      "error": "invalid replayed operation",
                      "code": "invalid_replayed_operation"
                    }
                  },
                  "stale_vault_epoch": {
                    "summary": "An operation has an old `epoch`. `epoch` holds the current one. Encrypted vault only.",
                    "value": {
                      "error": "refresh vault keys before syncing",
                      "code": "stale_vault_epoch",
                      "epoch": 2
                    }
                  }
                }
              }
            }
          },
          "423": {
            "description": "Locked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_in_progress": {
                    "summary": "Encryption setup is converting notes. Note writes are paused until it finishes.",
                    "value": {
                      "error": "note writes are paused for encryption",
                      "code": "vault_migration_in_progress"
                    }
                  },
                  "vault_maintenance_in_progress": {
                    "summary": "The server is removing plaintext data after encryption setup.",
                    "value": {
                      "error": "vault maintenance is in progress",
                      "code": "vault_maintenance_in_progress"
                    }
                  },
                  "vault_unavailable": {
                    "summary": "The encrypted vault is not ready. Encrypted vault only.",
                    "value": {
                      "error": "encrypted vault is unavailable",
                      "code": "vault_unavailable"
                    }
                  }
                }
              }
            }
          },
          "426": {
            "description": "Upgrade required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "encrypted_client_required": {
                    "summary": "The vault is encrypted and the request has no `X-Vylk-Vault-Protocol: 1` header.",
                    "value": {
                      "error": "update Vylk to sync this encrypted vault",
                      "code": "encrypted_client_required"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_file_recovery_blocked": {
                    "summary": "An interrupted file operation needs recovery before this note can change. Keep the change and retry later.",
                    "value": {
                      "error": "note file recovery requires attention",
                      "code": "note_file_recovery_blocked",
                      "note_id": "trip-notes"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "apply_sync_operation_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not apply sync operation",
                      "code": "apply_sync_operation_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/events": {
      "get": {
        "operationId": "subscribeEvents",
        "tags": [
          "Sync"
        ],
        "summary": "Stream events",
        "description": "Opens a Server-Sent Events stream. The stream starts with `retry: 3000`, a `server` event, and a `heartbeat` event. It sends a heartbeat every 25 seconds. A `change` event has a `type`. `notes` or `preferences`: pull the changes. `ai`: list the AI configurations again. Pull the changes after each reconnect too. When the session ends, the server sends `session-expired` and closes the stream. The events have no IDs, and the server ignores `Last-Event-ID`. The stream does not carry note data and is not a durable feed.",
        "responses": {
          "200": {
            "description": "The event stream stays open.",
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-cache"
                },
                "example": "no-cache"
              },
              "X-Accel-Buffering": {
                "description": "Tells nginx not to buffer the stream.",
                "schema": {
                  "type": "string",
                  "const": "no"
                },
                "example": "no"
              }
            },
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                },
                "example": "retry: 3000\n\nevent: server\ndata: {\"revision\":\"3a7403423c47610d\",\"version\":\"3.1.2\"}\n\nevent: heartbeat\ndata: {}\n\nevent: change\ndata: {\"type\":\"notes\",\"sequence\":7}\n\n"
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "The server could not start the stream. The body is plain text.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "example": "streaming is not supported"
              }
            }
          }
        }
      }
    },
    "/api/prefs": {
      "get": {
        "operationId": "getPreferences",
        "tags": [
          "Preferences"
        ],
        "summary": "Get preferences",
        "description": "Returns the preferences shared by every device. Preferences are not encrypted. The server fills in defaults for unset fields. The response has no `ETag` header. Read `revision` from the body.",
        "responses": {
          "200": {
            "description": "The preferences.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preferences"
                },
                "example": {
                  "aiEnabled": false,
                  "reduceMotion": "system",
                  "revision": 2,
                  "autoSave": true,
                  "startView": "split",
                  "hideToolbar": false,
                  "hideSaveButton": true,
                  "saveButtonLocation": "panel",
                  "collapseDetails": false,
                  "hideCursorHighlight": false,
                  "interactivePreview": true,
                  "contentWidth": "standard",
                  "zenPageWidth": "standard",
                  "fontFamilyGoogle": false,
                  "fontSize": "1rem",
                  "editorFontFamilyGoogle": false,
                  "editorFontSize": "1rem",
                  "previewFontFamilyGoogle": false,
                  "previewFontSize": "1rem",
                  "zenFontFamily": "Inter",
                  "zenFontFamilyGoogle": true,
                  "zenFontSize": "1.25rem",
                  "zenWordCount": true,
                  "zenShowTitle": true,
                  "zenShowControls": true,
                  "zenInteractivePreview": false,
                  "shortcutPrefix": {
                    "steps": [
                      {
                        "key": "e",
                        "modifiers": [
                          "Mod"
                        ]
                      }
                    ]
                  },
                  "keyboardShortcuts": {},
                  "shortcutConfirmationSkips": {},
                  "theme": "dark"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "load_preferences_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not load preferences",
                      "code": "load_preferences_failed"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "replacePreferences",
        "tags": [
          "Preferences"
        ],
        "summary": "Replace preferences",
        "description": "Replaces all preferences. The method is PATCH, but the server does not merge fields. A field that you omit returns to its default. Read the current preferences, change the fields, and send the whole object with its `revision` in `If-Match`. The server ignores `_sync_patch` and `_sync_base` on this route. The body limit is 16 KiB.",
        "parameters": [
          {
            "name": "If-Match",
            "in": "header",
            "description": "The `revision` that you last read, with or without quotes. Without this header or with `*`, the server replaces the preferences without a revision check.",
            "schema": {
              "type": "string"
            },
            "example": "2"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Preferences"
              },
              "example": {
                "aiEnabled": false,
                "reduceMotion": "system",
                "revision": 2,
                "autoSave": true,
                "startView": "split",
                "hideToolbar": false,
                "hideSaveButton": true,
                "saveButtonLocation": "panel",
                "collapseDetails": false,
                "hideCursorHighlight": false,
                "interactivePreview": true,
                "contentWidth": "standard",
                "zenPageWidth": "standard",
                "fontFamilyGoogle": false,
                "fontSize": "1rem",
                "editorFontFamilyGoogle": false,
                "editorFontSize": "1rem",
                "previewFontFamilyGoogle": false,
                "previewFontSize": "1rem",
                "zenFontFamily": "Inter",
                "zenFontFamilyGoogle": true,
                "zenFontSize": "1.25rem",
                "zenWordCount": true,
                "zenShowTitle": true,
                "zenShowControls": true,
                "zenInteractivePreview": false,
                "shortcutPrefix": {
                  "steps": [
                    {
                      "key": "e",
                      "modifiers": [
                        "Mod"
                      ]
                    }
                  ]
                },
                "keyboardShortcuts": {},
                "shortcutConfirmationSkips": {},
                "theme": "dark"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved preferences, with a new `revision`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preferences"
                },
                "example": {
                  "aiEnabled": false,
                  "reduceMotion": "system",
                  "revision": 3,
                  "autoSave": true,
                  "startView": "split",
                  "hideToolbar": false,
                  "hideSaveButton": true,
                  "saveButtonLocation": "panel",
                  "collapseDetails": false,
                  "hideCursorHighlight": false,
                  "interactivePreview": true,
                  "contentWidth": "standard",
                  "zenPageWidth": "standard",
                  "fontFamilyGoogle": false,
                  "fontSize": "1rem",
                  "editorFontFamilyGoogle": false,
                  "editorFontSize": "1rem",
                  "previewFontFamilyGoogle": false,
                  "previewFontSize": "1rem",
                  "zenFontFamily": "Inter",
                  "zenFontFamilyGoogle": true,
                  "zenFontSize": "1.25rem",
                  "zenWordCount": true,
                  "zenShowTitle": true,
                  "zenShowControls": true,
                  "zenInteractivePreview": false,
                  "shortcutPrefix": {
                    "steps": [
                      {
                        "key": "e",
                        "modifiers": [
                          "Mod"
                        ]
                      }
                    ]
                  },
                  "keyboardShortcuts": {},
                  "shortcutConfirmationSkips": {},
                  "theme": "dark"
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_preferences_revision": {
                    "summary": "`If-Match` is not a positive integer.",
                    "value": {
                      "error": "invalid preference revision",
                      "code": "invalid_preferences_revision"
                    }
                  },
                  "invalid_preferences": {
                    "summary": "A field has a value outside its allowed set. `error` names the field.",
                    "value": {
                      "error": "invalid start view",
                      "code": "invalid_preferences"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "preferences_revision_conflict": {
                    "summary": "`If-Match` is not the current revision. `current_revision` holds the current revision.",
                    "value": {
                      "code": "preferences_revision_conflict",
                      "current_revision": 3,
                      "error": "preferences changed on another device"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "save_preferences_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not save preferences",
                      "code": "save_preferences_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/bootstrap": {
      "get": {
        "operationId": "getVaultBootstrap",
        "tags": [
          "Encryption"
        ],
        "summary": "Get the vault status",
        "description": "Returns the vault mode and the public key derivation settings. This route needs no session. Before you read cached notes or a remembered key, compare `instance_id` with the value that you stored. In a plaintext vault, `vault_id`, `epoch`, and `kdf` are absent. `reset_available` is true when the vault is encrypted and the server has a password. It does not account for `VYLK_DISABLE_VAULT_CHANGES`.",
        "security": [],
        "responses": {
          "200": {
            "description": "The vault status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Bootstrap"
                },
                "example": {
                  "epoch": 1,
                  "instance_id": "95e9c24f3f492f0b776fa9f58b5837f0",
                  "kdf": {
                    "algorithm": "argon2id13",
                    "iterations": 3,
                    "memoryKiB": 65536,
                    "salt": "V2OdE0GPomvMRSmaTi4urQ"
                  },
                  "mode": "encrypted",
                  "require_strong_passwords": false,
                  "reset_available": true,
                  "revision": "3a7403423c47610d",
                  "vault_id": "_czcXBKjH4EmmKKl2q1TDQ",
                  "version": "3.1.2"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_status_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read vault status",
                      "code": "vault_status_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/keys": {
      "get": {
        "operationId": "getWrappedKeys",
        "tags": [
          "Encryption"
        ],
        "summary": "Get the wrapped keys",
        "description": "Returns the two encrypted copies of the vault key. Decrypt `wrapped_key` with the key derived from the encryption password, or `wrapped_recovery_key` with the key derived from the recovery key.",
        "responses": {
          "200": {
            "description": "The wrapped keys.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "vault_id",
                    "epoch",
                    "wrapped_key",
                    "wrapped_recovery_key"
                  ],
                  "properties": {
                    "vault_id": {
                      "$ref": "#/components/schemas/VaultID"
                    },
                    "epoch": {
                      "type": "integer",
                      "format": "int64",
                      "description": "Current vault epoch."
                    },
                    "wrapped_key": {
                      "$ref": "#/components/schemas/Envelope",
                      "description": "Vault key, encrypted with the password key."
                    },
                    "wrapped_recovery_key": {
                      "$ref": "#/components/schemas/Envelope",
                      "description": "Vault key, encrypted with the recovery key."
                    }
                  }
                },
                "example": {
                  "epoch": 1,
                  "vault_id": "_czcXBKjH4EmmKKl2q1TDQ",
                  "wrapped_key": {
                    "v": 1,
                    "nonce": "ax2sfi8tjylLhNvD",
                    "ciphertext": "JFBvmyEO5qHYDZqu2zydVahTTMN6qBJcOF-SEOFKsbkwxEL1l99HqeU-fy0pejEe"
                  },
                  "wrapped_recovery_key": {
                    "v": 1,
                    "nonce": "LkRY8fymwwTd72ro",
                    "ciphertext": "co7KXuXDSyRdINUo2PSFYQVcOCtteJC-eUjR0U7qJrqTUhm8Smln9c_vov2ZbTiJ"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_not_encrypted": {
                    "summary": "The vault is not encrypted.",
                    "value": {
                      "code": "vault_not_encrypted",
                      "error": "vault encryption is not active"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_status_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read vault status",
                      "code": "vault_status_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/credentials": {
      "post": {
        "operationId": "changeVaultCredentials",
        "tags": [
          "Encryption"
        ],
        "summary": "Change a credential",
        "description": "Replaces the encryption password or the recovery key. Encrypt the existing vault key again with the new credential. Do not generate a new vault key. With `kind` set to `master`, the request replaces the password, and you must send new key derivation settings. With `kind` set to `recovery`, the request replaces the recovery key. `current_recovery` selects which current credential proves access. It is independent of `kind`. On success, the server revokes the current session. Unless `sign_out_other_devices` is false, it also revokes every other session. Sign in again with the new credential. The body limit is 32 KiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CredentialChange"
              },
              "example": {
                "kind": "master",
                "current_proof": "p2_0cRkBqKE3CtQ6YlGru2jL-Bgg3UctyEN9ulTmE9g",
                "new_proof": "VXvVEOMZ9j8w1I2m0bWU0NFWGsZbunO00xlX-y3vkIY",
                "wrapped_key": {
                  "v": 1,
                  "nonce": "NbbNB6-2nRQ5JPqE",
                  "ciphertext": "-5rrCT_2eq8jTGEXvIFKvXkuU2VIKIBKB38Dq1-4A7GGSoDy-HnFqU4G9dXH5vtY"
                },
                "kdf_salt": "V6xB-1M1KSMQgzBjJ6J4EQ",
                "kdf_memory_kib": 65536,
                "kdf_iterations": 3,
                "sign_out_other_devices": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The credential is changed. The response clears the `session` cookie.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OK"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "Set-Cookie": {
                "description": "Expires the `session` cookie.",
                "schema": {
                  "type": "string"
                },
                "example": "session=; Path=/; Max-Age=0; HttpOnly; SameSite=Lax"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_vault_credentials": {
                    "summary": "A proof or `wrapped_key` is malformed, or `kind` is not `master` or `recovery`.",
                    "value": {
                      "error": "invalid vault credential change",
                      "code": "invalid_vault_credentials"
                    }
                  },
                  "invalid_vault_kdf": {
                    "summary": "The key derivation settings are missing or out of range. `kind` is `master` only.",
                    "value": {
                      "error": "invalid vault key derivation settings",
                      "code": "invalid_vault_kdf"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  },
                  "invalid_credentials": {
                    "summary": "`current_proof` is wrong.",
                    "value": {
                      "error": "current vault credential is incorrect",
                      "code": "invalid_credentials"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_unavailable": {
                    "summary": "The vault is not encrypted or is not ready.",
                    "value": {
                      "error": "encrypted vault is unavailable",
                      "code": "vault_unavailable"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "credential_change_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not update vault credentials",
                      "code": "credential_change_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/reset": {
      "post": {
        "operationId": "resetVault",
        "tags": [
          "Encryption"
        ],
        "summary": "Reset the vault",
        "description": "Replaces an encrypted vault with a new, empty vault. Use this route only when the encryption password and the recovery key are both lost. It does not decrypt anything. The request needs no session. It needs the server password, `VYLK_PASSWORD`, in `password`. Generate new vault credentials on the client, as for `POST /api/vault/migration/start`. The server moves the old database and encrypted notes to an archive and deletes the archive after 30 days. It deletes all notes and the change feed, revokes every session, and returns a new session. `instance_id` stays the same. `vault_id` changes, and `epoch` increases. The body limit is 32 KiB. If the response is lost, read `GET /api/vault/bootstrap` before you retry.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VaultReset"
              },
              "example": {
                "password": "your-server-password",
                "vault_id": "ZDjs0jd0FK2cJRMlqSpVKw",
                "kdf_salt": "kDc-l8DIgsH8T6R2uAtb3w",
                "kdf_memory_kib": 65536,
                "kdf_iterations": 3,
                "auth_proof": "KCEzRWwevRRVjHmKfFnHw0GvKOQWsLKY-2WDCV2twaw",
                "recovery_proof": "Ov1bHpA5nWSGG9S1pg8So2sZmkNHGVwcB1OGgTuckDw",
                "wrapped_key": {
                  "v": 1,
                  "nonce": "oLWV8NohFSiPWRKY",
                  "ciphertext": "U5zN9F7iZcRfSBJxn9vPH1lDvR0VGTiy58cZ1X7MnMxEcn05llAjA57CWHNAB-PT"
                },
                "wrapped_recovery_key": {
                  "v": 1,
                  "nonce": "n1PUQNhS8_geJn5l",
                  "ciphertext": "ZUvRpupL9JqEyK4qeZEptky5UfjmQoccKSa7EfDbZ0PfdTJcyzVxlxJOs4IAjSc_"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new vault is active. The response sets new `session` and `vylk-device` cookies.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "vault_id",
                    "epoch",
                    "archive_expires_at"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "vault_id": {
                      "$ref": "#/components/schemas/VaultID"
                    },
                    "epoch": {
                      "type": "integer",
                      "format": "int64",
                      "description": "Epoch of the new vault."
                    },
                    "archive_expires_at": {
                      "type": "string",
                      "format": "date-time",
                      "description": "Time when the server deletes the archive."
                    }
                  }
                },
                "example": {
                  "archive_expires_at": "2026-12-22T02:41:08Z",
                  "epoch": 2,
                  "ok": true,
                  "vault_id": "ZDjs0jd0FK2cJRMlqSpVKw"
                }
              }
            },
            "headers": {
              "Set-Cookie": {
                "description": "Two cookies: `session` and `vylk-device`. Store both.",
                "schema": {
                  "type": "string"
                },
                "example": [
                  "vylk-device=fdd91647e9dd809fdaf557291a2acd92; Path=/; Max-Age=31536000; HttpOnly; SameSite=Lax",
                  "session=81abd2fc412f40d7039912b972a6bb15; Path=/; Max-Age=15552000; HttpOnly; SameSite=Lax"
                ]
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_vault_reset": {
                    "summary": "A vault ID, salt, proof, envelope, or key derivation setting is invalid.",
                    "value": {
                      "error": "invalid new vault credentials",
                      "code": "invalid_vault_reset"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_credentials": {
                    "summary": "`password` is not `VYLK_PASSWORD`.",
                    "value": {
                      "error": "wrong Vylk password",
                      "code": "invalid_credentials"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  },
                  "vault_reset_unavailable": {
                    "summary": "The server has no `VYLK_PASSWORD`.",
                    "value": {
                      "error": "new vault setup is not available",
                      "code": "vault_reset_unavailable"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_reset_unavailable": {
                    "summary": "The vault is not encrypted, or encryption setup is not finished.",
                    "value": {
                      "error": "encrypted vault cannot be reset right now",
                      "code": "vault_reset_unavailable"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "login_rate_limited": {
                    "summary": "Too many failed attempts from this client address. Wait for the number of seconds in `retry_after`.",
                    "value": {
                      "error": "too many attempts",
                      "code": "login_rate_limited",
                      "retry_after": 60
                    }
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before the next attempt.",
                "schema": {
                  "type": "string"
                },
                "example": "60"
              }
            }
          },
          "503": {
            "description": "Service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_file_recovery_blocked": {
                    "summary": "An interrupted file operation needs recovery first.",
                    "value": {
                      "error": "encrypted file recovery is pending",
                      "code": "note_file_recovery_blocked"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_reset_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not create the new vault",
                      "code": "vault_reset_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/setup/verify-password": {
      "post": {
        "operationId": "verifyEncryptionSetupPassword",
        "tags": [
          "Migration"
        ],
        "summary": "Verify the password",
        "description": "Checks that `password` is the server password before encryption setup. Failed attempts count toward the sign-in rate limit. This route changes nothing on the server. It works before setup and while a started setup waits to resume.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "password"
                ],
                "properties": {
                  "password": {
                    "type": "string",
                    "description": "The server password, `VYLK_PASSWORD`."
                  }
                }
              },
              "example": {
                "password": "your-server-password"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The password is correct.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OK"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_credentials": {
                    "summary": "The password is wrong.",
                    "value": {
                      "code": "invalid_credentials",
                      "error": "wrong password"
                    }
                  },
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_setup_unavailable": {
                    "summary": "The vault is already encrypted.",
                    "value": {
                      "error": "encryption is already enabled",
                      "code": "vault_setup_unavailable"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "login_rate_limited": {
                    "summary": "Too many failed attempts from this client address.",
                    "value": {
                      "error": "too many attempts; please try again later",
                      "code": "login_rate_limited"
                    }
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before the next attempt.",
                "schema": {
                  "type": "string"
                },
                "example": "60"
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "login_rate_limit_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not check login rate limit",
                      "code": "login_rate_limit_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/start": {
      "post": {
        "operationId": "startEncryptionMigration",
        "tags": [
          "Migration"
        ],
        "summary": "Start encryption",
        "description": "Starts converting a plaintext vault to an encrypted vault. Generate the vault ID, the salt, the vault key, the recovery key, both proofs, and both wrapped keys on the client. The server checks `old_password`, saves a backup of the notes, and pauses note writes. A repeated request with the same `vault_id` resumes the setup and keeps the credentials stored by the first request. Keep the setup secrets until `POST /api/vault/migration/commit` succeeds. No route cancels a started setup. The body limit is 32 KiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MigrationStart"
              },
              "example": {
                "vault_id": "_czcXBKjH4EmmKKl2q1TDQ",
                "kdf_salt": "V2OdE0GPomvMRSmaTi4urQ",
                "kdf_memory_kib": 65536,
                "kdf_iterations": 3,
                "auth_proof": "p2_0cRkBqKE3CtQ6YlGru2jL-Bgg3UctyEN9ulTmE9g",
                "recovery_proof": "l6nRkO9YgnXzpnilSnYfjT7ldRbz2ye-cc7Gulrv3Zc",
                "wrapped_key": {
                  "v": 1,
                  "nonce": "ax2sfi8tjylLhNvD",
                  "ciphertext": "JFBvmyEO5qHYDZqu2zydVahTTMN6qBJcOF-SEOFKsbkwxEL1l99HqeU-fy0pejEe"
                },
                "wrapped_recovery_key": {
                  "v": 1,
                  "nonce": "LkRY8fymwwTd72ro",
                  "ciphertext": "co7KXuXDSyRdINUo2PSFYQVcOCtteJC-eUjR0U7qJrqTUhm8Smln9c_vov2ZbTiJ"
                },
                "old_password": "your-server-password"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The setup is started. Upload the encrypted notes next.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "epoch"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "epoch": {
                      "type": "integer",
                      "const": 1,
                      "description": "Epoch of the new vault."
                    }
                  }
                },
                "example": {
                  "epoch": 1,
                  "ok": true
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_vault_setup": {
                    "summary": "`old_password` is wrong, or a vault ID, salt, proof, envelope, or key derivation setting is invalid.",
                    "value": {
                      "error": "invalid vault setup or legacy password",
                      "code": "invalid_vault_setup"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_setup_already_started": {
                    "summary": "The vault is encrypted, or a setup with another `vault_id` is in progress.",
                    "value": {
                      "error": "another vault setup is active",
                      "code": "vault_setup_already_started"
                    }
                  },
                  "unexpected_note_files": {
                    "summary": "The notes folder holds files that the database does not list. `error` names the problem.",
                    "value": {
                      "error": "unexpected legacy note path \"notes/trip-notes.md\"",
                      "code": "unexpected_note_files"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "note_recovery_pending": {
                    "summary": "An interrupted file operation needs recovery first.",
                    "value": {
                      "error": "finish note file recovery before encrypting",
                      "code": "note_recovery_pending"
                    }
                  },
                  "note_recovery_failed": {
                    "summary": "File recovery failed. The server operator must fix it.",
                    "value": {
                      "error": "finish note file recovery before encrypting",
                      "code": "note_recovery_failed"
                    }
                  }
                }
              }
            }
          },
          "507": {
            "description": "Insufficient storage.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "migration_backup_failed": {
                    "summary": "The server could not write the backup. Free disk space and retry with the same body.",
                    "value": {
                      "error": "could not make a consistent local copy; free space and retry",
                      "code": "migration_backup_failed"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_setup_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not start encryption",
                      "code": "vault_setup_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/status": {
      "get": {
        "operationId": "getMigrationStatus",
        "tags": [
          "Migration"
        ],
        "summary": "Get the encryption progress",
        "description": "Returns the vault mode and the number of notes that are uploaded and verified. Encryption can finish when `verified_notes` equals `source_notes`.",
        "responses": {
          "200": {
            "description": "The progress.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "mode",
                    "backup_ready",
                    "source_notes",
                    "staged_notes",
                    "verified_notes"
                  ],
                  "properties": {
                    "mode": {
                      "$ref": "#/components/schemas/VaultMode"
                    },
                    "backup_ready": {
                      "type": "boolean",
                      "description": "True when the server has saved the backup."
                    },
                    "source_notes": {
                      "type": "integer",
                      "description": "Plaintext notes to convert."
                    },
                    "staged_notes": {
                      "type": "integer",
                      "description": "Notes with an uploaded encrypted copy."
                    },
                    "verified_notes": {
                      "type": "integer",
                      "description": "Uploaded copies that the client has verified."
                    }
                  }
                },
                "example": {
                  "backup_ready": true,
                  "mode": "preparing",
                  "source_notes": 2,
                  "staged_notes": 0,
                  "verified_notes": 0
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_not_started": {
                    "summary": "Encryption setup has not started.",
                    "value": {
                      "code": "vault_migration_not_started",
                      "error": "vault migration is not active"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_status_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not count migration progress",
                      "code": "vault_status_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/next": {
      "get": {
        "operationId": "listMigrationNotes",
        "tags": [
          "Migration"
        ],
        "summary": "List notes to convert",
        "description": "Lists up to 100 notes that have no verified encrypted copy, in ascending ID order. To read the next page, pass the last ID as `after`. An empty array means that every note is verified. When a note changes, its earlier verification no longer counts.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "description": "The last ID of the previous page. The response starts after it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The notes to convert.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "id",
                      "revision"
                    ],
                    "properties": {
                      "id": {
                        "$ref": "#/components/schemas/ID"
                      },
                      "revision": {
                        "type": "integer",
                        "format": "int64",
                        "description": "Current revision of the plaintext note."
                      }
                    }
                  }
                },
                "example": [
                  {
                    "id": "reading-list",
                    "revision": 2
                  },
                  {
                    "id": "trip-notes",
                    "revision": 2
                  }
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_not_ready": {
                    "summary": "Setup has not started or the backup is not saved.",
                    "value": {
                      "error": "vault migration is not ready",
                      "code": "vault_migration_not_ready"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_list_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not list remaining notes",
                      "code": "vault_migration_list_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/stage": {
      "post": {
        "operationId": "stageEncryptedNote",
        "tags": [
          "Migration"
        ],
        "summary": "Upload an encrypted copy",
        "description": "Uploads the encrypted copy of one note. `revision` must match the plaintext note. A new upload for the same note replaces the copy and clears its verification. After the upload, read the copy back with `GET /api/vault/migration/staged/{id}` and verify it. The body limit is 8 MiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StagedRequest"
              },
              "example": {
                "id": "reading-list",
                "revision": 2,
                "summary": {
                  "v": 1,
                  "nonce": "WEX-YDY8-R2R8E51",
                  "ciphertext": "5IGkqpAUUPCkD_LS96p4Bk10I1sloJgvBoDNiv5YOJp0BY_2_F0YFUtHJSjTy_q8soQoHV9_C4O2Oc9BxYnC6A"
                },
                "body": {
                  "v": 1,
                  "nonce": "p5ErQVu1FwrjfG5y",
                  "ciphertext": "j2AABCqv8cUGf_xvNOCFt_RSv8hlXuGc37TQtrNP1pm3sv9OjF07Fmx_crOun2_xWQN1fixs4tXckyzXa4snZcM8DU3LL72zJVCrqkq661H1XZcxmkAbcRZWH5twN8hG"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The copy is stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OK"
                },
                "example": {
                  "ok": true
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_encrypted_note": {
                    "summary": "`id`, `revision`, or an envelope is invalid.",
                    "value": {
                      "error": "invalid encrypted note envelope",
                      "code": "invalid_encrypted_note"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_not_ready": {
                    "summary": "Setup has not started or the backup is not saved.",
                    "value": {
                      "error": "vault migration is not ready",
                      "code": "vault_migration_not_ready"
                    }
                  },
                  "vault_note_changed": {
                    "summary": "The note does not exist or has another revision.",
                    "value": {
                      "error": "note changed during migration",
                      "code": "vault_note_changed"
                    }
                  }
                }
              }
            }
          },
          "507": {
            "description": "Insufficient storage.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_stage_failed": {
                    "summary": "The server could not write the file.",
                    "value": {
                      "error": "could not store encrypted note",
                      "code": "vault_stage_failed"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_stage_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not record encrypted note",
                      "code": "vault_stage_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/staged/{id}": {
      "get": {
        "operationId": "getStagedNote",
        "tags": [
          "Migration"
        ],
        "summary": "Get an encrypted copy",
        "description": "Returns the uploaded encrypted copy of a note as the server stored it. Decrypt it and compare it with the plaintext note before you verify it.",
        "parameters": [
          {
            "$ref": "#/components/parameters/NoteID"
          }
        ],
        "responses": {
          "200": {
            "description": "The encrypted copy.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StagedNote"
                },
                "example": {
                  "body": {
                    "v": 1,
                    "nonce": "p5ErQVu1FwrjfG5y",
                    "ciphertext": "j2AABCqv8cUGf_xvNOCFt_RSv8hlXuGc37TQtrNP1pm3sv9OjF07Fmx_crOun2_xWQN1fixs4tXckyzXa4snZcM8DU3LL72zJVCrqkq661H1XZcxmkAbcRZWH5twN8hG"
                  },
                  "body_hash": "21f8ba681e86f93e0af89edb6ea0ba755b6799460d35fe0d3b13a4dd4bba646c",
                  "epoch": 1,
                  "id": "reading-list",
                  "revision": 2,
                  "summary": {
                    "v": 1,
                    "nonce": "WEX-YDY8-R2R8E51",
                    "ciphertext": "5IGkqpAUUPCkD_LS96p4Bk10I1sloJgvBoDNiv5YOJp0BY_2_F0YFUtHJSjTy_q8soQoHV9_C4O2Oc9BxYnC6A"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "staged_note_not_found": {
                    "summary": "No copy is uploaded for this ID.",
                    "value": {
                      "error": "staged note not found",
                      "code": "staged_note_not_found"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "staged_note_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "staged note body is unavailable",
                      "code": "staged_note_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/verify": {
      "post": {
        "operationId": "verifyStagedNote",
        "tags": [
          "Migration"
        ],
        "summary": "Confirm an encrypted copy",
        "description": "Records that the client decrypted the uploaded copy and that it matches the plaintext note. Send the `body_hash` from `GET /api/vault/migration/staged/{id}`. The server checks only the hash and the revision. It cannot check the decryption. The body limit is 4 KiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "body_hash"
                ],
                "properties": {
                  "id": {
                    "$ref": "#/components/schemas/ID"
                  },
                  "body_hash": {
                    "type": "string",
                    "description": "`body_hash` from the uploaded copy. 64 lowercase hexadecimal characters.",
                    "minLength": 64,
                    "maxLength": 64
                  }
                }
              },
              "example": {
                "id": "reading-list",
                "body_hash": "21f8ba681e86f93e0af89edb6ea0ba755b6799460d35fe0d3b13a4dd4bba646c"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The copy is verified.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OK"
                },
                "example": {
                  "ok": true
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "invalid_verification": {
                    "summary": "`id` is invalid or `body_hash` is not 64 characters.",
                    "value": {
                      "error": "invalid note verification",
                      "code": "invalid_verification"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_not_ready": {
                    "summary": "Setup has not started.",
                    "value": {
                      "error": "vault migration is not ready",
                      "code": "vault_migration_not_ready"
                    }
                  },
                  "vault_verify_mismatch": {
                    "summary": "The hash does not match the stored copy, or the note changed.",
                    "value": {
                      "error": "staged note changed or has wrong hash",
                      "code": "vault_verify_mismatch"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_verify_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not verify staged note",
                      "code": "vault_verify_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/vault/migration/commit": {
      "post": {
        "operationId": "commitEncryptionMigration",
        "tags": [
          "Migration"
        ],
        "summary": "Finish encryption",
        "description": "Switches the vault to encrypted storage. Every note must have a verified copy. The request has no body. The server deletes the plaintext notes, the plaintext indexes, and the stored sync operations, and it revokes every session. Sign in again with the derived `proof`. Sync queue sequence numbers continue. Do not restart them at 1. If the response is 500 with `vault_cleanup_pending`, the switch succeeded. The server finishes the cleanup at its next start. Do not start a new setup.",
        "responses": {
          "200": {
            "description": "The vault is encrypted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "mode"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "mode": {
                      "type": "string",
                      "const": "encrypted"
                    }
                  }
                },
                "example": {
                  "mode": "encrypted",
                  "ok": true
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_changes_disabled": {
                    "summary": "The server runs with `VYLK_DISABLE_VAULT_CHANGES` set to true.",
                    "value": {
                      "error": "vault changes are disabled on this instance",
                      "code": "vault_changes_disabled"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Conflict.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_migration_not_ready": {
                    "summary": "Setup has not started or the backup is not saved.",
                    "value": {
                      "error": "vault migration is not ready",
                      "code": "vault_migration_not_ready"
                    }
                  },
                  "vault_migration_incomplete": {
                    "summary": "Some notes have no verified copy.",
                    "value": {
                      "error": "some notes are not verified",
                      "code": "vault_migration_incomplete"
                    }
                  },
                  "unexpected_note_files": {
                    "summary": "The notes folder holds files that the database does not list.",
                    "value": {
                      "error": "unexpected legacy note path \"notes/trip-notes.md\"",
                      "code": "unexpected_note_files"
                    }
                  },
                  "vault_verify_failed": {
                    "summary": "An encrypted file is missing or changed.",
                    "value": {
                      "error": "encrypted file is missing or changed",
                      "code": "vault_verify_failed"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "vault_commit_failed": {
                    "summary": "The switch failed. The vault is still in setup.",
                    "value": {
                      "error": "could not commit cutover",
                      "code": "vault_commit_failed"
                    }
                  },
                  "vault_cleanup_pending": {
                    "summary": "The switch succeeded. Cleanup resumes when the server restarts.",
                    "value": {
                      "error": "encrypted cutover succeeded; cleanup will resume after restart",
                      "code": "vault_cleanup_pending"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/capabilities": {
      "get": {
        "operationId": "getAICapabilities",
        "tags": [
          "AI"
        ],
        "summary": "Get AI capabilities",
        "description": "Returns whether the client can turn model thinking on and off, and a display name for the provider. Both values describe the default configuration, and only when it is checked. Without a checked default, `thinking_controllable` is false and `provider_name` is a generic phrase. The server can read model metadata from the provider, but it does not generate a response.",
        "responses": {
          "200": {
            "description": "The capabilities.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "thinking_controllable",
                    "provider_name"
                  ],
                  "properties": {
                    "thinking_controllable": {
                      "type": "boolean",
                      "description": "True when requests can set `thinking`."
                    },
                    "provider_name": {
                      "type": "string",
                      "description": "Name and model of the default configuration, for display."
                    }
                  }
                },
                "example": {
                  "provider_name": "OpenRouter (openai/gpt-4.1-mini)",
                  "thinking_controllable": false
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_request_failed": {
                    "summary": "AI was turned off during the request, or the server could not read the configurations.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_request_failed"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/configurations": {
      "get": {
        "operationId": "listAIConfigurations",
        "tags": [
          "AI"
        ],
        "summary": "List AI configurations",
        "description": "Returns every AI configuration, in order of creation. Responses never contain API keys. `has_key` tells whether a key is saved.",
        "responses": {
          "200": {
            "description": "The configurations.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/AIConfiguration"
                  }
                },
                "example": [
                  {
                    "output_profile": "",
                    "id": "93e426f2feca1406629434a9891ce6d7",
                    "name": "OpenRouter",
                    "url": "https://openrouter.ai/api/v1",
                    "model": "openai/gpt-4.1-mini",
                    "has_key": true,
                    "checked": true,
                    "is_default": true,
                    "revision": 1,
                    "context_tokens": 0,
                    "concurrency": 0
                  },
                  {
                    "output_profile": "",
                    "id": "5ac56143516b29c821e302682e246296",
                    "name": "Ollama on desktop",
                    "url": "http://192.168.1.20:11434/v1",
                    "model": "qwen3:8b",
                    "has_key": false,
                    "checked": true,
                    "is_default": false,
                    "revision": 2,
                    "context_tokens": 32768,
                    "concurrency": 2
                  }
                ]
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  },
                  "ai_storage_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not load AI configurations",
                      "code": "ai_storage_failed"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createAIConfiguration",
        "tags": [
          "AI"
        ],
        "summary": "Create an AI configuration",
        "description": "Saves a new configuration. With a `test_token`, the configuration is saved as checked. Without one, it is saved unchecked, and sessions cannot use it until `POST /api/ai/configurations/{id}/check` succeeds. The first successful check on a server makes that configuration the default when no default exists. A server holds at most 32 configurations. The body limit is 24 KiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "url",
                  "model"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Display name. 1 to 120 characters, with no control characters."
                  },
                  "url": {
                    "type": "string",
                    "description": "API base URL, such as `https://openrouter.ai/api/v1`. Not the completions URL. HTTP or HTTPS, with no user name, password, query, or fragment. At most 2048 bytes."
                  },
                  "key": {
                    "type": "string",
                    "description": "API key. At most 16 KiB. Omit it to keep the saved key. Send an empty string to remove the key."
                  },
                  "model": {
                    "type": "string",
                    "description": "Model ID. The server sends it to the provider unchanged. At most 256 bytes."
                  },
                  "output_profile": {
                    "type": "string",
                    "enum": [
                      "",
                      "json_schema"
                    ],
                    "description": "Empty: the server detects whether the provider supports JSON Schema output. `json_schema`: always request JSON Schema output."
                  },
                  "context_tokens": {
                    "type": "integer",
                    "description": "Context window in tokens. 0, or 2048 to 16777216. 0 uses the window that the provider reports, or 32768."
                  },
                  "concurrency": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 8,
                    "description": "Parallel requests for one AI job. 0 uses `VYLK_AI_CONCURRENCY`. The server never exceeds `VYLK_AI_CONCURRENCY`."
                  },
                  "test_token": {
                    "type": "string",
                    "description": "`test_token` from `POST /api/ai/configurations/test`. With a valid token, the configuration is saved as checked."
                  }
                }
              },
              "example": {
                "name": "OpenRouter",
                "url": "https://openrouter.ai/api/v1",
                "key": "sk-or-v1-example",
                "model": "openai/gpt-4.1-mini",
                "context_tokens": 0,
                "concurrency": 0,
                "test_token": "a2c4bb6b931a8b86bcdc1aed395736bf.1795349269.9e66c902fe9c4dbe7f91364d579838b2b8338d789d2285cd97070ae633f34c51"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AIConfiguration"
                },
                "example": {
                  "output_profile": "",
                  "id": "93e426f2feca1406629434a9891ce6d7",
                  "name": "OpenRouter",
                  "url": "https://openrouter.ai/api/v1",
                  "model": "openai/gpt-4.1-mini",
                  "has_key": true,
                  "checked": true,
                  "is_default": true,
                  "revision": 1,
                  "context_tokens": 0,
                  "concurrency": 0
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "ai_request_failed": {
                    "summary": "A field is invalid, the server already holds 32 configurations, or `test_token` is expired, already used, or for different settings. `error` names the problem.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "enter an HTTP or HTTPS API base URL without credentials, query, or fragment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/configurations/test": {
      "post": {
        "operationId": "testAIConfiguration",
        "tags": [
          "AI"
        ],
        "summary": "Test an AI configuration",
        "description": "Sends one short request to the provider and reports whether it returned a valid reply. Nothing is saved, but the server records the usage. The request has a limit of 2048 output tokens. If the model supports thinking control, the test turns thinking off. To test a saved configuration with its saved key, send its `id` and `revision` and omit `key`. A successful test returns a `test_token`. Send it to `POST /api/ai/configurations` or `PUT /api/ai/configurations/{id}` to save the configuration as checked. The token is valid for 10 minutes and for one save. The server forgets it on restart and when AI is turned off. It is bound to this session and to `url`, `key`, `model`, `output_profile`, `id`, and `revision`. A change to `name`, `context_tokens`, or `concurrency` does not invalidate it. The provider can take up to 10 minutes to reply. The body limit is 24 KiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url",
                  "model"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Display name. 1 to 120 characters, with no control characters."
                  },
                  "url": {
                    "type": "string",
                    "description": "API base URL, such as `https://openrouter.ai/api/v1`. Not the completions URL. HTTP or HTTPS, with no user name, password, query, or fragment. At most 2048 bytes."
                  },
                  "key": {
                    "type": "string",
                    "description": "API key. At most 16 KiB. Omit it to keep the saved key. Send an empty string to remove the key."
                  },
                  "model": {
                    "type": "string",
                    "description": "Model ID. The server sends it to the provider unchanged. At most 256 bytes."
                  },
                  "output_profile": {
                    "type": "string",
                    "enum": [
                      "",
                      "json_schema"
                    ],
                    "description": "Empty: the server detects whether the provider supports JSON Schema output. `json_schema`: always request JSON Schema output."
                  },
                  "context_tokens": {
                    "type": "integer",
                    "description": "Context window in tokens. 0, or 2048 to 16777216. 0 uses the window that the provider reports, or 32768."
                  },
                  "concurrency": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 8,
                    "description": "Parallel requests for one AI job. 0 uses `VYLK_AI_CONCURRENCY`. The server never exceeds `VYLK_AI_CONCURRENCY`."
                  },
                  "id": {
                    "type": "string",
                    "description": "ID of a saved configuration. Required to test with its saved key."
                  },
                  "revision": {
                    "type": "integer",
                    "description": "Current `revision` of the saved configuration. Required with `id`."
                  }
                }
              },
              "example": {
                "name": "OpenRouter",
                "url": "https://openrouter.ai/api/v1",
                "key": "sk-or-v1-example",
                "model": "openai/gpt-4.1-mini",
                "context_tokens": 0,
                "concurrency": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The provider returned a valid reply.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "thinking_controllable",
                    "test_token",
                    "reported_context_tokens",
                    "default_context_tokens"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "thinking_controllable": {
                      "type": "boolean",
                      "description": "True when requests can set `thinking`."
                    },
                    "test_token": {
                      "type": "string",
                      "description": "Proof of this test. Send it when you save the configuration."
                    },
                    "reported_context_tokens": {
                      "type": "integer",
                      "description": "Context window that the provider reports. 0 when the provider reports none."
                    },
                    "default_context_tokens": {
                      "type": "integer",
                      "description": "Context window that the server uses when neither `context_tokens` nor the provider sets one."
                    }
                  }
                },
                "example": {
                  "default_context_tokens": 32768,
                  "ok": true,
                  "reported_context_tokens": 0,
                  "test_token": "a2c4bb6b931a8b86bcdc1aed395736bf.1795349269.9e66c902fe9c4dbe7f91364d579838b2b8338d789d2285cd97070ae633f34c51",
                  "thinking_controllable": false
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "ai_request_failed": {
                    "summary": "A field is invalid, the saved configuration changed, the provider failed or timed out, or the reply was not valid. `error` names the problem.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "enter an HTTP or HTTPS API base URL without credentials, query, or fragment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  },
                  "ai_deadline_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not configure AI request deadline",
                      "code": "ai_deadline_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/configurations/{id}": {
      "put": {
        "operationId": "updateAIConfiguration",
        "tags": [
          "AI"
        ],
        "summary": "Update an AI configuration",
        "description": "Replaces a configuration. Send every field. A field that you omit takes its zero value, except `key`, which keeps the saved key. `revision` must equal the current revision. The saved configuration has a new `revision`. The configuration stays checked only when `url`, `model`, `output_profile`, and `key` do not change, or when the request has a valid `test_token`. The update closes every AI session that uses this configuration. The body limit is 24 KiB.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Configuration ID.",
            "schema": {
              "type": "string"
            },
            "example": "5ac56143516b29c821e302682e246296"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "url",
                  "model",
                  "revision"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Display name. 1 to 120 characters, with no control characters."
                  },
                  "url": {
                    "type": "string",
                    "description": "API base URL, such as `https://openrouter.ai/api/v1`. Not the completions URL. HTTP or HTTPS, with no user name, password, query, or fragment. At most 2048 bytes."
                  },
                  "key": {
                    "type": "string",
                    "description": "API key. At most 16 KiB. Omit it to keep the saved key. Send an empty string to remove the key."
                  },
                  "model": {
                    "type": "string",
                    "description": "Model ID. The server sends it to the provider unchanged. At most 256 bytes."
                  },
                  "output_profile": {
                    "type": "string",
                    "enum": [
                      "",
                      "json_schema"
                    ],
                    "description": "Empty: the server detects whether the provider supports JSON Schema output. `json_schema`: always request JSON Schema output."
                  },
                  "context_tokens": {
                    "type": "integer",
                    "description": "Context window in tokens. 0, or 2048 to 16777216. 0 uses the window that the provider reports, or 32768."
                  },
                  "concurrency": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 8,
                    "description": "Parallel requests for one AI job. 0 uses `VYLK_AI_CONCURRENCY`. The server never exceeds `VYLK_AI_CONCURRENCY`."
                  },
                  "revision": {
                    "type": "integer",
                    "description": "Current `revision`."
                  },
                  "test_token": {
                    "type": "string",
                    "description": "`test_token` from `POST /api/ai/configurations/test`. With a valid token, the configuration is saved as checked."
                  }
                }
              },
              "example": {
                "name": "Ollama on desktop",
                "url": "http://192.168.1.20:11434/v1",
                "model": "qwen3:8b",
                "revision": 1,
                "context_tokens": 32768,
                "concurrency": 2
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved configuration.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AIConfiguration"
                },
                "example": {
                  "output_profile": "",
                  "id": "5ac56143516b29c821e302682e246296",
                  "name": "Ollama on desktop",
                  "url": "http://192.168.1.20:11434/v1",
                  "model": "qwen3:8b",
                  "has_key": false,
                  "checked": true,
                  "is_default": true,
                  "revision": 2,
                  "context_tokens": 32768,
                  "concurrency": 2
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "ai_request_failed": {
                    "summary": "The ID is invalid or unknown, a field is invalid, `revision` is not current, or `test_token` is not valid for these settings. `error` names the problem.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "configuration could not be saved; reload before editing"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteAIConfiguration",
        "tags": [
          "AI"
        ],
        "summary": "Delete an AI configuration",
        "description": "Deletes a configuration and closes every AI session that uses it. When you delete the default configuration, the server does not choose another default. Usage records stay.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Configuration ID.",
            "schema": {
              "type": "string"
            },
            "example": "5ac56143516b29c821e302682e246296"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted. The response has no body.",
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_request_failed": {
                    "summary": "The ID is invalid, or the server could not delete the configuration.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "invalid configuration ID"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/configurations/{id}/{action}": {
      "post": {
        "operationId": "runAIConfigurationAction",
        "tags": [
          "AI"
        ],
        "summary": "Check or select an AI configuration",
        "description": "`check` sends one short request to the provider, the same as `POST /api/ai/configurations/test`, and marks the saved configuration as checked when the reply is valid. A failed check marks it unchecked and closes the sessions that use it. The server records the usage. The provider can take up to 10 minutes to reply. `default` makes a checked configuration the default. New sessions use the default configuration. Neither action has a request body.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Configuration ID.",
            "schema": {
              "type": "string"
            },
            "example": "5ac56143516b29c821e302682e246296"
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "description": "Action to run.",
            "schema": {
              "type": "string",
              "enum": [
                "check",
                "default"
              ]
            },
            "example": "check"
          }
        ],
        "responses": {
          "200": {
            "description": "`check` only. The check succeeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OK"
                },
                "example": {
                  "ok": true
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "204": {
            "description": "`default` only. The configuration is the default. The response has no body.",
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_request_failed": {
                    "summary": "The ID is invalid or unknown, the configuration is not checked (`default`), or the provider failed or timed out (`check`). `error` names the problem.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "check this configuration before choosing it as default"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found. The action is not one of the listed values. The body is plain text.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "example": "404 page not found\n"
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  },
                  "ai_deadline_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not configure AI request deadline",
                      "code": "ai_deadline_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/sessions": {
      "post": {
        "operationId": "createAISession",
        "tags": [
          "AI"
        ],
        "summary": "Start an AI session",
        "description": "Starts a session with the default configuration. The configuration must be checked. A session holds a draft of the shared text, the conversation, and the suggested changes. The server sends only `text` to the provider, never the title, the tags, or the rest of the note. In an encrypted vault, the client sends decrypted text, and the server forwards it to the provider. A session belongs to the `session` cookie that created it. It ends after 30 minutes without requests, when you sign out, when AI is turned off, and when the server restarts. The server holds at most four sessions at a time. The body limit is about 6 MiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "note_id",
                  "scope",
                  "text"
                ],
                "properties": {
                  "note_id": {
                    "$ref": "#/components/schemas/ID",
                    "description": "Note that the session edits."
                  },
                  "scope": {
                    "type": "string",
                    "enum": [
                      "none",
                      "selection",
                      "note"
                    ],
                    "description": "What `text` contains. `none`: nothing; the provider receives only the prompts. `selection`: selected Markdown, or an empty string for an insertion point. `note`: the whole note text."
                  },
                  "text": {
                    "type": "string",
                    "description": "Shared Markdown. At most 1 MiB. Must be empty when `scope` is `none`."
                  }
                }
              },
              "example": {
                "note_id": "trip-notes",
                "scope": "note",
                "text": "# Trip notes\n\nPack teh charger.\n\nBook the train.\n"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AISession"
                },
                "example": {
                  "configuration_id": "93e426f2feca1406629434a9891ce6d7",
                  "thinking_controllable": false,
                  "id": "0acde88882e62aaf5229b714b9054f8d",
                  "note_id": "trip-notes",
                  "scope": "note",
                  "draft": "# Trip notes\n\nPack teh charger.\n\nBook the train.\n",
                  "hunks": [],
                  "answer": "",
                  "version": 0,
                  "can_undo": false,
                  "changed": false
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "ai_request_failed": {
                    "summary": "`note_id` or `scope` is invalid, `text` is larger than 1 MiB, there is no checked default configuration, or four sessions are open. `error` names the problem.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "check a configuration and set it as default in AI preferences"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/sessions/{id}": {
      "get": {
        "operationId": "getAISession",
        "tags": [
          "AI"
        ],
        "summary": "Get an AI session",
        "description": "Returns the session. With `job`, returns the status of the current job instead. With `job` and `wait=1`, the server waits up to 25 seconds for the job to finish, and returns as soon as it does. Repeat the request while `status` is `running`. At most two requests can wait on one job.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Session ID from `POST /api/ai/sessions`.",
            "schema": {
              "type": "string"
            },
            "example": "0acde88882e62aaf5229b714b9054f8d"
          },
          {
            "name": "job",
            "in": "query",
            "description": "Any value returns the job status instead of the session.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "wait",
            "in": "query",
            "description": "`1` waits for the job to finish. Requires `job`.",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The session, or the job status when the request has `job`.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AISession"
                    },
                    {
                      "$ref": "#/components/schemas/AIJob"
                    }
                  ]
                },
                "example": {
                  "configuration_id": "93e426f2feca1406629434a9891ce6d7",
                  "job": {
                    "id": "337342d5d47c347e02000d0d88483fc8",
                    "snapshot_id": "2cb14c0b6097a1389cd319e5ef17fe5c",
                    "version": 1,
                    "status": "completed",
                    "completed": 1,
                    "total": 1
                  },
                  "thinking_controllable": false,
                  "id": "0acde88882e62aaf5229b714b9054f8d",
                  "note_id": "trip-notes",
                  "scope": "note",
                  "draft": "# Trip notes\n\nPack teh charger.\n\nBook the train.\n",
                  "hunks": [
                    {
                      "id": "ba968b79a37b2d3a741cdc7ba71a3314",
                      "ref": "@1",
                      "start": 14,
                      "end": 31,
                      "before": "Pack teh charger.",
                      "after": "Pack the charger.",
                      "decision": ""
                    }
                  ],
                  "answer": "Suggested changes are ready to review.",
                  "version": 1,
                  "can_undo": false,
                  "changed": false
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_request_failed": {
                    "summary": "The session ID is invalid, or the session ended. With `job`, the session has no job.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "AI session expired or unavailable; reopen AI"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "closeAISession",
        "tags": [
          "AI"
        ],
        "summary": "Close an AI session",
        "description": "Cancels the running job and deletes the session. The server returns 204 when the session is already closed.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Session ID from `POST /api/ai/sessions`.",
            "schema": {
              "type": "string"
            },
            "example": "0acde88882e62aaf5229b714b9054f8d"
          }
        ],
        "responses": {
          "204": {
            "description": "Closed. The response has no body.",
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_request_failed": {
                    "summary": "The session ID is invalid.",
                    "value": {
                      "error": "invalid session ID",
                      "code": "ai_request_failed"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/ai/sessions/{id}/{action}": {
      "post": {
        "operationId": "runAISessionAction",
        "tags": [
          "AI"
        ],
        "summary": "Run an AI session action",
        "description": "Runs one step of a session. Every action except `cancel` needs the current `version`, and each change to the session increases `version`. `plan` prepares a request and returns a plan. It does not generate a response. `start` runs a plan as a background job and returns 202. Starting the same plan again returns the same job. Poll `GET /api/ai/sessions/{id}?job=1&wait=1` until the job finishes, then get the session. `cancel` stops the job and the pending plans, and keeps the session. `review` accepts or rejects suggested changes in the draft. It does not save the note. `accept_all` accepts every pending hunk. `undo` reverts the last acceptance and discards the pending hunks. `finalize` returns the draft when every hunk has a decision and the draft differs from the original. `context` replaces the shared text and scope. Resolve every pending hunk first. `rebase` replaces the shared text after another device edits the note. Hunks that the edit touches become `outdated`. `configuration` switches the session to another checked configuration. It does not change the default. `turn` runs a request synchronously and returns the session. It can take up to 10 minutes. Use `plan` and `start` instead. A session allows 20 requests. The body limit is 100 KiB, or about 6 MiB for `context` and `rebase`.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Session ID from `POST /api/ai/sessions`.",
            "schema": {
              "type": "string"
            },
            "example": "0acde88882e62aaf5229b714b9054f8d"
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "description": "Action to run.",
            "schema": {
              "type": "string",
              "enum": [
                "plan",
                "start",
                "cancel",
                "review",
                "context",
                "rebase",
                "configuration",
                "turn"
              ]
            },
            "example": "plan"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "description": "Current `version` of the session. Used by every action except `cancel`."
                  },
                  "prompt": {
                    "type": "string",
                    "description": "Request to the model. At most 16 KiB. Used by `plan` and `turn`."
                  },
                  "thinking": {
                    "type": "boolean",
                    "default": false,
                    "description": "Turn model thinking on. True fails when `thinking_controllable` is false. Used by `plan` and `turn`."
                  },
                  "whole_context": {
                    "type": "boolean",
                    "default": false,
                    "description": "Send the whole shared text in one request when it fits. Used by `plan` and `turn`."
                  },
                  "plan_id": {
                    "type": "string",
                    "description": "`id` from the `plan` response. Used by `start`."
                  },
                  "action": {
                    "type": "string",
                    "enum": [
                      "accept",
                      "reject",
                      "accept_all",
                      "undo",
                      "finalize"
                    ],
                    "description": "Review step. Used by `review`."
                  },
                  "hunk_id": {
                    "type": "string",
                    "description": "`id` of the hunk. Used by `review` with `accept` or `reject`."
                  },
                  "scope": {
                    "type": "string",
                    "enum": [
                      "none",
                      "selection",
                      "note"
                    ],
                    "description": "New sharing scope. Used by `context`."
                  },
                  "text": {
                    "type": "string",
                    "description": "New shared text. At most 1 MiB. Used by `context` and `rebase`."
                  },
                  "configuration_id": {
                    "type": "string",
                    "description": "Checked configuration to use. Used by `configuration`."
                  }
                }
              },
              "example": {
                "prompt": "Fix typos",
                "version": 0
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "`plan`: the plan. Other actions: the session.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AIPlan"
                    },
                    {
                      "$ref": "#/components/schemas/AISession"
                    }
                  ]
                },
                "example": {
                  "whole_context": false,
                  "id": "2cb14c0b6097a1389cd319e5ef17fe5c",
                  "version": 0,
                  "sections": 1,
                  "estimated_input_tokens": 1544
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "202": {
            "description": "`start` only. The job is running.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AIJob"
                },
                "example": {
                  "id": "337342d5d47c347e02000d0d88483fc8",
                  "snapshot_id": "2cb14c0b6097a1389cd319e5ef17fe5c",
                  "version": 0,
                  "status": "running",
                  "completed": 0,
                  "total": 1
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "204": {
            "description": "`cancel` only. The response has no body.",
            "headers": {
              "Cache-Control": {
                "description": "Responses are not cached.",
                "schema": {
                  "type": "string",
                  "const": "no-store"
                },
                "example": "no-store"
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalid_request": {
                    "summary": "The body is not one JSON object, has an unknown field, or exceeds the size limit.",
                    "value": {
                      "error": "invalid request",
                      "code": "invalid_request"
                    }
                  },
                  "ai_request_failed": {
                    "summary": "The session ended, `version` is not current, a request is already running, a field is invalid, or the provider failed. `error` names the problem.",
                    "value": {
                      "code": "ai_request_failed",
                      "error": "AI draft changed; plan the request again"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found. The action is not one of the listed values. The body is plain text.",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                },
                "example": "404 page not found\n"
              }
            }
          },
          "401": {
            "description": "Unauthorized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "authentication_required": {
                    "summary": "The request has no valid session cookie.",
                    "value": {
                      "error": "unauthorized",
                      "code": "authentication_required"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_disabled": {
                    "summary": "The `aiEnabled` preference is false.",
                    "value": {
                      "error": "AI is disabled",
                      "code": "ai_disabled"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error. The `code` field names the step that failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "ai_unavailable": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not read AI settings",
                      "code": "ai_unavailable"
                    }
                  },
                  "ai_deadline_failed": {
                    "summary": "The server could not complete the request.",
                    "value": {
                      "error": "could not configure AI request deadline",
                      "code": "ai_deadline_failed"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "session",
        "description": "The `session` cookie from `POST /api/login`. Store cookies in a cookie jar and send them with each request. The API does not accept bearer tokens or API keys."
      }
    },
    "parameters": {
      "VaultProtocol": {
        "name": "X-Vylk-Vault-Protocol",
        "in": "header",
        "description": "Set it to `1` when the vault is encrypted. Without it, the request fails with 426. A plaintext vault ignores the header.",
        "schema": {
          "type": "string",
          "const": "1"
        }
      },
      "NoteID": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Note identifier.",
        "schema": {
          "$ref": "#/components/schemas/ID"
        },
        "example": "trip-notes"
      }
    },
    "headers": {
      "SetSession": {
        "description": "The server renews the `session` cookie while you use it. Store the new value.",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "ID": {
        "type": "string",
        "pattern": "^[A-Za-z0-9_-]{1,64}$",
        "description": "Note ID. 1 to 64 letters, digits, hyphens, or underscores."
      },
      "QueueID": {
        "type": "string",
        "pattern": "^[A-Za-z0-9_-]{1,128}$",
        "description": "Client-chosen identifier. 1 to 128 letters, digits, hyphens, or underscores."
      },
      "VaultID": {
        "type": "string",
        "description": "16 random bytes in unpadded base64url. 22 characters.",
        "minLength": 22,
        "maxLength": 22
      },
      "Proof": {
        "type": "string",
        "description": "32 bytes derived from a credential, in unpadded base64url. 43 characters. Treat it as a password. Never log it.",
        "minLength": 43,
        "maxLength": 43
      },
      "Envelope": {
        "title": "Envelope",
        "type": "object",
        "description": "AES-256-GCM ciphertext as a JSON object, not as a string. The [client protocol](client-protocol.md#encryption-wire-format) defines the encryption.",
        "required": [
          "v",
          "nonce",
          "ciphertext"
        ],
        "properties": {
          "v": {
            "type": "integer",
            "const": 1,
            "description": "Format version."
          },
          "nonce": {
            "type": "string",
            "minLength": 16,
            "maxLength": 16,
            "description": "12-byte nonce in unpadded base64url."
          },
          "ciphertext": {
            "type": "string",
            "minLength": 22,
            "description": "Ciphertext followed by the 16-byte authentication tag, in unpadded base64url."
          }
        }
      },
      "Error": {
        "title": "Error",
        "type": "object",
        "required": [
          "error",
          "code"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Message in English."
          },
          "code": {
            "type": "string",
            "description": "Stable error code."
          },
          "note_id": {
            "type": "string",
            "description": "Note that the error concerns."
          },
          "current_revision": {
            "type": "integer",
            "format": "int64",
            "description": "Current revision on the server."
          },
          "epoch": {
            "type": "integer",
            "format": "int64",
            "description": "Current vault epoch."
          },
          "retry_after": {
            "type": "integer",
            "description": "Seconds to wait before the next attempt."
          },
          "permanent": {
            "type": "boolean",
            "description": "True when a retry cannot succeed."
          },
          "operation_index": {
            "type": "integer",
            "minimum": 0,
            "description": "Index of the invalid operation in `operations`."
          },
          "client_sequence": {
            "type": "integer",
            "format": "int64",
            "description": "`client_sequence` of the invalid operation."
          },
          "op_id": {
            "type": "string",
            "description": "`op_id` of the invalid operation."
          }
        },
        "description": "Error responses carry this object. Branch on `code`. The `error` text can change between releases."
      },
      "OK": {
        "type": "object",
        "required": [
          "ok"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          }
        }
      },
      "Login": {
        "title": "Sign-in request",
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "password": {
            "type": "string",
            "description": "Server password, `VYLK_PASSWORD`. Plaintext vault and encryption setup only."
          },
          "proof": {
            "$ref": "#/components/schemas/Proof",
            "description": "Proof derived from the encryption password. Encrypted vault only."
          },
          "recovery_proof": {
            "$ref": "#/components/schemas/Proof",
            "description": "Proof derived from the recovery key. Encrypted vault only."
          }
        },
        "description": "Send `password`, `proof`, or `recovery_proof`, depending on the vault mode."
      },
      "LoginResult": {
        "title": "Sign-in result",
        "type": "object",
        "required": [
          "ok",
          "version",
          "revision",
          "instance_id"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "const": true
          },
          "version": {
            "type": "string",
            "description": "vylk version of the server."
          },
          "revision": {
            "type": "string",
            "description": "Build of the web app. Not a note revision."
          },
          "instance_id": {
            "type": "string",
            "description": "Identity of the server database. It changes only when the database is replaced."
          }
        }
      },
      "CheckResult": {
        "title": "Session status",
        "allOf": [
          {
            "$ref": "#/components/schemas/LoginResult"
          },
          {
            "type": "object",
            "required": [
              "vault_mode",
              "vault_epoch"
            ],
            "properties": {
              "vault_mode": {
                "$ref": "#/components/schemas/VaultMode"
              },
              "vault_epoch": {
                "type": "integer",
                "format": "int64",
                "description": "Current vault epoch. 0 in a plaintext vault."
              }
            }
          }
        ]
      },
      "Device": {
        "title": "Device",
        "type": "object",
        "required": [
          "id",
          "name",
          "last_seen_at",
          "current"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Device ID. 32 hexadecimal characters."
          },
          "name": {
            "type": "string",
            "description": "Browser and platform, from the User-Agent at sign-in."
          },
          "last_seen_at": {
            "type": "string",
            "format": "date-time",
            "description": "Approximate time of the last request."
          },
          "current": {
            "type": "boolean",
            "description": "True for the device that sent this request."
          }
        }
      },
      "PlainNote": {
        "title": "Note",
        "type": "object",
        "required": [
          "id",
          "title",
          "filename",
          "tags",
          "pinned",
          "created_at",
          "updated_at",
          "revision"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID"
          },
          "title": {
            "type": "string",
            "description": "Title. At most 512 bytes."
          },
          "filename": {
            "type": "string",
            "description": "File name in the notes folder. Not an API path."
          },
          "tags": {
            "type": "string",
            "description": "Comma-separated tags. The server trims them and removes duplicates. Tags are case-sensitive. At most 4096 bytes."
          },
          "pinned": {
            "type": "boolean",
            "description": "True when the note is pinned."
          },
          "pin_order": {
            "type": "integer",
            "format": "int64",
            "description": "Position among pinned notes. Absent when 0."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Creation time."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Time of the last change."
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision. Each change increases it by 1."
          }
        },
        "description": "Note metadata in a plaintext vault."
      },
      "EncryptedNote": {
        "title": "Encrypted note",
        "type": "object",
        "required": [
          "id",
          "summary",
          "pinned",
          "pin_order",
          "created_at",
          "updated_at",
          "revision",
          "epoch"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID"
          },
          "summary": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted title and tags."
          },
          "pinned": {
            "type": "boolean",
            "description": "True when the note is pinned."
          },
          "pin_order": {
            "type": "integer",
            "format": "int64",
            "description": "Position among pinned notes. 0 when not pinned."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Creation time."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Time of the last change."
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision. Each change increases it by 1."
          },
          "epoch": {
            "type": "integer",
            "format": "int64",
            "description": "Vault epoch that encrypted the note."
          }
        },
        "description": "Note metadata in an encrypted vault."
      },
      "NoteSummary": {
        "title": "Note summary",
        "oneOf": [
          {
            "$ref": "#/components/schemas/PlainNote"
          },
          {
            "$ref": "#/components/schemas/EncryptedNote"
          }
        ],
        "description": "A note without its content."
      },
      "CompleteNote": {
        "title": "Note with content",
        "oneOf": [
          {
            "allOf": [
              {
                "$ref": "#/components/schemas/PlainNote"
              },
              {
                "type": "object",
                "required": [
                  "content"
                ],
                "properties": {
                  "content": {
                    "type": "string",
                    "description": "Note text in Markdown."
                  }
                }
              }
            ],
            "title": "Plaintext vault"
          },
          {
            "allOf": [
              {
                "$ref": "#/components/schemas/EncryptedNote"
              },
              {
                "type": "object",
                "required": [
                  "body"
                ],
                "properties": {
                  "body": {
                    "$ref": "#/components/schemas/Envelope",
                    "description": "Encrypted note text."
                  }
                }
              }
            ],
            "title": "Encrypted vault"
          }
        ],
        "description": "A note with its content."
      },
      "NotesPage": {
        "title": "Notes page",
        "type": "object",
        "required": [
          "notes"
        ],
        "properties": {
          "notes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/NoteSummary"
            },
            "description": "Note summaries."
          },
          "nextCursor": {
            "type": "string",
            "description": "Cursor for the next page. Absent or empty on the last page."
          }
        }
      },
      "SaveNote": {
        "title": "Plaintext vault",
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID",
            "description": "Note ID. Omit it to let the server generate an ID."
          },
          "title": {
            "type": "string",
            "description": "Title. At most 512 bytes."
          },
          "content": {
            "type": "string",
            "description": "Note text in Markdown."
          },
          "tags": {
            "type": "string",
            "description": "Comma-separated tags. At most 4096 bytes."
          },
          "base_revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision that you last read. Required with `id`. Use 0 for a new note."
          }
        }
      },
      "SaveEncryptedNote": {
        "title": "Encrypted vault",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "summary",
          "body",
          "epoch",
          "base_revision"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID",
            "description": "Note ID that the client generated."
          },
          "summary": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted title and tags."
          },
          "body": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted note text."
          },
          "epoch": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Current vault epoch."
          },
          "base_revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision that you last read. Use 0 for a new note."
          }
        }
      },
      "Change": {
        "title": "Change",
        "type": "object",
        "required": [
          "sequence",
          "note_id",
          "revision",
          "deleted",
          "changed_at"
        ],
        "properties": {
          "sequence": {
            "type": "integer",
            "format": "int64",
            "description": "Position in the change feed."
          },
          "note_id": {
            "$ref": "#/components/schemas/ID",
            "description": "Changed note."
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision after the change."
          },
          "deleted": {
            "type": "boolean",
            "description": "True when the change deleted the note."
          },
          "changed_at": {
            "type": "string",
            "format": "date-time",
            "description": "Time of the change."
          }
        }
      },
      "ChangesPage": {
        "title": "Changes page",
        "type": "object",
        "required": [
          "changes",
          "nextSequence",
          "hasMore",
          "instance_id"
        ],
        "properties": {
          "changes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Change"
            },
            "description": "Changes, oldest first."
          },
          "nextSequence": {
            "type": "integer",
            "format": "int64",
            "description": "Sequence to send as `since` in the next request."
          },
          "hasMore": {
            "type": "boolean",
            "description": "True when more changes follow."
          },
          "resetRequired": {
            "type": "boolean",
            "description": "True when the server no longer has the changes after `since`. Present only when true."
          },
          "instance_id": {
            "type": "string",
            "description": "Identity of the server database."
          }
        }
      },
      "Operation": {
        "title": "Operation",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "client_sequence",
          "op_id",
          "type"
        ],
        "description": "A queued edit in a plaintext vault. `note.save` needs the complete `title`, `tags`, and `content`. The server accepts `base_content` but does not use it to merge text.",
        "properties": {
          "client_sequence": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Position in the queue. Starts at 1 and has no gaps."
          },
          "op_id": {
            "$ref": "#/components/schemas/QueueID",
            "description": "Stable identifier of the operation. Reuse it on retry."
          },
          "type": {
            "type": "string",
            "enum": [
              "note.save",
              "note.delete",
              "note.pin",
              "prefs.save",
              "noop"
            ],
            "description": "Operation type. `note.save`, `note.delete`, and `note.pin` change a note. `prefs.save` changes preferences. `noop` only uses a sequence number."
          },
          "note_id": {
            "$ref": "#/components/schemas/ID",
            "description": "Target note. Required for note operations."
          },
          "base_revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision that the edit is based on. Required for note operations. At least 1 for `note.delete`."
          },
          "title": {
            "type": "string",
            "description": "Complete title. `note.save` only."
          },
          "tags": {
            "type": "string",
            "description": "Complete tags. `note.save` only."
          },
          "content": {
            "type": "string",
            "description": "Complete Markdown text. `note.save` only."
          },
          "base_content": {
            "type": "string",
            "description": "Text that the edit is based on. Accepted and not used."
          },
          "pinned": {
            "type": "boolean",
            "description": "New pin state. `note.pin` only."
          },
          "prefs": {
            "$ref": "#/components/schemas/Preferences",
            "description": "Preferences. Required for `prefs.save`."
          }
        }
      },
      "EncryptedOperation": {
        "title": "Encrypted operation",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "client_sequence",
          "op_id",
          "type"
        ],
        "description": "A queued edit in an encrypted vault. The server rejects `title`, `tags`, `content`, and `base_content`.",
        "properties": {
          "client_sequence": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Position in the queue. Starts at 1 and has no gaps."
          },
          "op_id": {
            "$ref": "#/components/schemas/QueueID",
            "description": "Stable identifier of the operation. Reuse it on retry."
          },
          "type": {
            "type": "string",
            "enum": [
              "note.save",
              "note.delete",
              "note.pin",
              "prefs.save",
              "noop"
            ],
            "description": "Operation type. `note.save`, `note.delete`, and `note.pin` change a note. `prefs.save` changes preferences. `noop` only uses a sequence number."
          },
          "note_id": {
            "$ref": "#/components/schemas/ID",
            "description": "Target note. Required for note operations."
          },
          "base_revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision that the edit is based on. Required for note operations. At least 1 for `note.delete`."
          },
          "summary": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted title and tags. `note.save` only."
          },
          "body": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted note text. `note.save` only."
          },
          "epoch": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Vault epoch that encrypted the envelopes. Required for note operations."
          },
          "pinned": {
            "type": "boolean",
            "description": "New pin state. `note.pin` only."
          },
          "prefs": {
            "$ref": "#/components/schemas/Preferences",
            "description": "Preferences. Required for `prefs.save`."
          }
        }
      },
      "PushRequest": {
        "title": "Plaintext vault",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "device_id",
          "operations"
        ],
        "properties": {
          "device_id": {
            "$ref": "#/components/schemas/QueueID",
            "description": "Identifier of the client queue. Keep it for the lifetime of the queue."
          },
          "operations": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/Operation"
            },
            "description": "Operations in queue order. At most 100."
          }
        }
      },
      "EncryptedPushRequest": {
        "title": "Encrypted vault",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "device_id",
          "operations"
        ],
        "properties": {
          "device_id": {
            "$ref": "#/components/schemas/QueueID",
            "description": "Identifier of the client queue. Keep it for the lifetime of the queue."
          },
          "operations": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/EncryptedOperation"
            },
            "description": "Operations in queue order. At most 100."
          }
        }
      },
      "Acknowledgement": {
        "title": "Acknowledgement",
        "type": "object",
        "required": [
          "client_sequence",
          "op_id",
          "status"
        ],
        "properties": {
          "client_sequence": {
            "type": "integer",
            "format": "int64",
            "description": "`client_sequence` of the operation."
          },
          "op_id": {
            "type": "string",
            "description": "`op_id` of the operation."
          },
          "status": {
            "type": "string",
            "enum": [
              "applied",
              "conflict",
              "compacted"
            ],
            "description": "`applied`: the server applied the operation. `conflict`: the base revision is old, and nothing changed. `compacted`: the server applied the operation earlier and no longer keeps its result."
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "description": "New revision. Present when the operation applied."
          },
          "current_revision": {
            "type": "integer",
            "format": "int64",
            "description": "Current revision. Present on a conflict."
          },
          "pin_order": {
            "type": "integer",
            "format": "int64",
            "description": "New pin position. `note.pin` only."
          }
        }
      },
      "PushResult": {
        "title": "Push result",
        "type": "object",
        "required": [
          "acknowledged",
          "expected_sequence"
        ],
        "properties": {
          "acknowledged": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Acknowledgement"
            },
            "description": "One result for each operation that the server processed."
          },
          "expected_sequence": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "`client_sequence` that the server expects next."
          }
        }
      },
      "ShortcutStep": {
        "title": "Shortcut step",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "modifiers"
        ],
        "description": "One key press. The first step uses `[\"Mod\"]` or `[\"Mod\", \"Shift\"]`. A second step uses no modifiers.",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[A-Za-z0-9/;]$",
            "description": "One letter, digit, `/`, or `;`."
          },
          "modifiers": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "Mod",
                "Shift"
              ]
            },
            "description": "`Mod` is Ctrl on Windows and Linux and Command on macOS."
          }
        }
      },
      "ShortcutBinding": {
        "title": "Shortcut",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "steps"
        ],
        "properties": {
          "steps": {
            "type": "array",
            "minItems": 1,
            "maxItems": 2,
            "items": {
              "$ref": "#/components/schemas/ShortcutStep"
            },
            "description": "One or two key presses."
          }
        }
      },
      "FontSize": {
        "type": "string",
        "description": "Font size. An empty string is allowed in `PATCH /api/prefs`, not in `_sync_patch`.",
        "enum": [
          "",
          "0.8rem",
          "0.9rem",
          "1rem",
          "1.1rem",
          "1.25rem",
          "1.5rem"
        ]
      },
      "ContentWidth": {
        "type": "string",
        "description": "Width of the text column. An empty string is allowed in `PATCH /api/prefs`, not in `_sync_patch`.",
        "enum": [
          "",
          "compact",
          "standard",
          "wide",
          "full"
        ]
      },
      "Preferences": {
        "title": "Preferences",
        "type": "object",
        "additionalProperties": false,
        "description": "Preferences that every device shares. They are not encrypted. Defaults apply to a new account. In a `prefs.save` operation, send the changed fields in `_sync_patch` and their previous values in `_sync_base`. A field conflicts when another device changed it to a third value.",
        "properties": {
          "aiEnabled": {
            "type": "boolean",
            "default": false,
            "description": "Turn on AI. When false, every `/api/ai/` route returns 403, and the server ends every AI session."
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision. Each save increases it by 1."
          },
          "autoSave": {
            "type": "boolean",
            "default": true,
            "description": "Sync changes automatically. Changes are always saved on the device."
          },
          "reduceMotion": {
            "type": "string",
            "enum": [
              "system",
              "always",
              "never"
            ],
            "default": "system",
            "description": "`system` follows the operating system. `always` turns off animations. `never` keeps them on."
          },
          "startView": {
            "type": "string",
            "enum": [
              "editor",
              "preview",
              "split",
              "zen"
            ],
            "default": "editor",
            "description": "View of a newly opened note."
          },
          "hideToolbar": {
            "type": "boolean",
            "default": false,
            "description": "Hide the formatting toolbar above the editor."
          },
          "hideSaveButton": {
            "type": "boolean",
            "default": true,
            "description": "Hide the manual Save button."
          },
          "saveButtonLocation": {
            "type": "string",
            "enum": [
              "",
              "panel",
              "header"
            ],
            "default": "panel",
            "description": "`panel` puts the Save button in the editor toolbar. `header` puts it in the app header."
          },
          "collapseDetails": {
            "type": "boolean",
            "description": "Collapse the title and tags fields when a note opens."
          },
          "hideCursorHighlight": {
            "type": "boolean",
            "description": "Turn off the preview highlight of the block at the cursor."
          },
          "interactivePreview": {
            "type": "boolean",
            "default": true,
            "description": "Allow toggling tasks and moving blocks in Split and Preview views."
          },
          "statusDisplay": {
            "type": "string",
            "description": "Sync status display. The web app uses `normal`, `compact`, or `off`."
          },
          "contentWidth": {
            "$ref": "#/components/schemas/ContentWidth",
            "description": "Width of the text column."
          },
          "zenPageWidth": {
            "$ref": "#/components/schemas/ContentWidth",
            "description": "Width of the page in Zen mode."
          },
          "theme": {
            "type": "string",
            "description": "Built-in theme name, or a palette string that the client defines. The server does not interpret it."
          },
          "accentColor": {
            "type": "string",
            "description": "Custom accent color. Empty means the theme color."
          },
          "fontFamily": {
            "type": "string",
            "description": "Interface font."
          },
          "fontFamilyGoogle": {
            "type": "boolean",
            "description": "Load `fontFamily` from Google Fonts."
          },
          "fontSize": {
            "$ref": "#/components/schemas/FontSize",
            "description": "Interface font size."
          },
          "editorFontFamily": {
            "type": "string",
            "description": "Editor font."
          },
          "editorFontFamilyGoogle": {
            "type": "boolean",
            "description": "Load `editorFontFamily` from Google Fonts."
          },
          "editorFontSize": {
            "$ref": "#/components/schemas/FontSize",
            "description": "Editor font size."
          },
          "previewFontFamily": {
            "type": "string",
            "description": "Preview font."
          },
          "previewFontFamilyGoogle": {
            "type": "boolean",
            "description": "Load `previewFontFamily` from Google Fonts."
          },
          "previewFontSize": {
            "$ref": "#/components/schemas/FontSize",
            "description": "Preview font size."
          },
          "zenFontFamily": {
            "type": "string",
            "default": "Inter",
            "description": "Zen mode font."
          },
          "zenFontFamilyGoogle": {
            "type": "boolean",
            "default": true,
            "description": "Load `zenFontFamily` from Google Fonts."
          },
          "zenFontSize": {
            "$ref": "#/components/schemas/FontSize",
            "default": "1.25rem",
            "description": "Zen mode font size."
          },
          "zenWordCount": {
            "type": "boolean",
            "default": true,
            "description": "Show the word count in Zen mode."
          },
          "zenShowTitle": {
            "type": "boolean",
            "default": true,
            "description": "Show the title in Zen mode."
          },
          "zenShowControls": {
            "type": "boolean",
            "default": true,
            "description": "Show the controls in Zen mode."
          },
          "zenInteractivePreview": {
            "type": "boolean",
            "description": "Stored for clients. The vylk web app does not use it."
          },
          "shortcutPrefix": {
            "$ref": "#/components/schemas/ShortcutBinding",
            "description": "Key press that starts a shortcut. Exactly one step. The default is `Mod+E`."
          },
          "keyboardShortcuts": {
            "type": "object",
            "maxProperties": 64,
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9.-]{0,63}$"
            },
            "additionalProperties": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/ShortcutBinding"
                },
                {
                  "type": "null"
                }
              ]
            },
            "description": "Custom shortcuts by action name, at most 64. `null` turns off the default shortcut for that action."
          },
          "shortcutConfirmationSkips": {
            "type": "object",
            "maxProperties": 64,
            "propertyNames": {
              "pattern": "^[a-z][a-z0-9.-]{0,63}$"
            },
            "additionalProperties": {
              "type": "boolean",
              "const": true
            },
            "description": "Actions that run without a confirmation, at most 64."
          },
          "_sync_patch": {
            "type": "object",
            "additionalProperties": true,
            "description": "Changed fields. `prefs.save` operations only."
          },
          "_sync_base": {
            "type": "object",
            "additionalProperties": true,
            "description": "Previous values of the changed fields. `prefs.save` operations only."
          }
        }
      },
      "VaultMode": {
        "type": "string",
        "enum": [
          "legacy",
          "preparing",
          "cleaning",
          "encrypted"
        ],
        "description": "`legacy`: plaintext vault. `preparing`: encryption setup is converting notes. `cleaning`: the server is removing plaintext data. `encrypted`: encrypted vault."
      },
      "Bootstrap": {
        "title": "Vault status",
        "type": "object",
        "required": [
          "mode",
          "reset_available",
          "require_strong_passwords",
          "version",
          "revision",
          "instance_id"
        ],
        "properties": {
          "mode": {
            "$ref": "#/components/schemas/VaultMode"
          },
          "reset_available": {
            "type": "boolean",
            "description": "True when `POST /api/vault/reset` can run."
          },
          "instance_id": {
            "type": "string",
            "description": "Identity of the server database. Compare it with the value that you stored."
          },
          "require_strong_passwords": {
            "type": "boolean",
            "description": "True when the client must reject weak encryption passwords."
          },
          "version": {
            "type": "string",
            "description": "vylk version of the server."
          },
          "revision": {
            "type": "string",
            "description": "Build of the web app."
          },
          "vault_id": {
            "$ref": "#/components/schemas/VaultID",
            "description": "Vault ID. Absent in a plaintext vault."
          },
          "epoch": {
            "type": "integer",
            "format": "int64",
            "description": "Current vault epoch. Absent in a plaintext vault."
          },
          "kdf": {
            "type": "object",
            "required": [
              "algorithm",
              "salt",
              "memoryKiB",
              "iterations"
            ],
            "properties": {
              "algorithm": {
                "type": "string",
                "const": "argon2id13",
                "description": "Key derivation function."
              },
              "salt": {
                "$ref": "#/components/schemas/VaultID",
                "description": "Salt. 16 bytes in unpadded base64url."
              },
              "memoryKiB": {
                "type": "integer",
                "minimum": 19456,
                "maximum": 262144,
                "description": "Memory cost in KiB."
              },
              "iterations": {
                "type": "integer",
                "minimum": 2,
                "maximum": 10,
                "description": "Time cost."
              }
            },
            "description": "Argon2id settings for the password key. Absent in a plaintext vault."
          }
        }
      },
      "VaultSetup": {
        "title": "Vault credentials",
        "type": "object",
        "required": [
          "vault_id",
          "kdf_salt",
          "kdf_memory_kib",
          "kdf_iterations",
          "auth_proof",
          "recovery_proof",
          "wrapped_key",
          "wrapped_recovery_key"
        ],
        "properties": {
          "vault_id": {
            "$ref": "#/components/schemas/VaultID",
            "description": "New random vault ID."
          },
          "kdf_salt": {
            "$ref": "#/components/schemas/VaultID",
            "description": "New random Argon2id salt. 16 bytes in unpadded base64url."
          },
          "kdf_memory_kib": {
            "type": "integer",
            "minimum": 19456,
            "maximum": 262144,
            "description": "Argon2id memory cost in KiB."
          },
          "kdf_iterations": {
            "type": "integer",
            "minimum": 2,
            "maximum": 10,
            "description": "Argon2id time cost."
          },
          "auth_proof": {
            "$ref": "#/components/schemas/Proof",
            "description": "Proof derived from the encryption password."
          },
          "recovery_proof": {
            "$ref": "#/components/schemas/Proof",
            "description": "Proof derived from the recovery key."
          },
          "wrapped_key": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Vault key, encrypted with the password key."
          },
          "wrapped_recovery_key": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Vault key, encrypted with the recovery key."
          }
        }
      },
      "MigrationStart": {
        "title": "Encryption setup",
        "allOf": [
          {
            "$ref": "#/components/schemas/VaultSetup"
          },
          {
            "type": "object",
            "required": [
              "old_password"
            ],
            "properties": {
              "old_password": {
                "type": "string",
                "description": "The server password, `VYLK_PASSWORD`."
              }
            }
          }
        ],
        "unevaluatedProperties": false
      },
      "VaultReset": {
        "title": "Vault reset",
        "allOf": [
          {
            "$ref": "#/components/schemas/VaultSetup"
          },
          {
            "type": "object",
            "required": [
              "password"
            ],
            "properties": {
              "password": {
                "type": "string",
                "description": "The server password, `VYLK_PASSWORD`. Not the encryption password."
              }
            }
          }
        ],
        "unevaluatedProperties": false
      },
      "CredentialChange": {
        "title": "Credential change",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "kind",
          "current_proof",
          "new_proof",
          "wrapped_key"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "master",
              "recovery"
            ],
            "description": "`master` replaces the encryption password. `recovery` replaces the recovery key."
          },
          "current_proof": {
            "$ref": "#/components/schemas/Proof",
            "description": "Proof derived from a current credential."
          },
          "current_recovery": {
            "type": "boolean",
            "default": false,
            "description": "True when `current_proof` comes from the recovery key."
          },
          "new_proof": {
            "$ref": "#/components/schemas/Proof",
            "description": "Proof derived from the new credential."
          },
          "wrapped_key": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Existing vault key, encrypted with the key derived from the new credential."
          },
          "kdf_salt": {
            "$ref": "#/components/schemas/VaultID",
            "description": "New Argon2id salt. Required when `kind` is `master`."
          },
          "kdf_memory_kib": {
            "type": "integer",
            "minimum": 19456,
            "maximum": 262144,
            "description": "Argon2id memory cost in KiB. Required when `kind` is `master`."
          },
          "kdf_iterations": {
            "type": "integer",
            "minimum": 2,
            "maximum": 10,
            "description": "Argon2id time cost. Required when `kind` is `master`."
          },
          "sign_out_other_devices": {
            "type": "boolean",
            "default": true,
            "description": "Revoke the sessions of every other device."
          }
        }
      },
      "StagedRequest": {
        "title": "Encrypted copy upload",
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "revision",
          "summary",
          "body"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID"
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "Revision of the plaintext note."
          },
          "summary": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted title and tags."
          },
          "body": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted note text."
          }
        }
      },
      "StagedNote": {
        "title": "Encrypted copy",
        "type": "object",
        "required": [
          "id",
          "revision",
          "summary",
          "body",
          "epoch",
          "body_hash"
        ],
        "properties": {
          "id": {
            "$ref": "#/components/schemas/ID"
          },
          "revision": {
            "type": "integer",
            "format": "int64",
            "description": "Revision of the plaintext note."
          },
          "summary": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted title and tags."
          },
          "body": {
            "$ref": "#/components/schemas/Envelope",
            "description": "Encrypted note text."
          },
          "epoch": {
            "type": "integer",
            "format": "int64",
            "description": "Vault epoch."
          },
          "body_hash": {
            "type": "string",
            "description": "SHA-256 of the stored `body` bytes, in lowercase hexadecimal. Not a hash of the Markdown."
          }
        }
      },
      "AIConfiguration": {
        "title": "AI configuration",
        "type": "object",
        "description": "A saved AI provider configuration.",
        "required": [
          "id",
          "name",
          "url",
          "model",
          "has_key",
          "checked",
          "is_default",
          "revision",
          "output_profile",
          "context_tokens",
          "concurrency"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Configuration ID."
          },
          "name": {
            "type": "string",
            "description": "Display name."
          },
          "url": {
            "type": "string",
            "description": "API base URL."
          },
          "model": {
            "type": "string",
            "description": "Model ID."
          },
          "has_key": {
            "type": "boolean",
            "description": "True when an API key is saved. The API never returns the key."
          },
          "checked": {
            "type": "boolean",
            "description": "True when a test or check succeeded with the current `url`, `model`, `output_profile`, and key. Sessions use only checked configurations."
          },
          "is_default": {
            "type": "boolean",
            "description": "True for the configuration that new sessions use. At most one configuration is the default."
          },
          "revision": {
            "type": "integer",
            "description": "Revision. Each update increases it by 1."
          },
          "output_profile": {
            "type": "string",
            "enum": [
              "",
              "json_schema"
            ],
            "description": "Empty: detect JSON Schema support. `json_schema`: always request JSON Schema output."
          },
          "context_tokens": {
            "type": "integer",
            "description": "Context window in tokens. 0 uses the provider value or 32768."
          },
          "concurrency": {
            "type": "integer",
            "description": "Parallel requests for one job. 0 uses `VYLK_AI_CONCURRENCY`."
          }
        }
      },
      "AIHunk": {
        "title": "AI hunk",
        "type": "object",
        "description": "One suggested change.",
        "required": [
          "id",
          "ref",
          "start",
          "end",
          "before",
          "after",
          "decision"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Hunk ID. Send it as `hunk_id`."
          },
          "ref": {
            "type": "string",
            "description": "Label for people, such as `@1` or `@2.1`. A prompt can name it. The server never reuses a label in a session."
          },
          "start": {
            "type": "integer",
            "description": "Start of `before` in the draft, in UTF-16 code units. 0 when `decision` is `outdated`."
          },
          "end": {
            "type": "integer",
            "description": "End of `before` in the draft, in UTF-16 code units. 0 when `decision` is `outdated`."
          },
          "before": {
            "type": "string",
            "description": "Current text."
          },
          "after": {
            "type": "string",
            "description": "Suggested text."
          },
          "decision": {
            "type": "string",
            "enum": [
              "",
              "accepted",
              "rejected",
              "outdated"
            ],
            "description": "Empty while pending. `outdated`: another edit changed the text, and the hunk cannot be accepted. Reject it to dismiss it."
          }
        }
      },
      "AIJob": {
        "title": "AI job",
        "type": "object",
        "description": "Status of a background job.",
        "required": [
          "id",
          "snapshot_id",
          "version",
          "status",
          "completed",
          "total"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Job ID."
          },
          "snapshot_id": {
            "type": "string",
            "description": "ID of the plan that the job runs."
          },
          "version": {
            "type": "integer",
            "description": "Session `version` when the job finished, or when it started while it runs."
          },
          "status": {
            "type": "string",
            "enum": [
              "running",
              "completed",
              "failed",
              "cancelled"
            ],
            "description": "Job state. Get the session when it is `completed`."
          },
          "completed": {
            "type": "integer",
            "description": "Provider requests that finished."
          },
          "total": {
            "type": "integer",
            "description": "Provider requests planned so far. It can grow while the job runs."
          },
          "error": {
            "type": "string",
            "description": "Reason for a `failed` job."
          }
        }
      },
      "AIPlan": {
        "title": "AI plan",
        "type": "object",
        "description": "A prepared request. A plan does not call the model.",
        "required": [
          "id",
          "version",
          "sections",
          "estimated_input_tokens",
          "whole_context"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Plan ID. Send it as `plan_id` to `start`."
          },
          "version": {
            "type": "integer",
            "description": "Session `version` that the plan is for."
          },
          "sections": {
            "type": "integer",
            "description": "Parts of the shared text that the job handles separately."
          },
          "estimated_input_tokens": {
            "type": "integer",
            "description": "Estimate of the input tokens. Not a tokenizer count."
          },
          "whole_context": {
            "type": "boolean",
            "description": "True when the request asked for the whole shared text at once."
          }
        }
      },
      "AISession": {
        "title": "AI session",
        "type": "object",
        "description": "A temporary AI session. The server keeps it in memory only.",
        "required": [
          "id",
          "note_id",
          "configuration_id",
          "scope",
          "draft",
          "hunks",
          "answer",
          "version",
          "can_undo",
          "changed",
          "thinking_controllable"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Session ID."
          },
          "note_id": {
            "$ref": "#/components/schemas/ID",
            "description": "Note that the session edits."
          },
          "configuration_id": {
            "type": "string",
            "description": "Configuration that the session uses."
          },
          "scope": {
            "type": "string",
            "enum": [
              "none",
              "selection",
              "note"
            ],
            "description": "What the shared text contains."
          },
          "draft": {
            "type": "string",
            "description": "Shared text with the accepted changes."
          },
          "hunks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AIHunk"
            },
            "description": "Suggested changes from the last request that suggested any."
          },
          "answer": {
            "type": "string",
            "description": "Reply from the model to the last request."
          },
          "version": {
            "type": "integer",
            "description": "Version. Each change to the session increases it. Send it with each action."
          },
          "can_undo": {
            "type": "boolean",
            "description": "True when `undo` can revert an acceptance."
          },
          "changed": {
            "type": "boolean",
            "description": "True when `draft` differs from the shared text."
          },
          "thinking_controllable": {
            "type": "boolean",
            "description": "True when requests can set `thinking`. Fixed for the session."
          },
          "job": {
            "$ref": "#/components/schemas/AIJob",
            "description": "Latest job. Absent before the first job."
          }
        }
      }
    }
  }
}
