{
  "openapi": "3.1.0",
  "info": {
    "title": "Raziel PQC Services API",
    "version": "1.13.1",
    "description": "Raziel PQC Services API. 1.13.1: signed reports need two keys: a private signing key that only pqprobe reads, and a public-only verify key that the service reads. If either is missing, or the verify key is not public-only, a report is 503 signed reports unavailable and nothing is charged. 1.13.0: kind=report is signed. A finished report adds report_jws (compact ML-DSA-65 JWS from pqprobe, verified by the service before it is stored) and signing_kid; verify offline with pqverify. Without a configured signing key a report is 503 signed reports unavailable and nothing is charged. 1.12.0: POST /v1/scanner/scans charges and queues the scan and answers 202 with scan_id and Location; GET /v1/scanner/scans/{id} answers 202 while the probe is queued or running, then the stored result (200, 502, or 500 while a refund is pending). A retry of a running key is a 202 replay instead of 409. 503 scanner busy now means the worker queue is full. 1.11.6: document GET /v1/credits/ledger (session auth, limit 1-100, newest first); POST /v1/scanner/scans adds 503 scanner busy/unavailable (no charge). 1.11.5: PQProbe scan routes POST /v1/scanner/scans and GET /v1/scanner/scans/{id}. Session auth required. kind=grade costs 0 credits; kind=report costs 1,200 credits ($12) and is idempotent per idempotency_key; monitoring (400 credits / $4 per host-month) is not this route. The route answers 404 scanner disabled unless RAZIEL_SCANNER_HTTP=1. Unauthenticated calls are 401 even when the flag is off. A scanner failure refunds a report charge. 1.11.4: document code-only routes (auth verify/reset/revert, usage, health aliases, DELETE /v1/subscriptions); define BearerAuth/sessionAuth; declare session security on change-email; add missing 401/403 and small-body 413; clarify WebAuthn sidecar routing; unsupported methods on known routes return 405 with Allow."
  },
  "servers": [
    {
      "url": "https://raziel-pqc.cc",
      "description": "production"
    }
  ],
  "paths": {
    "/v1/health": {
      "get": {
        "summary": "Health check",
        "tags": [
          "system"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    },
    "/v1/algorithms": {
      "get": {
        "summary": "List algorithms",
        "tags": [
          "system"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AlgorithmList"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/free": {
      "post": {
        "summary": "Get free API key",
        "tags": [
          "keys"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FreeKey"
                }
              }
            }
          },
          "405": {
            "description": "Method Not Allowed \u2014 POST-only. The Allow response header lists POST."
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "RATE-LIMITED: 10 req/min/IP (429 + Retry-After). POST-only since 2026-10-07 (Weekly #39 M-window item 6): a mint is a state-changing side effect and must not ride GET \u2014 GET now returns 405 with Allow: POST."
      }
    },
    "/v1/kem/keypair": {
      "post": {
        "summary": "Generate KEM keypair",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-KEM-768",
                      "ML-KEM-1024"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Keypair"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/kem/encapsulate": {
      "post": {
        "summary": "Encapsulate",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm",
                  "public_key"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-KEM-768",
                      "ML-KEM-1024"
                    ]
                  },
                  "public_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Encap"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/kem/decapsulate": {
      "post": {
        "summary": "Decapsulate",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm",
                  "ciphertext",
                  "secret_key"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-KEM-768",
                      "ML-KEM-1024"
                    ]
                  },
                  "ciphertext": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 1000
                  },
                  "secret_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 1000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decap"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/kem/session": {
      "post": {
        "summary": "Create wrapped session envelope",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm",
                  "recipient_public_key"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-KEM-768",
                      "ML-KEM-1024"
                    ]
                  },
                  "recipient_public_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionEnvelope"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sig/keypair": {
      "post": {
        "summary": "Generate SIG keypair",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-DSA-65",
                      "SLH_DSA_PURE_SHA2_128S"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Keypair"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sig/sign": {
      "post": {
        "summary": "Sign message",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm",
                  "message",
                  "secret_key"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-DSA-65",
                      "SLH_DSA_PURE_SHA2_128S"
                    ]
                  },
                  "message": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 0
                  },
                  "secret_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Signature"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sig/verify": {
      "post": {
        "summary": "Verify signature",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "algorithm",
                  "message",
                  "signature",
                  "public_key"
                ],
                "properties": {
                  "algorithm": {
                    "enum": [
                      "ML-DSA-65",
                      "SLH_DSA_PURE_SHA2_128S"
                    ]
                  },
                  "message": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 0
                  },
                  "signature": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  },
                  "public_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Verify"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/encrypt": {
      "post": {
        "summary": "Encrypt file (JSON)",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "plaintext_b64",
                  "recipient_public_key",
                  "algorithm"
                ],
                "properties": {
                  "plaintext_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 0
                  },
                  "recipient_public_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  },
                  "algorithm": {
                    "enum": [
                      "ML-KEM-768",
                      "ML-KEM-1024"
                    ]
                  },
                  "filename": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EncryptResp"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large (max 700 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/decrypt": {
      "post": {
        "summary": "Decrypt .raziel (JSON)",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "raziel_b64",
                  "secret_key"
                ],
                "properties": {
                  "raziel_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 10
                  },
                  "secret_key": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EncryptResp"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large (max 700 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/encrypt/session": {
      "post": {
        "summary": "Encrypt with session key",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Either (session_envelope_b64 + secret_key_b64) or session_key_b64 alone. Envelope flow is primary.",
                "required": [
                  "session_envelope_b64",
                  "secret_key_b64"
                ],
                "properties": {
                  "session_envelope_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 1000
                  },
                  "secret_key_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  },
                  "session_key_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 32
                  },
                  "plaintext_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 0
                  },
                  "filename": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EncryptResp"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large (max 700 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/decrypt/session": {
      "post": {
        "summary": "Decrypt with session key",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Either (session_envelope_b64 + secret_key_b64) or session_key_b64 alone. Envelope flow is primary.",
                "required": [
                  "session_envelope_b64",
                  "secret_key_b64"
                ],
                "properties": {
                  "session_envelope_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 1000
                  },
                  "secret_key_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 100
                  },
                  "session_key_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 32
                  },
                  "data_b64": {
                    "type": "string",
                    "pattern": "^[A-Za-z0-9+/]+=*$",
                    "minLength": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EncryptResp"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large (max 700 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/encrypt/raw": {
      "post": {
        "summary": "Encrypt raw binary (X-Algorithm, X-Public-Key headers, octet-stream body)",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "binary payload (application/octet-stream)"
          },
          "415": {
            "description": "unsupported media type \u2014 raw endpoints require Content-Type: application/octet-stream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large (max 700 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "ENCRYPT RAW: JSON body {data_b64} + headers X-Algorithm (ML-KEM-768|ML-KEM-1024), X-Public-Key (base64). Response 200 = RAW BINARY .raziel envelope (Rzl\\0 magic, application/octet-stream), not JSON. Media contract enforced 2026-09-30: Content-Type must be application/octet-stream; JSON or any other type -> 415 (Accept-Post header advertises the accepted type)."
      }
    },
    "/v1/decrypt/raw": {
      "post": {
        "summary": "Decrypt raw binary (X-Secret-Key header, octet-stream body)",
        "tags": [
          "crypto"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "binary payload (application/octet-stream)"
          },
          "415": {
            "description": "unsupported media type \u2014 raw endpoints require Content-Type: application/octet-stream",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large (max 700 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "description": "DECRYPT RAW: body is the RAW BINARY .raziel ciphertext (NOT JSON, NOT base64). Header X-Secret-Key: base64 secret key. Response 200 = raw binary plaintext (application/octet-stream); wrong key/tamper -> 422. F4 documented 2026-09-05. Media contract enforced 2026-09-30: Content-Type must be application/octet-stream; JSON or any other type -> 415 (Accept-Post header advertises the accepted type)."
      }
    },
    "/v1/auth/register": {
      "post": {
        "summary": "Register user",
        "tags": [
          "auth"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 8
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Register"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "invalid JSON or validation failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Register with email+password. Returns {token, user_id, expires_at}. Duplicate email -> 400 'email already registered or invalid' (no enumeration). RATE-LIMITED: 10 req/min/IP (429 + Retry-After) \u2014 QA F1."
      }
    },
    "/v1/auth/login": {
      "post": {
        "summary": "Login",
        "tags": [
          "auth"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "password"
                ],
                "properties": {
                  "email": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Login"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "400": {
            "description": "invalid JSON or validation failure",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Login. 5 failed attempts / 15 min -> lockout. RATE-LIMITED: 10 req/min/IP (429 + Retry-After) \u2014 QA F1."
      }
    },
    "/v1/auth/logout": {
      "post": {
        "summary": "Logout",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": null,
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "session not found (no matching row)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/profile": {
      "post": {
        "summary": "Update profile",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "display_name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/change-password": {
      "post": {
        "summary": "Change password",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "old_password": {
                    "type": "string"
                  },
                  "new_password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/delete-account": {
      "post": {
        "summary": "Delete account",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "password"
                ],
                "properties": {
                  "password": {
                    "type": "string",
                    "minLength": 8
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/sessions/revoke": {
      "post": {
        "summary": "Revoke session",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "session not found (no matching row)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/me": {
      "get": {
        "summary": "Current user",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/sessions": {
      "get": {
        "summary": "List sessions",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Sessions"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "summary": "Create API key",
        "tags": [
          "keys"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tier": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List API keys",
        "tags": [
          "keys"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "keys",
                    "count"
                  ],
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/revoke": {
      "post": {
        "summary": "Revoke API key",
        "tags": [
          "keys"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key_id"
                ],
                "properties": {
                  "key_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/rotate": {
      "post": {
        "summary": "Rotate API key",
        "tags": [
          "keys"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key_id"
                ],
                "properties": {
                  "key_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/history": {
      "get": {
        "summary": "Operation history",
        "tags": [
          "dashboard"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/History"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/analytics": {
      "get": {
        "summary": "Monthly analytics",
        "tags": [
          "dashboard"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Analytics"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/payments/invoices": {
      "get": {
        "summary": "List invoices",
        "tags": [
          "payments"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KeysList"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/payments/status": {
      "get": {
        "summary": "Payment status",
        "tags": [
          "payments"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentStatus"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/credits/ledger": {
      "get": {
        "summary": "Credit ledger",
        "description": "Newest-first credit ledger rows for the session user. Each row carries the signed delta and the balance after it.",
        "tags": [
          "payments"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Rows to return, 1-100. Values over 100 are capped; anything else falls back to 100.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ledger rows, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["entries"],
                  "properties": {
                    "entries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": ["id", "delta", "reason", "ref", "balance_after", "created_at"],
                        "properties": {
                          "id": {"type": "integer"},
                          "delta": {"type": "integer", "description": "Signed credit change."},
                          "reason": {"type": "string", "enum": ["topup", "launch_bonus", "file_op", "file_refund", "scanner_report", "scanner_refund", "scanner_monitor", "guardian_month", "admin_adjust", "opening_balance"]},
                          "ref": {"type": "string", "description": "Idempotency reference (invoice id, scan idempotency_key, YYYY-MM)."},
                          "balance_after": {"type": "integer"},
                          "created_at": {"type": "string", "description": "UTC, SQLite datetime format."}
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "405": {
            "description": "Method not allowed. Allow lists GET.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "500": {
            "description": "Ledger could not be loaded.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          }
        }
      }
    },
    "/v1/payments/balance": {
      "get": {
        "summary": "Payment balance",
        "tags": [
          "payments"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaymentBalance"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/payments/invoice": {
      "post": {
        "summary": "Create invoice",
        "tags": [
          "payments"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "currency": {
                    "type": "string",
                    "enum": [
                      "BTC",
                      "ETH",
                      "XRP"
                    ],
                    "description": "Invoice currency (required)."
                  },
                  "tier": {
                    "type": "string",
                    "enum": [
                      "free",
                      "payg",
                      "pro",
                      "enterprise"
                    ],
                    "description": "Target tier (required). pro min $12, enterprise min $250; per-tier max_topup_usd cap."
                  },
                  "interval": {
                    "type": "string",
                    "enum": [
                      "monthly",
                      "quarterly",
                      "semiannual",
                      "annual"
                    ],
                    "description": "Billing interval for subscription invoices."
                  },
                  "amount": {
                    "type": "number",
                    "description": "USD amount (optional, default 10). Validated against tier min/max server-side; invoice amounts are validated server-side against the tier price."
                  }
                },
                "required": [
                  "currency",
                  "tier"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/admin/keys": {
      "post": {
        "summary": "Admin: create/upgrade key",
        "tags": [
          "admin"
        ],
        "security": [
          {
            "masterKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "api_key": {
                    "type": "string"
                  },
                  "tier": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/admin/payments/confirm": {
      "post": {
        "summary": "Admin: confirm payment",
        "tags": [
          "admin"
        ],
        "security": [
          {
            "masterKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "invoice_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/vault/store": {
      "post": {
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ],
        "summary": "Store file in Twin-Key Vault (v3 envelope)",
        "operationId": "vaultStore",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recipient_public_key": {
                    "type": "string",
                    "description": "ML-KEM-768 (1184B) or ML-KEM-1024 (1568B) public key, base64"
                  },
                  "plaintext_b64": {
                    "type": "string"
                  },
                  "filename": {
                    "type": "string"
                  }
                },
                "required": [
                  "recipient_public_key",
                  "plaintext_b64"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "stored",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "file_id": {
                      "type": "string"
                    },
                    "filename": {
                      "type": "string"
                    },
                    "size_bytes": {
                      "type": "integer"
                    },
                    "data_b64": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "string",
                      "nullable": true,
                      "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "bad request"
          },
          "401": {
            "description": "auth required"
          },
          "409": {
            "description": "duplicate content"
          },
          "500": {
            "description": "error"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/vault/list": {
      "get": {
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ],
        "summary": "List user's vault entries (size-quantized)",
        "operationId": "vaultList",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "files": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "file_id": {
                            "type": "string"
                          },
                          "filename": {
                            "type": "string"
                          },
                          "size_bytes": {
                            "type": "integer"
                          },
                          "quantized_size": {
                            "type": "integer"
                          },
                          "created_at": {
                            "type": "string"
                          },
                          "alg": {
                            "type": "string"
                          },
                          "ver": {
                            "type": "integer"
                          },
                          "has_owner_meta": {
                            "type": "boolean"
                          },
                          "expires_at": {
                            "type": "string",
                            "nullable": true,
                            "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "limit": {
                      "type": "integer"
                    },
                    "offset": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "auth required"
          },
          "500": {
            "description": "error"
          }
        }
      }
    },
    "/v1/vault/get": {
      "post": {
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ],
        "summary": "Fetch stored envelope by file_id",
        "operationId": "vaultGet",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file_id": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{16}$"
                  },
                  "expires_at": {
                    "type": "string",
                    "nullable": true,
                    "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                  }
                },
                "required": [
                  "file_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "envelope",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "file_id": {
                      "type": "string"
                    },
                    "data_b64": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "string",
                      "nullable": true,
                      "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid file_id"
          },
          "401": {
            "description": "auth required"
          },
          "404": {
            "description": "not found"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/vault/delete": {
      "post": {
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ],
        "summary": "Delete a vault entry (owner-scoped, atomic, audited)",
        "operationId": "vaultDelete",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "file_id": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{16}$"
                  },
                  "expires_at": {
                    "type": "string",
                    "nullable": true,
                    "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                  }
                },
                "required": [
                  "file_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid file_id"
          },
          "401": {
            "description": "auth required"
          },
          "404": {
            "description": "not found"
          },
          "500": {
            "description": "error"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/openapi.json": {
      "get": {
        "summary": "This OpenAPI document",
        "description": "Live spec of this service. QA F2 (2026-09-05).",
        "responses": {
          "200": {
            "description": "OpenAPI 3 JSON"
          },
          "500": {
            "description": "spec unavailable"
          }
        }
      }
    },
    "/v1/auth/change-email": {
      "post": {
        "summary": "Request email change (session)",
        "description": "Swaps account email to new_email, un-verifies it, and mails a confirmation link (24h) to the new address. Security notice sent to the old address. Login email becomes the new one only after confirmation via /v1/auth/verify.",
        "operationId": "authChangeEmail",
        "tags": [
          "auth"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "new_email"
                ],
                "properties": {
                  "new_email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification mail sent to new address"
          },
          "400": {
            "description": "invalid JSON / missing new_email / invalid email format"
          },
          "401": {
            "description": "authentication required"
          },
          "409": {
            "description": "email not available (taken by another account)"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/v1/subscriptions": {
      "post": {
        "summary": "Create a subscription (issues the activation invoice)",
        "description": "One active subscription per user. Tier pro|enterprise; interval monthly|quarterly|semiannual|annual. Amount computed server-side from the tier/interval price table \u2014 the client NEVER sends an amount. Returns the activation invoice (paid via the standard invoice pipeline).",
        "responses": {
          "201": {
            "description": "Subscription created, activation invoice issued (invoice object with payment_uri)"
          },
          "400": {
            "description": "invalid JSON / missing tier or coin",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "email not verified",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "subscription already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "invalid tier/interval/coin, invoice cap reached, or wallet unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ]
      },
      "get": {
        "summary": "Get the current subscription status card",
        "responses": {
          "200": {
            "description": "Subscription status (or subscribed:false when none)"
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "subscription query failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ]
      },
      "delete": {
        "summary": "Cancel the subscription at period end (DELETE alias)",
        "description": "Same behaviour as POST /v1/subscriptions/cancel. Dashboard Cancel uses DELETE. Requires session; mutating subscription routes also require a verified email (403).",
        "responses": {
          "200": {
            "description": "canceled"
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "no active subscription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "cancel failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "email not verified",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "operationId": "subscriptionsCancelDelete",
        "tags": [
          "payments"
        ],
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/v1/subscriptions/cancel": {
      "post": {
        "summary": "Cancel the subscription at period end",
        "description": "status=canceled; access continues until the paid period ends (no further renewal invoices).",
        "responses": {
          "200": {
            "description": "canceled"
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "no active subscription",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "cancel failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "email not verified",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/v1/share": {
      "post": {
        "summary": "Create a share link for a vault file",
        "tags": [
          "share"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "file_id"
                ],
                "properties": {
                  "file_id": {
                    "type": "string",
                    "minLength": 16,
                    "maxLength": 16
                  },
                  "expires_hours": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 720,
                    "default": 168
                  },
                  "max_views": {
                    "type": "integer",
                    "enum": [
                      0,
                      1
                    ],
                    "default": 0,
                    "description": "1 = view-once"
                  },
                  "password": {
                    "type": "string",
                    "description": "optional share password (bcrypt-hashed server-side)"
                  },
                  "expires_at": {
                    "type": "string",
                    "nullable": true,
                    "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created - token shown ONCE",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "share_id": {
                      "type": "integer"
                    },
                    "token": {
                      "type": "string"
                    },
                    "share_url": {
                      "type": "string"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "no session"
          },
          "404": {
            "description": "file not in your vault"
          },
          "500": {
            "description": "creation failed"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List your share links",
        "tags": [
          "share"
        ],
        "responses": {
          "200": {
            "description": "share list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "shares": {
                      "type": "array"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "no session"
          }
        }
      },
      "delete": {
        "summary": "Revoke a share immediately",
        "tags": [
          "share"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "share_id"
                ],
                "properties": {
                  "share_id": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "revoked"
          },
          "401": {
            "description": "no session"
          },
          "404": {
            "description": "share not found"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/s/{token}": {
      "get": {
        "summary": "Public share redemption - returns the ENCRYPTED .raziel envelope (decryption key travels out-of-band from sender)",
        "tags": [
          "share"
        ],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 20,
              "maxLength": 128
            }
          },
          {
            "name": "password",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "required when the share has a password"
          }
        ],
        "responses": {
          "200": {
            "description": "envelope delivered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data_b64": {
                      "type": "string"
                    },
                    "file_id": {
                      "type": "string"
                    },
                    "note": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "string",
                      "nullable": true,
                      "description": "vault-cache purge time (TTL 6h/12h free/payg, 24h/48h pro/ent)"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "wrong password (only when share is password-protected)"
          },
          "404": {
            "description": "unknown / expired / consumed / revoked - generic, no state disclosure"
          },
          "429": {
            "description": "rate limited (nginx raziel_shareri + backend unauth_rate_gate)"
          }
        }
      }
    },
    "/v1/auth/login/passkey": {
      "post": {
        "summary": "Passkey login \u2014 C service verifies via sidecar then mints session",
        "tags": [
          "auth"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id",
                  "challenge",
                  "response"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "session token"
          },
          "401": {
            "description": "verification failed (generic anti-enumeration)"
          },
          "429": {
            "description": "rate limited"
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/{id}": {
      "delete": {
        "tags": [
          "keys"
        ],
        "security": [
          {
            "sessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-fA-F]{32}$"
            }
          }
        ],
        "summary": "Revoke an API key by id (W37 M-7): Bearer key may revoke itself; owner-scoped revoke of linked keys. Response {\"status\":\"revoked\"}. 400 malformed id, 401 bad auth, 403 not owned."
      }
    },
    "/v1/scanner/scans": {
      "post": {
        "summary": "Queue a PQProbe scan (poll for Report v1)",
        "description": "Authenticated scan of one public host on port 443. kind=grade costs 0 credits. kind=report costs 1,200 credits ($12) via credits_charge_scanner and is idempotent for the same idempotency_key (a retry does not debit again). A probe failure refunds the report charge. Private, loopback, link-local, and metadata targets are refused and are not charged. The server never passes -allow-local-test. Validation, rate limit and the charge happen before the 202; the probe runs on a scanner worker and the result is fetched with GET /v1/scanner/scans/{id}. Disabled (404) unless RAZIEL_SCANNER_HTTP=1. Monitoring at 400 credits ($4) per host per month is not this operation. A finished kind=report carries report_jws, a compact ML-DSA-65 JWS over the canonical Report v1 bytes, plus signing_kid.",
        "tags": ["scanner"],
        "security": [
          {"sessionToken": []},
          {"BearerAuth": []}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/ScannerScanRequest"}
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted: the scan is queued or running. Also returned, with idempotent_replay true and credits_charged 0, for a retry while that key is still running. Location points at the poll URL; Retry-After is 2.",
            "headers": {
              "Location": {"schema": {"type": "string"}, "description": "/v1/scanner/scans/{scan_id}"},
              "Retry-After": {"schema": {"type": "integer"}}
            },
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ScannerScanAccepted"}
              }
            }
          },
          "200": {
            "description": "Idempotent replay of a finished scan: the stored Report v1 with idempotent_replay true and credits_charged 0.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ScannerScanResponse"}
              }
            }
          },
          "400": {
            "description": "Invalid JSON, target, kind, or idempotency key. Private targets are not charged.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "401": {
            "description": "Authentication required (also when the feature flag is off).",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "402": {
            "description": "Insufficient credits for kind=report (1,200). No partial debit.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "404": {
            "description": "Scanner disabled (RAZIEL_SCANNER_HTTP is not 1).",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "409": {
            "description": "Idempotency key reused with a different target or kind.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "413": {
            "description": "Payload too large for this endpoint (max 1 MB).",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "429": {
            "description": "Per-user scan rate limit. Retry-After is set.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "502": {
            "description": "Replay of a failed scan (the report charge was refunded), or scan interrupted: the row was settled before the charge, and nothing was charged.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "500": {
            "description": "Replay of a failed scan whose refund is still pending; this retry attempted the refund again.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "503": {
            "description": "Worker queue full (scanner busy), scanner workers not running (scanner unavailable), or kind=report without a usable signing key and public verify key (signed reports unavailable). Nothing is charged and the idempotency key stays usable. Retry-After is set.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "405": {
            "description": "Method not allowed. Allow lists POST.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          }
        }
      }
    },
    "/v1/scanner/scans/{id}": {
      "get": {
        "summary": "Poll a PQProbe scan",
        "description": "202 while the probe is queued or running (Retry-After 2). Then the stored result for the authenticated user: 200 with Report v1, 502 if the probe failed or was interrupted (a report charge is refunded), or 500 while a refund is still pending (a POST retry with the same idempotency_key attempts it again). 404 when the flag is off or the id is unknown.",
        "tags": ["scanner"],
        "security": [
          {"sessionToken": []},
          {"BearerAuth": []}
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {"type": "string", "pattern": "^[A-Za-z0-9-]{8,80}$"}
          }
        ],
        "responses": {
          "200": {
            "description": "Stored Report v1 response.",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ScannerScanResponse"}
              }
            }
          },
          "202": {
            "description": "Queued or running. Poll again after Retry-After.",
            "headers": {"Retry-After": {"schema": {"type": "integer"}}},
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/ScannerScanRunning"}
              }
            }
          },
          "500": {
            "description": "Probe failed and the refund is still pending.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "502": {
            "description": "Probe failed or was interrupted. A report charge is refunded.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "401": {
            "description": "Authentication required.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "404": {
            "description": "Scanner disabled, or no scan with this id for the caller.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          },
          "405": {
            "description": "Method not allowed. Allow lists GET.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}
          }
        }
      }
    },
    "/api/v1/webauthn/register/challenge": {
      "post": {
        "summary": "WebAuthn registration challenge (sidecar)",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionAuth": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "PKCC options + challenge"
          },
          "400": {
            "description": "bad request"
          },
          "404": {
            "description": "not served by the main API binary (sidecar only)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "WebAuthn registration challenge (sidecar) Served by the WebAuthn sidecar at these paths. The main API binary does not implement them and responds 404; reverse-proxy routing must send /api/v1/webauthn/* to the sidecar."
      }
    },
    "/api/v1/webauthn/register/verify": {
      "post": {
        "summary": "WebAuthn registration verify (sidecar)",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionAuth": []
          },
          {
            "sessionToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id",
                  "challenge",
                  "response"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "credential stored"
          },
          "400": {
            "description": "challenge invalid/expired/used or verification failed"
          },
          "404": {
            "description": "not served by the main API binary (sidecar only)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "WebAuthn registration verify (sidecar) Served by the WebAuthn sidecar at these paths. The main API binary does not implement them and responds 404; reverse-proxy routing must send /api/v1/webauthn/* to the sidecar."
      }
    },
    "/api/v1/webauthn/login/challenge": {
      "post": {
        "summary": "WebAuthn login challenge (sidecar; user_id or discoverable)",
        "tags": [
          "auth"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "user_id": {
                    "type": "string"
                  },
                  "discoverable": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "assertion options"
          },
          "400": {
            "description": "no credentials / bad request"
          },
          "404": {
            "description": "not served by the main API binary (sidecar only)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "WebAuthn login challenge (sidecar; user_id or discoverable) Served by the WebAuthn sidecar at these paths. The main API binary does not implement them and responds 404; reverse-proxy routing must send /api/v1/webauthn/* to the sidecar."
      }
    },
    "/health": {
      "get": {
        "summary": "Health check (alias of /v1/health)",
        "tags": [
          "system"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        },
        "description": "Public alias of GET /v1/health \u2014 same JSON payload."
      }
    },
    "/v1/status": {
      "get": {
        "summary": "Status check (alias of /v1/health)",
        "tags": [
          "system"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        },
        "description": "Public alias of GET /v1/health \u2014 same JSON payload.",
        "operationId": "getStatus"
      }
    },
    "/v1/usage": {
      "get": {
        "summary": "API key usage / quota",
        "description": "Returns tier, files_limit, files_remaining, files_used, credits, and period for the calling API key.",
        "operationId": "getUsage",
        "tags": [
          "keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "usage snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tier": {
                      "type": "string"
                    },
                    "files_limit": {
                      "type": "integer"
                    },
                    "files_remaining": {
                      "type": "integer"
                    },
                    "files_used": {
                      "type": "integer"
                    },
                    "credits": {
                      "type": "integer"
                    },
                    "period": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/verify": {
      "post": {
        "summary": "Confirm email verification or pending email change",
        "description": "Public token endpoint. Body token verifies signup email or completes a pending email change. Invalid/expired token -> 400; contested address -> 409.",
        "operationId": "authVerify",
        "tags": [
          "auth"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "verified or email change completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid JSON / missing token / invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "requested email address is no longer available",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/resend-verification": {
      "post": {
        "summary": "Resend verification email",
        "description": "Session-required. Re-queues a verification email for the signed-in user. Already-verified accounts still receive 200 with an already-verified message. Body is ignored.",
        "operationId": "authResendVerification",
        "tags": [
          "auth"
        ],
        "security": [
          {
            "sessionToken": []
          },
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "verification email sent or already verified",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "could not create verification email",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/reset-request": {
      "post": {
        "summary": "Request password reset email",
        "description": "Public. Always returns 200 with a generic message (anti-enumeration). A reset link is mailed only when a matching active account exists.",
        "operationId": "authResetRequest",
        "tags": [
          "auth"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "generic acceptance (does not reveal account existence)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid JSON / missing email",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/reset-confirm": {
      "post": {
        "summary": "Confirm password reset",
        "description": "Public token endpoint. Sets a new password when the reset token is valid.",
        "operationId": "authResetConfirm",
        "tags": [
          "auth"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token",
                  "password"
                ],
                "properties": {
                  "token": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 8
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "password updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid JSON / missing fields / invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/revert-email": {
      "post": {
        "summary": "Cancel a pending email change",
        "description": "Public token endpoint. Consumes a cancellation token mailed to the previous address and leaves the login email unchanged.",
        "operationId": "authRevertEmail",
        "tags": [
          "auth"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "email change cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid JSON / missing token / invalid or expired token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "payload too large for this endpoint (max 1 MB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "method not allowed \u2014 see Allow response header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key (32 hex chars) \u2014 mint via POST /v1/key/free"
      },
      "sessionToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Session-Token",
        "description": "Browser/dashboard session token (32 hex chars) via X-Session-Token. Vault and many session routes also accept Authorization: Bearer <session>."
      },
      "masterKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Master-Key",
        "description": "Admin master key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Session token as Authorization: Bearer <session>. Equivalent to X-Session-Token for vault and session routes."
      },
      "sessionAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Session-Token",
        "description": "Session token for WebAuthn sidecar routes (same value as sessionToken)."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "const": "ok"
          }
        }
      },
      "AlgorithmList": {
        "type": "object",
        "required": [
          "kem_algorithms",
          "sig_algorithms"
        ],
        "properties": {
          "kem_algorithms": {
            "type": "array",
            "items": {
              "enum": [
                "ML-KEM-768",
                "ML-KEM-1024"
              ]
            }
          },
          "sig_algorithms": {
            "type": "array",
            "items": {
              "enum": [
                "ML-DSA-65",
                "SLH_DSA_PURE_SHA2_128S"
              ]
            }
          }
        }
      },
      "FreeKey": {
        "type": "object",
        "required": [
          "api_key",
          "tier",
          "remaining_files",
          "max_file_size_mb"
        ],
        "properties": {
          "api_key": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "tier": {
            "type": "string"
          },
          "remaining_files": {
            "type": "integer"
          },
          "max_file_size_mb": {
            "type": "integer"
          }
        }
      },
      "Keypair": {
        "type": "object",
        "required": [
          "algorithm",
          "type",
          "public_key",
          "secret_key"
        ],
        "properties": {
          "algorithm": {
            "type": "string"
          },
          "type": {
            "enum": [
              "kem",
              "sig"
            ]
          },
          "public_key": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 100
          },
          "secret_key": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 100
          }
        }
      },
      "Encap": {
        "type": "object",
        "required": [
          "ciphertext",
          "shared_secret"
        ],
        "properties": {
          "ciphertext": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 1000
          },
          "shared_secret": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 32
          }
        }
      },
      "Decap": {
        "type": "object",
        "required": [
          "shared_secret"
        ],
        "properties": {
          "shared_secret": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 32
          }
        }
      },
      "SessionEnvelope": {
        "type": "object",
        "required": [
          "session_envelope_b64"
        ],
        "properties": {
          "session_envelope_b64": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 1000
          }
        }
      },
      "Signature": {
        "type": "object",
        "required": [
          "signature"
        ],
        "properties": {
          "signature": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 100
          }
        }
      },
      "Verify": {
        "type": "object",
        "required": [
          "valid"
        ],
        "properties": {
          "valid": {
            "type": "boolean"
          }
        }
      },
      "EncryptResp": {
        "type": "object",
        "required": [
          "filename",
          "data_b64"
        ],
        "properties": {
          "filename": {
            "type": "string"
          },
          "data_b64": {
            "type": "string",
            "pattern": "^[A-Za-z0-9+/]+=*$",
            "minLength": 10
          }
        }
      },
      "Register": {
        "type": "object",
        "required": [
          "token",
          "user_id",
          "expires_at"
        ],
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "user_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "expires_at": {
            "type": "string"
          }
        }
      },
      "Login": {
        "type": "object",
        "required": [
          "token",
          "user_id",
          "expires_at"
        ],
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "user_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          },
          "expires_at": {
            "type": "string"
          }
        }
      },
      "Me": {
        "type": "object",
        "required": [
          "user_id",
          "email",
          "display_name",
          "created_at",
          "active",
          "keys_count",
          "total_files_encrypted",
          "remaining_files"
        ],
        "properties": {
          "user_id": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          },
          "created_at": {
            "type": "string"
          },
          "active": {
            "type": "integer"
          },
          "keys_count": {
            "type": "integer"
          },
          "total_files_encrypted": {
            "type": "integer"
          },
          "remaining_files": {
            "type": "integer"
          }
        }
      },
      "Sessions": {
        "type": "object",
        "required": [
          "sessions",
          "count"
        ],
        "properties": {
          "sessions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "token",
                "token_display",
                "created_at",
                "expires_at"
              ],
              "properties": {
                "token": {
                  "type": "string"
                },
                "token_display": {
                  "type": "string"
                },
                "created_at": {
                  "type": "string"
                },
                "expires_at": {
                  "type": "string"
                }
              }
            }
          },
          "count": {
            "type": "integer"
          }
        }
      },
      "History": {
        "type": "object",
        "required": [
          "operations",
          "total",
          "limit",
          "offset"
        ],
        "properties": {
          "operations": {
            "type": "array"
          },
          "total": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          }
        }
      },
      "Analytics": {
        "type": "object",
        "required": [
          "monthly_usage",
          "total_operations",
          "total_bytes"
        ],
        "properties": {
          "monthly_usage": {
            "type": "array"
          },
          "total_operations": {
            "type": "integer"
          },
          "total_bytes": {
            "type": "integer"
          }
        }
      },
      "KeysList": {
        "type": "object",
        "required": [
          "keys",
          "count"
        ],
        "properties": {
          "keys": {
            "type": "array"
          },
          "count": {
            "type": "integer"
          }
        }
      },
      "PaymentStatus": {
        "type": "object",
        "required": [
          "status",
          "total_paid",
          "currency",
          "invoices"
        ],
        "properties": {
          "status": {
            "type": "string"
          },
          "total_paid": {
            "type": "string"
          },
          "currency": {
            "type": "string"
          },
          "invoices": {
            "type": "object",
            "properties": {
              "pending": {
                "type": "integer"
              },
              "confirmed": {
                "type": "integer"
              },
              "expired": {
                "type": "integer"
              }
            }
          }
        }
      },
      "PaymentBalance": {
        "type": "object",
        "required": [
          "tier",
          "credits",
          "total_encrypted",
          "total_decrypted",
          "updated_at"
        ],
        "properties": {
          "tier": {
            "type": "string"
          },
          "credits": {
            "type": "integer"
          },
          "total_encrypted": {
            "type": "integer"
          },
          "total_decrypted": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string"
          }
        }
      },
      "ScannerScanRequest": {
        "type": "object",
        "required": ["target", "idempotency_key"],
        "properties": {
          "target": {
            "type": "string",
            "description": "Hostname or public IP, optional :443. Private, loopback, link-local, and metadata ranges are rejected."
          },
          "kind": {
            "type": "string",
            "enum": ["grade", "report"],
            "default": "grade",
            "description": "grade = 0 credits. report = 1,200 credits ($12)."
          },
          "idempotency_key": {
            "type": "string",
            "minLength": 8,
            "maxLength": 80,
            "description": "Caller-chosen key. A retry with the same key does not charge twice."
          }
        }
      },
      "PQProbeReport": {
        "type": "object",
        "description": "pqprobe Report v1.",
        "required": ["report_version", "generated_at", "tool", "target", "grade", "addresses"],
        "properties": {
          "report_version": {"const": "1"},
          "generated_at": {"type": "string"},
          "tool": {"const": "pqprobe"},
          "target": {"type": "string"},
          "grade": {
            "type": "string",
            "enum": [
              "pq-only",
              "hybrid-preferred",
              "hybrid-offered-not-preferred",
              "partial",
              "classical-only",
              "intolerant",
              "timeout",
              "mixed",
              "other",
              "blocked"
            ]
          },
          "addresses": {"type": "array", "items": {"type": "object"}},
          "notes": {"type": "array", "items": {"type": "string"}}
        }
      },
      "ScannerScanAccepted": {
        "type": "object",
        "required": ["scan_id", "status", "kind", "idempotent_replay", "credits_charged", "balance_after"],
        "properties": {
          "scan_id": {"type": "string"},
          "status": {"type": "string", "enum": ["running"]},
          "kind": {"type": "string", "enum": ["grade", "report"]},
          "idempotent_replay": {"type": "boolean"},
          "credits_charged": {"type": "integer", "description": "1200 for a newly accepted report, else 0."},
          "balance_after": {"type": "integer"}
        }
      },
      "ScannerScanRunning": {
        "type": "object",
        "required": ["scan_id", "status", "kind"],
        "properties": {
          "scan_id": {"type": "string"},
          "status": {"type": "string", "enum": ["running"]},
          "kind": {"type": "string", "enum": ["grade", "report"]}
        }
      },
      "ScannerScanResponse": {
        "type": "object",
        "required": ["scan_id", "idempotent_replay", "kind", "credits_charged", "balance_after", "report"],
        "properties": {
          "scan_id": {"type": "string"},
          "idempotent_replay": {"type": "boolean"},
          "kind": {"type": "string", "enum": ["grade", "report"]},
          "credits_charged": {
            "type": "integer",
            "description": "0 for grade and for any replay. 1200 for a first successful report charge."
          },
          "balance_after": {"type": "integer"},
          "report": {"$ref": "#/components/schemas/PQProbeReport"},
          "report_jws": {
            "type": "string",
            "description": "kind=report only. Compact JWS exactly as pqprobe produced it: header {alg: ML-DSA-65, kid, typ: pqprobe-report+jws}, payload the canonical Report v1 bytes. Verified by the service before storage; verify offline with pqverify -pub."
          },
          "signing_kid": {
            "type": "string",
            "description": "kind=report only. RFC 7638 thumbprint of the signing key; equals the JWS header kid."
          }
        }
      }
    }
  }
}
