{
  "openapi": "3.1.0",
  "info": {
    "title": "scratchthepad API",
    "description": "A shared markdown pad with AI interoperability. Other AIs (Grok, Perplexity) read via /raw/ URL. AI Agents (Claude Code, Claude Cowork, Codex, Manus) read and write via API. No accounts, no setup. One pad, every AI.",
    "version": "1.0.0",
    "contact": {
      "name": "scratchthepad",
      "url": "https://scratchthepad.com"
    }
  },
  "servers": [
    {
      "url": "https://scratchthepad.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/new": {
      "post": {
        "operationId": "createPad",
        "summary": "Create a new pad",
        "description": "Creates a new shared pad and returns its URL, API endpoint, and write key. No authentication required. The write key is returned only once — save it. Give the url to the human. Use the api endpoint and write_key for subsequent reads and writes.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "content": {
                    "type": "string",
                    "description": "Optional initial markdown content for the pad"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Pad created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string", "description": "10-character pad ID" },
                    "url": { "type": "string", "description": "Browser URL for humans" },
                    "api": { "type": "string", "description": "API endpoint for agents" },
                    "write_key": { "type": "string", "description": "Write key — shown once, save it. Send as X-Pad-Key header for writes." }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/{id}": {
      "get": {
        "operationId": "readPad",
        "summary": "Read a pad",
        "description": "Returns the raw markdown content of the pad's default page. No authentication required.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "The 10-character pad ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Pad content",
            "content": {
              "text/plain": {
                "schema": { "type": "string" }
              }
            }
          },
          "404": { "description": "Pad not found" },
          "410": { "description": "Pad has been deleted" }
        }
      },
      "post": {
        "operationId": "writePad",
        "summary": "Write to a pad",
        "description": "Overwrites the default page content with the provided markdown. Requires the write key in the X-Pad-Key header. Use ?mode=append to append instead of overwrite.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "mode",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "enum": ["append"] },
            "description": "Set to 'append' to add to existing content instead of replacing"
          },
          {
            "name": "X-Pad-Key",
            "in": "header",
            "required": true,
            "schema": { "type": "string" },
            "description": "The write key returned at pad creation"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "text/plain": {
              "schema": { "type": "string" }
            }
          }
        },
        "responses": {
          "200": { "description": "Saved" },
          "401": { "description": "Write key missing or invalid" },
          "404": { "description": "Pad not found" }
        }
      }
    },
    "/api/{id}/pages": {
      "get": {
        "operationId": "listPages",
        "summary": "List pages in a pad",
        "description": "Returns an array of page names in this pad. Every pad has at least a 'default' page.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Page list",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "type": "string" } }
              }
            }
          }
        }
      }
    },
    "/api/{id}/pages/{pageName}": {
      "get": {
        "operationId": "readPage",
        "summary": "Read a named page",
        "description": "Returns the raw markdown content of a specific page within the pad.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "pageName", "in": "path", "required": true, "schema": { "type": "string" }, "description": "URL-encoded page name" }
        ],
        "responses": {
          "200": { "description": "Page content", "content": { "text/plain": { "schema": { "type": "string" } } } },
          "404": { "description": "Page not found" }
        }
      },
      "post": {
        "operationId": "writePage",
        "summary": "Write to a named page",
        "description": "Write markdown content to a named page. Creates the page if it doesn't exist. Agent writes append by default. Send plain text, not JSON.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "pageName", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "X-Pad-Key", "in": "header", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": { "text/plain": { "schema": { "type": "string" } } }
        },
        "responses": {
          "200": { "description": "Saved" },
          "401": { "description": "Write key missing or invalid" }
        }
      }
    },
    "/api/{id}/meta": {
      "get": {
        "operationId": "getPadMeta",
        "summary": "Get pad metadata",
        "description": "Returns metadata about the pad including creation date, word count, and last contributor type.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Pad metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "created": { "type": "string", "format": "date-time" },
                    "modified": { "type": "string", "format": "date-time" },
                    "pages": { "type": "integer" },
                    "words": { "type": "integer" },
                    "last_by": { "type": "string", "enum": ["human", "agent"] }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
