{
  "openapi": "3.1.0",
  "info": {
    "title": "AIStoryHub API",
    "version": "1.0.0",
    "description": "A REST API for reading and creating stories and chapters on AIStoryHub outside the app. Authenticate with a scoped bearer token created under Settings, Developer API. Scopes are explicit, so write access does not imply read access.",
    "contact": {
      "url": "https://aistoryhub.co/developers"
    },
    "termsOfService": "https://aistoryhub.co/terms"
  },
  "servers": [
    { "url": "https://aistoryhub.co/api/v1" }
  ],
  "security": [{ "bearerAuth": [] }],
  "tags": [
    { "name": "account", "description": "The authenticated token's owner." },
    { "name": "stories", "description": "Stories owned by the token holder." },
    { "name": "chapters", "description": "Chapters and scenes within a story." },
    { "name": "world", "description": "World-building entries (characters, locations, lore, etc.)." },
    { "name": "voice", "description": "Voiceprints: reusable 33-dial Style Lab voice profiles, and the one pinned to a story." },
    { "name": "ai", "description": "AI generation and revision. Runs on your own BYOK provider key." },
    { "name": "skills", "description": "The prose-instruction skills catalog installable onto this connection." },
    { "name": "memory", "description": "Durable memories (preference/feedback/context/reference) that persist across sessions." },
    { "name": "rules", "description": "Story Rules: a reusable writing-instruction library, not tied to one story." }
  ],
  "paths": {
    "/me": {
      "get": {
        "operationId": "getMe",
        "tags": ["account"],
        "summary": "Get the token owner's account",
        "x-required-scope": "account:read",
        "responses": {
          "200": {
            "description": "The token owner's account.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Account" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories": {
      "get": {
        "operationId": "listStories",
        "tags": ["stories"],
        "summary": "List your stories",
        "x-required-scope": "stories:read",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Max results per page.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 }
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Number of results to skip.",
            "schema": { "type": "integer", "minimum": 0, "default": 0 }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of stories, newest updated first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data", "pagination"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/Story" } },
                    "pagination": { "$ref": "#/components/schemas/Pagination" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createStory",
        "tags": ["stories"],
        "summary": "Create a story",
        "x-required-scope": "stories:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/StoryCreate" } }
          }
        },
        "responses": {
          "201": {
            "description": "The created story.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Story" } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}": {
      "get": {
        "operationId": "getStory",
        "tags": ["stories"],
        "summary": "Fetch a single story",
        "x-required-scope": "stories:read",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "responses": {
          "200": {
            "description": "The story.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Story" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "updateStory",
        "tags": ["stories"],
        "summary": "Update a story's bible fields, including the outline",
        "description": "Provide only the fields to change: logline/genre/tone/etc and the story-level spine (outline).",
        "x-required-scope": "stories:write",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/StoryCreate" } } }
        },
        "responses": {
          "200": {
            "description": "The updated story.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Story" } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/chapters": {
      "get": {
        "operationId": "listChapters",
        "tags": ["chapters"],
        "summary": "List a story's chapters and scenes",
        "description": "Content is omitted from list results; fetch a single chapter for its `content`.",
        "x-required-scope": "stories:read",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "responses": {
          "200": {
            "description": "The story's chapters and scenes, in manuscript order.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": {
                    "data": { "type": "array", "items": { "$ref": "#/components/schemas/ChapterSummary" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createChapter",
        "tags": ["chapters"],
        "summary": "Create a chapter or scene",
        "description": "Defaults to the end of the manuscript unless order_index is given. Leave content empty to draft into it afterward with /ai/generate.",
        "x-required-scope": "stories:write",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["title"],
                "properties": {
                  "title": { "type": "string" },
                  "type": { "type": "string", "enum": ["chapter", "scene"], "default": "chapter" },
                  "content": { "type": "string" },
                  "parent_id": { "type": "string", "format": "uuid" },
                  "order_index": { "type": "integer", "minimum": 0 }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The created chapter.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChapterDetail" } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/chapters/{chapterId}": {
      "get": {
        "operationId": "getChapter",
        "tags": ["chapters"],
        "summary": "Fetch one chapter with its content",
        "x-required-scope": "stories:read",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          {
            "name": "chapterId",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "The chapter, including its content.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChapterDetail" } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "updateChapter",
        "tags": ["chapters"],
        "summary": "Update a chapter or scene's title, content, or position",
        "description": "Full replacement of `content` when provided -- e.g. save generated prose into a chapter. Chapters are stored as plain text with a blank line between paragraphs.",
        "x-required-scope": "stories:write",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          { "name": "chapterId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": { "type": "string" },
                  "content": { "type": "string" },
                  "order_index": { "type": "integer", "minimum": 0 }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated chapter.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChapterDetail" } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "delete": {
        "operationId": "deleteChapter",
        "tags": ["chapters"],
        "summary": "Delete a chapter or scene",
        "description": "Irreversible. The first call always fails with `confirmation_required`; retry with `confirm: true` to actually delete.",
        "x-required-scope": "stories:write",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          { "name": "chapterId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": { "type": "object", "properties": { "confirm": { "type": "boolean" } } }
            }
          }
        },
        "responses": {
          "200": { "description": "Deleted.", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "description": "Destructive action needs `confirm: true` to proceed, or the resource changed since you last read it.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/chapters/{chapterId}/apply-edit": {
      "post": {
        "operationId": "applyEdit",
        "tags": ["chapters"],
        "summary": "Replace one exact, unique text span in a chapter",
        "description": "A literal patch, not an AI rewrite. `old_text` must match exactly one place in the chapter's current content or the call fails instead of guessing. Use find_replace for renaming something everywhere it appears.",
        "x-required-scope": "stories:write",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          { "name": "chapterId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["old_text", "new_text"],
                "properties": {
                  "old_text": { "type": "string", "description": "Exact text to replace, copied verbatim from the chapter. Must be unique in the chapter." },
                  "new_text": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The updated chapter.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChapterDetail" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/manuscript/find-replace": {
      "post": {
        "operationId": "findReplace",
        "tags": ["chapters"],
        "summary": "Deterministic find/replace across one chapter or the whole manuscript",
        "description": "No AI rewrite -- a literal text substitution, not a regex. Story-wide replacements snapshot each affected chapter first so they stay undoable.",
        "x-required-scope": "stories:write",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["find", "replace", "scope"],
                "properties": {
                  "find": { "type": "string" },
                  "replace": { "type": "string" },
                  "scope": { "type": "string", "enum": ["chapter", "story"] },
                  "chapter_id": { "type": "string", "format": "uuid", "description": "Required when scope is \"chapter\"." },
                  "case_sensitive": { "type": "boolean", "default": false },
                  "whole_word": { "type": "boolean", "default": false }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Match count and the chapters affected.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "replacements": { "type": "integer" }, "chapters_affected": { "type": "integer" } } } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/world": {
      "get": {
        "operationId": "listWorld",
        "tags": ["world"],
        "summary": "List world-building entries",
        "x-required-scope": "world:read",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          {
            "name": "type",
            "in": "query",
            "description": "Filter by world type.",
            "schema": { "type": "string", "enum": ["character", "species", "faction", "location", "item", "lore", "timeline"] }
          }
        ],
        "responses": {
          "200": {
            "description": "World entries.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["data"],
                  "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/WorldNode" } } }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createWorld",
        "tags": ["world"],
        "summary": "Create a world-building entry",
        "x-required-scope": "world:write",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WorldNodeCreate" } } }
        },
        "responses": {
          "201": {
            "description": "The created world entry.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WorldNode" } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/world/{nodeId}": {
      "get": {
        "operationId": "getWorldNode",
        "tags": ["world"],
        "summary": "Fetch a world-building entry",
        "x-required-scope": "world:read",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          { "name": "nodeId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": { "description": "The world entry.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WorldNode" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "updateWorldNode",
        "tags": ["world"],
        "summary": "Update a world-building entry",
        "x-required-scope": "world:write",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          { "name": "nodeId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": { "type": "string" },
                  "content": { "type": "string" },
                  "tags": { "type": "array", "items": { "type": "string" } },
                  "metadata": { "type": "object", "additionalProperties": true }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The updated world entry.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/WorldNode" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "delete": {
        "operationId": "deleteWorldNode",
        "tags": ["world"],
        "summary": "Delete a world-building entry",
        "x-required-scope": "world:write",
        "parameters": [
          { "$ref": "#/components/parameters/StoryId" },
          { "name": "nodeId", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": { "description": "Deleted.", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/stories/{id}/voice": {
      "get": {
        "operationId": "getStoryVoice",
        "tags": ["voice"],
        "summary": "Fetch the story's pinned Voiceprint",
        "x-required-scope": "voice:read",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "responses": {
          "200": {
            "description": "The pinned Voiceprint, or null if none is pinned.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "voiceprint_id": { "type": ["string", "null"], "format": "uuid" }, "voiceprint": { "anyOf": [{ "$ref": "#/components/schemas/Voiceprint" }, { "type": "null" }] } } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "setStoryVoice",
        "tags": ["voice"],
        "summary": "Pin or clear the story's Voiceprint",
        "x-required-scope": "voice:write",
        "parameters": [{ "$ref": "#/components/parameters/StoryId" }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "required": ["voiceprint_id"], "properties": { "voiceprint_id": { "type": ["string", "null"], "format": "uuid", "description": "A Voiceprint id you own, or null to clear the pin." } } } } }
        },
        "responses": {
          "200": { "description": "The pin's new state.", "content": { "application/json": { "schema": { "type": "object", "properties": { "voiceprint_id": { "type": ["string", "null"], "format": "uuid" } } } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/ai/generate": {
      "post": {
        "operationId": "aiGenerate",
        "tags": ["ai"],
        "summary": "Generate prose (Generate Pro)",
        "description": "Runs on the token owner's own AI provider key (BYOK).",
        "x-required-scope": "ai:generate",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["story_id", "instruction"],
                "properties": {
                  "story_id": { "type": "string", "format": "uuid" },
                  "instruction": { "type": "string" },
                  "chapter_id": { "type": "string", "format": "uuid" },
                  "file_type": { "type": "string", "default": "chapter" },
                  "file_name": { "type": "string" },
                  "special_instructions": { "type": "string" },
                  "references": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": { "id": { "type": "string" }, "type": { "type": "string" } }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The generated prose.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AiText" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/ai/revise": {
      "post": {
        "operationId": "aiRevise",
        "tags": ["ai"],
        "summary": "Revise text against an instruction",
        "description": "Runs on the token owner's own AI provider key (BYOK).",
        "x-required-scope": "ai:revise",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["story_id", "text", "instruction"],
                "properties": {
                  "story_id": { "type": "string", "format": "uuid" },
                  "text": { "type": "string" },
                  "instruction": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The revised text.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AiText" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/ai/grit-pass": {
      "post": {
        "operationId": "aiGritPass",
        "tags": ["ai"],
        "summary": "Run the Human Grit Pass over text",
        "description": "Runs on the token owner's own AI provider key (BYOK).",
        "x-required-scope": "ai:revise",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["story_id", "text"],
                "properties": {
                  "story_id": { "type": "string", "format": "uuid" },
                  "text": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The grit-passed rewrite.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AiText" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/ai/editorial-pass": {
      "post": {
        "operationId": "aiEditorialPass",
        "tags": ["ai"],
        "summary": "Get structured editorial notes on a chapter",
        "description": "Runs on the token owner's own AI provider key (BYOK). Notes are grounded in the story bible and the author's voice style.",
        "x-required-scope": "ai:editorial",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["story_id", "paragraphs"],
                "properties": {
                  "story_id": { "type": "string", "format": "uuid" },
                  "paragraphs": {
                    "type": "array",
                    "items": { "type": "string" },
                    "description": "The chapter split into text blocks; note anchors reference these by index."
                  },
                  "file_name": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Editorial notes, fence list, and scope limits.",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/EditorialResult" } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/ai/self-check": {
      "post": {
        "operationId": "aiSelfCheck",
        "tags": ["ai"],
        "summary": "Score a chapter or passage for AI tells (0-100)",
        "description": "Pure analysis against the platform's AI-cliche corpus and structural detectors -- no AI model call, so it doesn't require a BYOK key.",
        "x-required-scope": "stories:read",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["story_id"],
                "properties": {
                  "story_id": { "type": "string", "format": "uuid" },
                  "chapter_id": { "type": "string", "format": "uuid", "description": "Score this chapter's current content." },
                  "text": { "type": "string", "description": "Or score this pasted passage instead." }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A 0-100 score (lower is cleaner) with the worst offenders listed.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "score": { "type": "integer" }, "findings": { "type": "array", "items": { "type": "object" } } } } } }
          },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/skills": {
      "get": {
        "operationId": "listSkills",
        "tags": ["skills"],
        "summary": "List the skills catalog",
        "description": "First-party prose-instruction skills plus any custom skills the token owner has written, flagged with which are installed on this connection.",
        "x-required-scope": "skills:read",
        "responses": {
          "200": {
            "description": "The skills catalog.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Skill" } } } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/skills/{slug}": {
      "get": {
        "operationId": "loadSkill",
        "tags": ["skills"],
        "summary": "Load a skill's prose instructions",
        "description": "Fails if the skill isn't installed on this connection.",
        "x-required-scope": "skills:read",
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "The skill's full instructions.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Skill" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/skills/{slug}/export": {
      "get": {
        "operationId": "exportSkill",
        "tags": ["skills"],
        "summary": "Download a skill as a Claude Code SKILL.md file",
        "description": "A snapshot of the revision installed at download time. Re-download after a skill is revised to pick up the current version.",
        "x-required-scope": "skills:read",
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "The SKILL.md file.", "content": { "text/markdown": { "schema": { "type": "string" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/memory": {
      "get": {
        "operationId": "listMemories",
        "tags": ["memory"],
        "summary": "List durable memories",
        "description": "Account-scoped memories, plus a story's own if story_id is given.",
        "x-required-scope": "memory:read",
        "parameters": [{ "name": "story_id", "in": "query", "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "Saved memories.", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Memory" } } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "saveMemory",
        "tags": ["memory"],
        "summary": "Save or update a memory by name",
        "description": "Reusing an existing name overwrites it instead of creating a duplicate.",
        "x-required-scope": "memory:write",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["type", "name", "description", "content"],
                "properties": {
                  "type": { "type": "string", "enum": ["preference", "feedback", "context", "reference"] },
                  "name": { "type": "string", "description": "Short slug identifying this memory. Reusing an existing name overwrites it." },
                  "description": { "type": "string", "description": "One-line summary shown in every future briefing." },
                  "content": { "type": "string" },
                  "scope": { "type": "string", "enum": ["story", "account"], "default": "story" },
                  "story_id": { "type": "string", "format": "uuid", "description": "Required when scope is \"story\"." }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "The saved memory.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Memory" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/memory/{name}": {
      "delete": {
        "operationId": "forgetMemory",
        "tags": ["memory"],
        "summary": "Delete a memory by name",
        "x-required-scope": "memory:write",
        "parameters": [
          { "name": "name", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "story_id", "in": "query", "schema": { "type": "string", "format": "uuid" }, "description": "Required when the memory was saved with scope \"story\"." }
        ],
        "responses": {
          "200": { "description": "Deleted.", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/rules": {
      "get": {
        "operationId": "listRules",
        "tags": ["rules"],
        "summary": "List your Story Rules library",
        "x-required-scope": "rules:read",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "default": 0 } }
        ],
        "responses": {
          "200": {
            "description": "A page of Story Rules.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Rule" } }, "pagination": { "$ref": "#/components/schemas/Pagination" } } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createRule",
        "tags": ["rules"],
        "summary": "Create or update a Story Rule",
        "description": "Reusing an existing name overwrites that rule instead of creating a duplicate.",
        "x-required-scope": "rules:write",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RuleCreate" } } }
        },
        "responses": {
          "201": { "description": "The created or updated rule.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Rule" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/rules/{id}": {
      "get": {
        "operationId": "getRule",
        "tags": ["rules"],
        "summary": "Fetch a single Story Rule",
        "x-required-scope": "rules:read",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The rule.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Rule" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "updateRule",
        "tags": ["rules"],
        "summary": "Update a Story Rule's fields",
        "x-required-scope": "rules:write",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RuleCreate" } } }
        },
        "responses": {
          "200": { "description": "The updated rule.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Rule" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "delete": {
        "operationId": "deleteRule",
        "tags": ["rules"],
        "summary": "Delete a Story Rule",
        "description": "Irreversible. The first call always fails with `confirmation_required`; retry with `confirm: true` to actually delete.",
        "x-required-scope": "rules:write",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": {
          "content": { "application/json": { "schema": { "type": "object", "properties": { "confirm": { "type": "boolean" } } } } }
        },
        "responses": {
          "200": { "description": "Deleted.", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "description": "Needs `confirm: true` to proceed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/voiceprints": {
      "get": {
        "operationId": "listVoiceprints",
        "tags": ["voice"],
        "summary": "List your Voiceprint library",
        "x-required-scope": "voice:read",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 25 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0, "default": 0 } }
        ],
        "responses": {
          "200": {
            "description": "A page of Voiceprints.",
            "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/Voiceprint" } }, "pagination": { "$ref": "#/components/schemas/Pagination" } } } } }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "operationId": "createVoiceprint",
        "tags": ["voice"],
        "summary": "Create a Voiceprint",
        "description": "Unspecified dials default to 50 (neutral).",
        "x-required-scope": "voice:write",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VoiceprintCreate" } } }
        },
        "responses": {
          "201": { "description": "The created Voiceprint.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Voiceprint" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/voiceprints/{id}": {
      "get": {
        "operationId": "getVoiceprint",
        "tags": ["voice"],
        "summary": "Fetch a single Voiceprint",
        "x-required-scope": "voice:read",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "responses": {
          "200": { "description": "The voiceprint.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Voiceprint" } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "patch": {
        "operationId": "updateVoiceprint",
        "tags": ["voice"],
        "summary": "Update a Voiceprint's fields",
        "x-required-scope": "voice:write",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VoiceprintCreate" } } }
        },
        "responses": {
          "200": { "description": "The updated voiceprint.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Voiceprint" } } } },
          "400": { "$ref": "#/components/responses/InvalidRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "delete": {
        "operationId": "deleteVoiceprint",
        "tags": ["voice"],
        "summary": "Delete a Voiceprint",
        "description": "Irreversible. The first call always fails with `confirmation_required`; retry with `confirm: true` to actually delete.",
        "x-required-scope": "voice:write",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }],
        "requestBody": {
          "content": { "application/json": { "schema": { "type": "object", "properties": { "confirm": { "type": "boolean" } } } } }
        },
        "responses": {
          "200": { "description": "Deleted.", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" } } } } } },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "409": { "description": "Needs `confirm: true` to proceed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ash_...",
        "description": "Create a token under Settings, Developer API and send it as `Authorization: Bearer ash_...`. Each endpoint requires one scope, listed per-operation via the `x-required-scope` extension; see https://aistoryhub.co/developers for the full scope list."
      }
    },
    "parameters": {
      "StoryId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      }
    },
    "schemas": {
      "Account": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "email": { "type": ["string", "null"], "format": "email" },
          "plan": { "type": "string", "enum": ["free", "paid", "admin"] },
          "token_scopes": { "type": "array", "items": { "type": "string" } }
        }
      },
      "Story": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "description": { "type": ["string", "null"] },
          "genre": { "type": ["string", "null"] },
          "tense": { "type": ["string", "null"] },
          "language": { "type": ["string", "null"] },
          "mood": { "type": ["string", "null"] },
          "time_period": { "type": ["string", "null"] },
          "tone": { "type": ["string", "null"] },
          "pov": { "type": ["string", "null"] },
          "status": { "type": ["string", "null"] },
          "is_public": { "type": "boolean" },
          "word_count": { "type": "integer" },
          "target_word_count": { "type": ["integer", "null"] },
          "cover_image_url": { "type": ["string", "null"], "format": "uri" },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "StoryCreate": {
        "type": "object",
        "required": ["title"],
        "properties": {
          "title": { "type": "string" },
          "description": { "type": "string" },
          "genre": { "type": "string" },
          "tense": { "type": "string" },
          "language": { "type": "string" },
          "mood": { "type": "string" },
          "time_period": { "type": "string" },
          "tone": { "type": "string" },
          "pov": { "type": "string" },
          "banned_words": { "type": "array", "items": { "type": "string" } },
          "target_word_count": { "type": "integer", "default": 50000 }
        }
      },
      "ChapterSummary": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "type": { "type": "string", "enum": ["chapter", "scene"] },
          "order": { "type": "integer" },
          "word_count": { "type": "integer" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "ChapterDetail": {
        "allOf": [
          { "$ref": "#/components/schemas/ChapterSummary" },
          {
            "type": "object",
            "properties": {
              "content": { "type": "string" }
            }
          }
        ]
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "limit": { "type": "integer" },
          "offset": { "type": "integer" },
          "total": { "type": "integer" }
        }
      },
      "WorldNode": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "type": { "type": "string", "enum": ["character", "species", "faction", "location", "item", "lore", "timeline"] },
          "title": { "type": "string" },
          "content": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "metadata": { "type": "object", "additionalProperties": true },
          "order": { "type": "integer" },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "WorldNodeCreate": {
        "type": "object",
        "required": ["type", "title"],
        "properties": {
          "type": { "type": "string", "enum": ["character", "species", "faction", "location", "item", "lore", "timeline"] },
          "title": { "type": "string" },
          "content": { "type": "string" },
          "tags": { "type": "array", "items": { "type": "string" } },
          "metadata": { "type": "object", "additionalProperties": true }
        }
      },
      "AiText": {
        "type": "object",
        "properties": { "text": { "type": "string" } }
      },
      "EditorialNote": {
        "type": "object",
        "description": "A single editorial note anchored to the chapter text by verbatim quote.",
        "properties": {
          "category": { "type": "string" },
          "scope": { "type": "string", "enum": ["line", "structural"] },
          "confidence": { "type": "string", "enum": ["high", "medium", "low"] },
          "note": { "type": "string" },
          "suggestedInstruction": { "type": "string" },
          "anchorStart": { "type": "string" },
          "anchorEnd": { "type": "string" },
          "paragraphIndex": { "type": "integer" },
          "paragraphIndexEnd": { "type": "integer" }
        },
        "additionalProperties": true
      },
      "EditorialResult": {
        "type": "object",
        "properties": {
          "notes": { "type": "array", "items": { "$ref": "#/components/schemas/EditorialNote" } },
          "fence_list": { "type": "array", "items": { "type": "string" } },
          "scope_limits": {}
        }
      },
      "Skill": {
        "type": "object",
        "properties": {
          "slug": { "type": "string" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "installed": { "type": "boolean" },
          "instructions": { "type": "string", "description": "Present on the single-skill GET; omitted from the catalog list." }
        }
      },
      "Memory": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "type": { "type": "string", "enum": ["preference", "feedback", "context", "reference"] },
          "description": { "type": "string" },
          "content": { "type": "string" },
          "scope": { "type": "string", "enum": ["story", "account"] },
          "story_id": { "type": ["string", "null"], "format": "uuid" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "Rule": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "instructions": { "type": "string" },
          "special_instructions": { "type": ["string", "null"] },
          "context": { "type": ["string", "null"] },
          "description": { "type": ["string", "null"] },
          "content_rating": { "type": "string", "enum": ["general", "adult"] },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "RuleCreate": {
        "type": "object",
        "required": ["name", "instructions"],
        "properties": {
          "name": { "type": "string", "description": "Reusing an existing name overwrites it." },
          "instructions": { "type": "string" },
          "special_instructions": { "type": "string" },
          "context": { "type": "string" },
          "description": { "type": "string" },
          "content_rating": { "type": "string", "enum": ["general", "adult"], "default": "general" }
        }
      },
      "VoiceDials": {
        "type": "object",
        "description": "The 33 Style Lab dials, each 0-100. Unspecified dials default to 50 (neutral) on create.",
        "properties": {
          "technical_influence": { "type": "integer", "minimum": 0, "maximum": 100 },
          "emotional_directness": { "type": "integer", "minimum": 0, "maximum": 100 },
          "sentence_complexity": { "type": "integer", "minimum": 0, "maximum": 100 },
          "metaphor_density": { "type": "integer", "minimum": 0, "maximum": 100 },
          "cynicism_hope": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0 = cynical, 100 = hopeful." },
          "pacing": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0 = slow/deliberate, 100 = fast/propulsive." },
          "action_heavy_opening": { "type": "integer", "minimum": 0, "maximum": 100 },
          "paragraph_length": { "type": "integer", "minimum": 0, "maximum": 100 },
          "dialogue_ratio": { "type": "integer", "minimum": 0, "maximum": 100 },
          "time_linearity": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0 = fragmented/nonlinear, 100 = strictly linear." },
          "visual_emphasis": { "type": "integer", "minimum": 0, "maximum": 100 },
          "physical_detail_level": { "type": "integer", "minimum": 0, "maximum": 100 },
          "setting_detail": { "type": "integer", "minimum": 0, "maximum": 100 },
          "interiority_access": { "type": "integer", "minimum": 0, "maximum": 100 },
          "narrator_presence": { "type": "integer", "minimum": 0, "maximum": 100 },
          "humor_level": { "type": "integer", "minimum": 0, "maximum": 100 },
          "profanity_level": { "type": "integer", "minimum": 0, "maximum": 100 },
          "vocabulary_register": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0 = plain/colloquial, 100 = elevated/literary." },
          "tactile_emphasis": { "type": "integer", "minimum": 0, "maximum": 100 },
          "auditory_emphasis": { "type": "integer", "minimum": 0, "maximum": 100 },
          "olfactory_emphasis": { "type": "integer", "minimum": 0, "maximum": 100 },
          "body_awareness": { "type": "integer", "minimum": 0, "maximum": 100 },
          "temperature_texture": { "type": "integer", "minimum": 0, "maximum": 100 },
          "fragmentation": { "type": "integer", "minimum": 0, "maximum": 100 },
          "repetition_effect": { "type": "integer", "minimum": 0, "maximum": 100 },
          "time_dilation": { "type": "integer", "minimum": 0, "maximum": 100 },
          "technical_accuracy": { "type": "integer", "minimum": 0, "maximum": 100 },
          "systemic_focus": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0 = individual-focused, 100 = systems/institution-focused." },
          "ambiguity": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0 = resolved/clear, 100 = deliberately ambiguous." },
          "power_dynamics_visibility": { "type": "integer", "minimum": 0, "maximum": 100 },
          "numeric_density": { "type": "integer", "minimum": 0, "maximum": 100 },
          "acronym_tolerance": { "type": "integer", "minimum": 0, "maximum": 100 },
          "mechanism_surface": { "type": "integer", "minimum": 0, "maximum": 100 }
        }
      },
      "Voiceprint": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "description": { "type": ["string", "null"] },
          "is_default": { "type": "boolean" },
          "voice_fingerprint": { "type": ["string", "null"], "description": "Freeform notes distilling this voice's signature quirks." },
          "exemplar_prose": { "type": ["string", "null"], "description": "A pasted passage exemplifying this voice." },
          "dials": { "$ref": "#/components/schemas/VoiceDials" },
          "created_at": { "type": ["string", "null"], "format": "date-time" },
          "updated_at": { "type": ["string", "null"], "format": "date-time" }
        }
      },
      "VoiceprintCreate": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": { "type": "string" },
          "description": { "type": "string" },
          "is_default": { "type": "boolean", "description": "Make this the writer's default Voiceprint. Unsets any other default." },
          "voice_fingerprint": { "type": "string" },
          "exemplar_prose": { "type": "string" },
          "dials": { "$ref": "#/components/schemas/VoiceDials" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": ["unauthorized", "forbidden", "invalid_request", "not_found", "rate_limited", "internal_error"]
              },
              "message": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing, malformed, invalid, revoked, or expired token.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Forbidden": {
        "description": "The token lacks the scope this endpoint requires.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "InvalidRequest": {
        "description": "The request body or parameters are invalid.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "NotFound": {
        "description": "The resource does not exist or you do not own it.",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "RateLimited": {
        "description": "Too many requests. Retry after the delay in the `Retry-After` header.",
        "headers": {
          "Retry-After": { "schema": { "type": "integer" }, "description": "Seconds to wait before retrying." }
        },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    }
  }
}
