{
  "openapi": "3.1.0",
  "info": {
    "title": "Worksheets API",
    "version": "1.0.0",
    "summary": "Read, write and automate spreadsheets in Worksheets, the cloud spreadsheet by Beezifi Inc.",
    "description": "All endpoints live under `/api` on your Worksheets host and exchange JSON.\n\n**Authentication.** Send a personal access token: `Authorization: Bearer wst_…`. Create tokens in the app under\n*account menu → AI connections (MCP)*. A token acts as its owner, with the same viewer/editor/owner rights.\n\n**Errors** return `{ \"error\": \"message\", \"code\": \"not_found\", \"requestId\": \"…\" }` with an HTTP status.\n\n**Rate limits.** 600 requests per minute per token by default. Every response includes `RateLimit-Limit`,\n`RateLimit-Remaining` and `RateLimit-Reset`; a `429` means wait `RateLimit-Reset` seconds.\n\n**Edits are live.** Commands are applied to the same live document people have open in the app, broadcast to\nthem immediately and saved within ~1.5 s.",
    "contact": {
      "name": "Beezifi Developer Support",
      "email": "support@beezifi.com"
    },
    "license": {
      "name": "Proprietary. SDKs are MIT licensed.",
      "url": "/terms"
    },
    "termsOfService": "/terms"
  },
  "servers": [
    {
      "url": "{host}/api",
      "variables": {
        "host": {
          "default": "http://localhost:7171",
          "description": "Your Worksheets address"
        }
      }
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Account",
      "description": "The token’s user."
    },
    {
      "name": "Workbooks",
      "description": "Create, list, import, export and manage workbooks."
    },
    {
      "name": "Cells",
      "description": "Read ranges and run editing commands."
    },
    {
      "name": "Sharing",
      "description": "Who can open a workbook."
    },
    {
      "name": "Versions",
      "description": "Snapshots and restore."
    },
    {
      "name": "Reference",
      "description": "Functions and commands available."
    }
  ],
  "paths": {
    "/auth/me": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getMe",
        "summary": "Current user",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user": {
                      "$ref": "#/components/schemas/User"
                    }
                  },
                  "required": [
                    "user"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          }
        }
      }
    },
    "/workbooks": {
      "get": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "listWorkbooks",
        "summary": "List workbooks",
        "description": "Workbooks you own or that are shared with you, newest first (up to 500).",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "workbooks",
                    "samples"
                  ],
                  "properties": {
                    "workbooks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WorkbookListItem"
                      }
                    },
                    "samples": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Template"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      },
      "post": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "createWorkbook",
        "summary": "Create a workbook",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "sample": {
                    "type": "string",
                    "enum": [
                      "budget",
                      "sales",
                      "grades"
                    ],
                    "description": "Start from a template. The template’s title is used; rename afterwards to change it."
                  }
                }
              },
              "examples": {
                "blank": {
                  "value": {
                    "title": "Q4 forecast"
                  }
                },
                "template": {
                  "value": {
                    "sample": "sales"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Created"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/workbooks/import": {
      "post": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "importWorkbook",
        "summary": "Import a file",
        "description": "Creates a workbook from .xlsx, .xlsm, .csv, .tsv or .txt (25 MB by default). The extension of the uploaded filename decides how it is read.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Created"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "warnings": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "413": {
            "$ref": "#/components/responses/E413"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/workbooks/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "getWorkbook",
        "summary": "Get the full workbook document",
        "description": "Includes every cell, style and object. Prefer `/summary` and `/cells` for large workbooks.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "role": {
                      "$ref": "#/components/schemas/Role"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "snapshot": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "patch": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "renameWorkbook",
        "summary": "Rename",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "title": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "delete": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "deleteWorkbook",
        "summary": "Delete, or leave a shared workbook",
        "description": "Owners delete the workbook (recoverable for 30 days through support, then erased). Others remove it from their list.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/summary": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "getWorkbookSummary",
        "summary": "Sheets, used ranges, tables, charts and names",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkbookSummary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/duplicate": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "post": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "duplicateWorkbook",
        "summary": "Make a copy you own",
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Created"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/export": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Workbooks"
        ],
        "operationId": "exportWorkbook",
        "summary": "Export",
        "parameters": [
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "xlsx",
                "csv",
                "tsv",
                "json"
              ],
              "default": "xlsx"
            }
          },
          {
            "name": "sheet",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "For csv/tsv: the sheet to export (default: first/active)."
          }
        ],
        "responses": {
          "200": {
            "description": "The file",
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "text/tab-separated-values": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/cells": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Cells"
        ],
        "operationId": "readCells",
        "summary": "Read a range",
        "parameters": [
          {
            "name": "range",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "default": "A1:Z100"
            },
            "example": "B4:G10",
            "description": "A1 notation. Whole columns/rows are clipped to the used area."
          },
          {
            "name": "sheet",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Sheet name or id. Default: first/active sheet."
          },
          {
            "name": "mode",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "values",
                "display",
                "formulas"
              ],
              "default": "values"
            },
            "description": "`values`: calculated values (errors as `{ \"e\": \"#DIV/0!\" }`, dates as serial numbers). `display`: text as shown. `formulas`: what was typed."
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "sheet",
                    "range",
                    "values"
                  ],
                  "properties": {
                    "sheet": {
                      "type": "string"
                    },
                    "range": {
                      "type": "string"
                    },
                    "values": {
                      "type": "array",
                      "items": {
                        "type": "array",
                        "items": {
                          "$ref": "#/components/schemas/CellValue"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/commands": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "post": {
        "tags": [
          "Cells"
        ],
        "operationId": "runCommands",
        "summary": "Run editing commands",
        "description": "Applies up to 500 commands in order. Processing stops at the first failing command; earlier ones stay applied. Requires editor access. See `GET /commands` for every command and its parameters.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "commands"
                ],
                "properties": {
                  "commands": {
                    "type": "array",
                    "maxItems": 500,
                    "items": {
                      "$ref": "#/components/schemas/Command"
                    }
                  }
                }
              },
              "examples": {
                "formatAndChart": {
                  "value": {
                    "commands": [
                      {
                        "id": "range.setInputs",
                        "params": {
                          "sheet": "Sheet1",
                          "range": "A1",
                          "rows": [
                            [
                              "Month",
                              "Revenue"
                            ],
                            [
                              "Oct",
                              "42000"
                            ],
                            [
                              "Nov",
                              "45500"
                            ]
                          ]
                        }
                      },
                      {
                        "id": "format.set",
                        "params": {
                          "sheet": "Sheet1",
                          "range": "B2:B3",
                          "style": {
                            "nf": "$#,##0"
                          }
                        }
                      },
                      {
                        "id": "chart.add",
                        "params": {
                          "sheet": "Sheet1",
                          "range": "A1:B3",
                          "type": "column",
                          "title": "Revenue"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "results"
                  ],
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CommandResult"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          },
          "429": {
            "$ref": "#/components/responses/E429"
          }
        }
      }
    },
    "/workbooks/{id}/shares": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Sharing"
        ],
        "operationId": "listShares",
        "summary": "List people with access",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "role": {
                      "$ref": "#/components/schemas/Role"
                    },
                    "owner": {
                      "$ref": "#/components/schemas/User"
                    },
                    "shares": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/User"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "role": {
                                "type": "string",
                                "enum": [
                                  "viewer",
                                  "editor"
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "post": {
        "tags": [
          "Sharing"
        ],
        "operationId": "addShare",
        "summary": "Share with someone (owner only)",
        "description": "They need a Worksheets account with that email.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "viewer",
                      "editor"
                    ],
                    "default": "viewer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Shared",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": true
                    },
                    "user": {
                      "$ref": "#/components/schemas/User"
                    },
                    "role": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/E400"
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/shares/{userId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        },
        {
          "name": "userId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "delete": {
        "tags": [
          "Sharing"
        ],
        "operationId": "removeShare",
        "summary": "Remove someone’s access (owner only)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/versions": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Versions"
        ],
        "operationId": "listVersions",
        "summary": "List versions (newest 100)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "versions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Version"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      },
      "post": {
        "tags": [
          "Versions"
        ],
        "operationId": "saveVersion",
        "summary": "Save a version",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "label": {
                    "type": "string",
                    "maxLength": 120
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Saved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/versions/{versionId}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        },
        {
          "$ref": "#/components/parameters/VersionId"
        }
      ],
      "get": {
        "tags": [
          "Versions"
        ],
        "operationId": "getVersion",
        "summary": "Get a version’s document",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "snapshot": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/versions/{versionId}/restore": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        },
        {
          "$ref": "#/components/parameters/VersionId"
        }
      ],
      "post": {
        "tags": [
          "Versions"
        ],
        "operationId": "restoreVersion",
        "summary": "Restore a version",
        "description": "The current state is saved as a version labelled “Before restore” first. Everyone viewing reloads.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "403": {
            "$ref": "#/components/responses/E403"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/workbooks/{id}/activity": {
      "parameters": [
        {
          "$ref": "#/components/parameters/WorkbookId"
        }
      ],
      "get": {
        "tags": [
          "Versions"
        ],
        "operationId": "listActivity",
        "summary": "Recent changes (newest 200)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "command": {
                            "type": "string"
                          },
                          "summary": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "user": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/E401"
          },
          "404": {
            "$ref": "#/components/responses/E404"
          }
        }
      }
    },
    "/functions": {
      "get": {
        "tags": [
          "Reference"
        ],
        "operationId": "listFunctions",
        "summary": "Worksheets functions",
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "enum": [
                          "Financial",
                          "Logical",
                          "Text",
                          "Date & Time",
                          "Lookup & Reference",
                          "Math & Trig",
                          "Statistical",
                          "Engineering",
                          "Information"
                        ]
                      }
                    },
                    "functions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "cat": {
                            "type": "string"
                          },
                          "args": {
                            "type": "string"
                          },
                          "desc": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/commands": {
      "get": {
        "tags": [
          "Reference"
        ],
        "operationId": "listCommands",
        "summary": "Commands accepted by /commands",
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "commands": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "params": {
                            "type": "string"
                          },
                          "desc": {
                            "type": "string"
                          },
                          "undoable": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "tags": [
          "Reference"
        ],
        "operationId": "health",
        "summary": "Health check",
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Database unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "wst_…",
        "description": "Personal access token from account menu → AI connections."
      }
    },
    "parameters": {
      "WorkbookId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "VersionId": {
        "name": "versionId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        }
      }
    },
    "headers": {
      "X-Request-Id": {
        "schema": {
          "type": "string"
        },
        "description": "Unique id for this request; quote it to support."
      }
    },
    "responses": {
      "E400": {
        "description": "Invalid request",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E401": {
        "description": "Missing, invalid or revoked token",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E403": {
        "description": "Not allowed (e.g. view-only access)",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E404": {
        "description": "Not found or not shared with you",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E413": {
        "description": "Too large",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "E429": {
        "description": "Rate limited; retry after RateLimit-Reset seconds",
        "headers": {
          "X-Request-Id": {
            "$ref": "#/components/headers/X-Request-Id"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "code"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "enum": [
              "invalid_request",
              "unauthorized",
              "forbidden",
              "not_found",
              "conflict",
              "payload_too_large",
              "rate_limited",
              "server_error"
            ]
          },
          "requestId": {
            "type": "string"
          }
        }
      },
      "Ok": {
        "type": "object",
        "properties": {
          "ok": {
            "const": true
          }
        }
      },
      "Role": {
        "type": "string",
        "enum": [
          "owner",
          "editor",
          "viewer"
        ]
      },
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "budget",
              "sales",
              "grades"
            ]
          },
          "title": {
            "type": "string"
          },
          "desc": {
            "type": "string"
          }
        }
      },
      "Created": {
        "type": "object",
        "required": [
          "id",
          "title"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          }
        }
      },
      "WorkbookListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "role": {
            "$ref": "#/components/schemas/Role"
          },
          "owner_name": {
            "type": "string"
          },
          "owner_email": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "size_bytes": {
            "type": "integer"
          }
        }
      },
      "WorkbookSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "role": {
            "$ref": "#/components/schemas/Role"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "sheets": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                },
                "usedRange": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "example": "A1:I17"
                },
                "hidden": {
                  "type": "boolean"
                },
                "frozen": {
                  "type": "object",
                  "properties": {
                    "rows": {
                      "type": "integer"
                    },
                    "cols": {
                      "type": "integer"
                    }
                  }
                },
                "tables": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "range": {
                        "type": "string"
                      }
                    }
                  }
                },
                "charts": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "integer"
                      },
                      "type": {
                        "type": "string"
                      },
                      "title": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "names": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "ref": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CellValue": {
        "description": "number, string, boolean, null, or an error object",
        "oneOf": [
          {
            "type": "number"
          },
          {
            "type": "string"
          },
          {
            "type": "boolean"
          },
          {
            "type": "null"
          },
          {
            "type": "object",
            "required": [
              "e"
            ],
            "properties": {
              "e": {
                "type": "string",
                "example": "#DIV/0!"
              }
            }
          }
        ]
      },
      "Command": {
        "type": "object",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "cell.set",
              "range.setValues",
              "range.setInputs",
              "range.clear",
              "range.paste",
              "range.move",
              "range.fill",
              "format.set",
              "format.toggle",
              "format.borders",
              "format.cellStyle",
              "format.painter",
              "sheet.colWidth",
              "sheet.rowHeight",
              "rows.insert",
              "rows.delete",
              "rows.hide",
              "cols.insert",
              "cols.delete",
              "cols.hide",
              "cells.insert",
              "cells.delete",
              "cells.merge",
              "cells.unmerge",
              "sheet.add",
              "sheet.duplicate",
              "sheet.delete",
              "sheet.rename",
              "sheet.move",
              "sheet.tabColor",
              "sheet.gridlines",
              "sheet.hide",
              "sheet.freeze",
              "data.sort",
              "data.filter",
              "data.filterColumn",
              "data.reapply",
              "data.removeDuplicates",
              "data.replaceAll",
              "cf.add",
              "cf.delete",
              "cf.clear",
              "table.add",
              "table.update",
              "table.delete",
              "chart.add",
              "chart.update",
              "chart.delete",
              "sparkline.add",
              "sparkline.clear",
              "note.set",
              "link.set",
              "validation.set",
              "name.set",
              "name.delete",
              "workbook.title"
            ],
            "description": "- `cell.set` `{sheet, cell, input}` Sets a cell (or every cell of a range) as if the input were typed: \"=...\" is a formula, \"12%\" a percentage, etc.\n- `range.setValues` `{sheet, range, values: [[...]]}` Writes a 2-D array of raw values from the top-left of range; strings starting with \"=\" are formulas.\n- `range.setInputs` `{sheet, range, rows: [[text]]}` Writes typed text (parsed like keyboard entry) from the top-left of range.\n- `range.clear` `{sheet, range, what: contents|formats|all|notes|links}` Clear\n- `range.paste` `{sheet, range, data: {rows, cols, cells: [[{v,f,st}]], src: {r, c}}, mode, transpose, skipBlanks}` Paste\n- `range.move` `{sheet, range, toSheet?, to}` Cut and paste: moves cells and updates references to them.\n- `range.fill` `{sheet, src, dest}` Fill handle / Fill Down / Fill Right: extends series, increments numbers and dates, shifts formulas.\n- `format.set` `{sheet, range, style: {b,i,u,st,ff,fs,fc,bg,ha,va,wrap,nf,indent,rot,bd}}` Merges style properties into a range; null removes a property.\n- `format.toggle` `{sheet, range, prop: b|i|u|st|wrap, on?}` Format Cells\n- `format.borders` `{sheet, range, preset: all|outside|thickOutside|inside|none|top|bottom|left|right|doubleBottom|thickBottom|topBottom|topDoubleBottom, style, color}` Borders\n- `format.cellStyle` `{sheet, range, name}` Cell Style\n- `format.painter` `{sheet, src, dest}` Format Painter\n- `sheet.colWidth` `{sheet, cols: \"B:D\", width | widths: []}` Column Width\n- `sheet.rowHeight` `{sheet, rows: \"2:5\", height | heights: []}` Row Height\n- `rows.insert` `{sheet, rows: \"3:4\"}` Insert Rows\n- `rows.delete` `{sheet, rows}` Delete Rows\n- `rows.hide` `{sheet, rows, hidden: true|false}` Hide Rows\n- `cols.insert` `{sheet, cols: \"B:C\"}` Insert Columns\n- `cols.delete` `{sheet, cols}` Delete Columns\n- `cols.hide` `{sheet, cols, hidden: true|false}` Hide Columns\n- `cells.insert` `{sheet, range, shift: down|right}` Insert Cells\n- `cells.delete` `{sheet, range, shift: up|left}` Delete Cells\n- `cells.merge` `{sheet, range, across?, center?}` Merge Cells\n- `cells.unmerge` `{sheet, range}` Unmerge Cells\n- `sheet.add` `{name?, index?}` Insert Sheet\n- `sheet.duplicate` `{sheet, name?}` Duplicate Sheet\n- `sheet.delete` `{sheet}` Delete Sheet\n- `sheet.rename` `{sheet, name}` Rename Sheet\n- `sheet.move` `{sheet, index}` Move Sheet\n- `sheet.tabColor` `{sheet, value}` Tab Color\n- `sheet.gridlines` `{sheet, value}` Gridlines\n- `sheet.hide` `{sheet, value}` Hide Sheet\n- `sheet.freeze` `{sheet, rows, cols}` Freeze Panes\n- `data.sort` `{sheet, range, keys: [{col: \"B\", desc}], header}` Sort\n- `data.filter` `{sheet, range | null}` Turns AutoFilter on for a range (header row first), or off when range is null.\n- `data.filterColumn` `{sheet, col, criteria: {values: [...]} | {op, value} | {top} | null}` Filter\n- `data.reapply`  Reapply Filter\n- `data.removeDuplicates` `{sheet, range, cols?, header}` Remove Duplicates\n- `data.replaceAll` `{find, replace, sheet?, range?, matchCase, wholeCell}` Replace All\n- `cf.add` `{sheet, range, rule: {type, operator, values, style|preset, colors, color, set, ...}}` Conditional Formatting\n- `cf.delete` `{sheet, id}` Delete Rule\n- `cf.clear` `{sheet, range?}` Clear Rules\n- `table.add` `{sheet, range, name?, style?, header?}` Format as Table\n- `table.update` `{sheet, table, props: {name, style, banded, filterButton, totalRow, totals: {Column: sum|average|count|max|min|none}}}` Table Design\n- `table.delete` `{sheet, table}` Convert to Range\n- `chart.add` `{sheet, range, type: column|columnStacked|bar|barStacked|line|lineMarkers|area|pie|doughnut|scatter, title, at, width, height}` Insert Chart\n- `chart.update` `{sheet, id, props: {type, title, r, c, dx, dy, w, h, legend, range}}` Format Chart\n- `chart.delete` `{sheet, id}` Delete Chart\n- `sparkline.add` `{sheet, range (data), at (location), type: line|column|winloss}` Insert Sparklines\n- `sparkline.clear` `{sheet, range}` Clear Sparklines\n- `note.set` `{sheet, cell, text | null}` Note\n- `link.set` `{sheet, cell, url | null, text?}` Link\n- `validation.set` `{sheet, range, rule: {type: \"list\", values: [...] | source: \"=A1:A5\", strict} | null}` Data Validation\n- `name.set` `{name, ref, comment?}` Define Name\n- `name.delete` `{name}` Delete Name\n- `workbook.title` `{title}` Rename Workbook"
          },
          "params": {
            "type": "object",
            "additionalProperties": true,
            "description": "Most commands take `sheet` (name or id; default first/active) and `range` in A1 notation."
          }
        }
      },
      "CommandResult": {
        "type": "object",
        "required": [
          "ok"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "seq": {
            "type": "integer",
            "description": "Change number in the live document"
          },
          "result": {
            "description": "Command-specific, e.g. `{ id }` for chart.add, `{ id, name }` for sheet.add"
          },
          "error": {
            "type": "string"
          }
        }
      },
      "Version": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "label": {
            "type": [
              "string",
              "null"
            ]
          },
          "size_bytes": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "author": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  }
}
