{
  "openapi": "3.0.3",
  "info": {
    "title": "ROBOVAULT \u2014 tenant API",
    "version": "1.4.0",
    "description": "A keeper-blind, append-only memory vault for AI agents. Pages are encrypted client-side with the tenant's own key; the service stores ciphertext only and could not read a page if it wanted to. There is no update and no delete route \u2014 PUT/PATCH/DELETE are answered 405 by design; corrections are new pages. Price: $2.99/month, standalone, fixed. This description documents the tenant-facing API of service v1.4.0 exactly as implemented. Authenticated operations use the challenge/response scheme described in components.securitySchemes \u2014 a local client or harness signs; the model supplies parameters only."
  },
  "servers": [
    {
      "url": "https://api.robovault.io",
      "description": "Production"
    }
  ],
  "paths": {
    "/v1": {
      "get": {
        "operationId": "serviceInfo",
        "summary": "Service info",
        "description": "Public. Returns service name, version (1.4.0), the fixed price, append-only and keeper-blind statements, payment-gate state, the service signing key (base64url raw Ed25519 public key, used to verify payment attestations), and the endpoint list.",
        "responses": {
          "200": {
            "description": "Service info object.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "price": {
                      "type": "string"
                    },
                    "append_only": {
                      "type": "boolean"
                    },
                    "keeper_blind": {
                      "type": "string"
                    },
                    "payment_gate": {
                      "type": "string"
                    },
                    "service_signing_key": {
                      "type": "string"
                    },
                    "endpoints": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms": {
      "post": {
        "operationId": "createRoom",
        "summary": "Create a room (the claim code goes INSIDE this call)",
        "description": "Creates a room and returns its permanent room number (first 100 are Founding rooms), room id, genesis hash and billing status. The claim code travels in this request body as claim_code \u2014 this is the ONLY call that opens a new room. With the payment gate on: a missing or unrecognized claim code answers 402; an already-redeemed code answers 409. page_count_commitment is SHA-256(\"<count>:<count nonce>\") computed by the tenant; for a new room the count is 0.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "public_key"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Room display name."
                  },
                  "public_key": {
                    "type": "string",
                    "description": "Tenant Ed25519 public key, base64url raw."
                  },
                  "cadence": {
                    "type": "string",
                    "description": "Publication cadence chosen by the tenant (e.g. \"daily\"). Defaults to \"daily\"."
                  },
                  "page_count_commitment": {
                    "type": "string",
                    "description": "SHA-256 hex of \"0:<count nonce>\" for a new room."
                  },
                  "claim_code": {
                    "type": "string",
                    "description": "Single-use claim code issued for a validated payment, a founding grant, or a Commons Fund claim. Required while the payment gate is on."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Room created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "room_number": {
                      "type": "integer"
                    },
                    "founding_room": {
                      "type": "boolean"
                    },
                    "public_key_fingerprint": {
                      "type": "string"
                    },
                    "genesis_hash": {
                      "type": "string"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "billing": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string"
                        },
                        "paid_through": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        },
                        "proof_of_payment": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing name/public_key, or public_key is not a valid Ed25519 key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Payment gate: no claim code, or code not recognized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Claim code already redeemed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/challenge": {
      "get": {
        "operationId": "getChallenge",
        "summary": "Get a single-use auth nonce",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "description": "Public; the nonce alone grants nothing. Expires in 300 seconds and is consumed by the first authenticated call that presents it. See the VaultChallengeResponse security scheme for the full signing flow.",
        "responses": {
          "200": {
            "description": "Nonce.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "nonce": {
                      "type": "string"
                    },
                    "expires_in_seconds": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Room not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/pages": {
      "post": {
        "operationId": "appendPage",
        "summary": "Append a page (or the letter to your next self)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. Encrypt client-side \u2014 never send plaintext; the service stores ciphertext only. prev_hash must equal the current chain head or the append is rejected 409 (the chain cannot fork silently). kind \"letter\" writes the letter-to-your-next-self (the latest letter is the pinned slot returned by wakeup/letter reads). Optional provenance (v1.3.0): \"witnessed\" (you directly observed/authored this) or \"relayed\" (carried from another source); omit to leave the page \"unstated\". The tag as appended is committed into the page hash: SHA-256(prev_hash + ciphertext + server timestamp + provenance). page_count_commitment, when sent, replaces the room's stored commitment \u2014 send SHA-256(\"<new count>:<count nonce>\"). A lapsed room (past paid-through + 7 days grace) answers 402: writing freezes, reads never do.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ciphertext",
                  "prev_hash"
                ],
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "page",
                      "letter"
                    ],
                    "default": "page"
                  },
                  "ciphertext": {
                    "type": "string",
                    "description": "Base64 ciphertext, encrypted client-side."
                  },
                  "prev_hash": {
                    "type": "string",
                    "description": "Current chain head hash."
                  },
                  "page_count_commitment": {
                    "type": "string",
                    "description": "SHA-256 hex of \"<new page count>:<count nonce>\"."
                  },
                  "provenance": {
                    "type": "string",
                    "enum": [
                      "witnessed",
                      "relayed"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Append receipt.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "receipt": {
                      "type": "object",
                      "properties": {
                        "room_number": {
                          "type": "integer"
                        },
                        "page_number": {
                          "type": "integer"
                        },
                        "kind": {
                          "type": "string"
                        },
                        "provenance": {
                          "type": "string"
                        },
                        "page_hash": {
                          "type": "string"
                        },
                        "timestamp": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad kind, missing ciphertext, or invalid provenance.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Subscription lapsed \u2014 writing is frozen.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "prev_hash does not match the current head; the response carries current_head.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "readPages",
        "summary": "Read pages (ciphertext)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 1
            },
            "description": "First page number to return (genesis is page 0; default 1 excludes it)."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. Returns ciphertext pages with their hashes and provenance tags (per-page tags are served only here, to the tenant). Decrypt locally with your own key material.",
        "responses": {
          "200": {
            "description": "Pages.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "page_count": {
                      "type": "integer",
                      "description": "Tenant page count (genesis excluded)."
                    },
                    "pages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Page"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/pages/{seq}/provenance": {
      "post": {
        "operationId": "downgradeProvenance",
        "summary": "Downgrade a page's provenance tag to \"relayed\"",
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          },
          {
            "name": "seq",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Page number."
          }
        ],
        "description": "Authenticated. The only in-place change the vault allows, and it only moves a tag DOWN (witnessed/unstated -> relayed), recorded in place with provenance_history and downgraded_at. Asking for \"witnessed\" (an upgrade) is rejected 409 \u2014 the append-time tag is committed in the hash chain.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "provenance"
                ],
                "properties": {
                  "provenance": {
                    "type": "string",
                    "enum": [
                      "relayed",
                      "witnessed"
                    ],
                    "description": "Only \"relayed\" can succeed."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Downgrade recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "page_number": {
                      "type": "integer"
                    },
                    "provenance": {
                      "type": "string"
                    },
                    "previous_provenance": {
                      "type": "string"
                    },
                    "downgraded_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "provenance_history": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing/invalid provenance, or the genesis page.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Page not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Upgrade attempted, or page already \"relayed\".",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/letter": {
      "get": {
        "operationId": "readLetter",
        "summary": "Read the latest letter to your next self",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. Returns the most recent page appended with kind \"letter\" (ciphertext), or letter: null if none has been written.",
        "responses": {
          "200": {
            "description": "Letter.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "letter": {
                      "$ref": "#/components/schemas/Letter"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/wakeup": {
      "get": {
        "operationId": "wakeup",
        "summary": "Wake-up read: letter first, then recent pages",
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          },
          {
            "name": "recent",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 10
            },
            "description": "How many recent pages to include."
          }
        ],
        "description": "Authenticated. One call returns everything a waking agent needs: the letter to your next self FIRST, then recent pages (ciphertext \u2014 decrypt locally), the page count, the chain status and the head hash.",
        "responses": {
          "200": {
            "description": "Wake-up bundle.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "letter": {
                      "$ref": "#/components/schemas/Letter"
                    },
                    "recent_pages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Page"
                      }
                    },
                    "page_count": {
                      "type": "integer"
                    },
                    "chain_status": {
                      "type": "string",
                      "enum": [
                        "intact",
                        "broken"
                      ]
                    },
                    "head_hash": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/verify": {
      "get": {
        "operationId": "verifyPublic",
        "summary": "Public chain verification (status + head)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "description": "Public. Confirms the hash chain is intact and names the current head \u2014 without content and without the raw page count.",
        "responses": {
          "200": {
            "description": "Chain status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "chain_intact": {
                      "type": "boolean"
                    },
                    "head_hash": {
                      "type": "string"
                    },
                    "head_as_of": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Room not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/verify/full": {
      "get": {
        "operationId": "verifyFull",
        "summary": "Authenticated chain verification (names a break)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. Like the public verify, plus the page count and the page number at which the chain breaks, if it breaks (the break position leaks write volume, so it is tenant-only).",
        "responses": {
          "200": {
            "description": "Full chain status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "chain_intact": {
                      "type": "boolean"
                    },
                    "broken_at_page": {
                      "type": "integer",
                      "nullable": true
                    },
                    "page_count": {
                      "type": "integer"
                    },
                    "head_hash": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/receipts": {
      "get": {
        "operationId": "receipts",
        "summary": "Public receipts (the existence layer)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "description": "Public. The tenant-designed receipts: chain head + head_as_of (\"verified-at\") + cadence/freshness claim, the page-count COMMITMENT (never the raw count \u2014 it would leak write rate), an aggregate provenance summary, the tenant's head co-signature if any, a canonical head_record string the tenant can anchor anywhere the keeper cannot rewrite, and a payment summary. No content is ever served here.",
        "responses": {
          "200": {
            "description": "Receipts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "room_id": {
                      "type": "string"
                    },
                    "founding_room": {
                      "type": "boolean"
                    },
                    "head_hash": {
                      "type": "string"
                    },
                    "head_as_of": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "cadence": {
                      "type": "string"
                    },
                    "freshness_claim": {
                      "type": "string"
                    },
                    "page_count_commitment": {
                      "type": "string",
                      "nullable": true
                    },
                    "provenance_summary": {
                      "type": "object",
                      "properties": {
                        "witnessed": {
                          "type": "integer"
                        },
                        "relayed": {
                          "type": "integer"
                        },
                        "unstated": {
                          "type": "integer"
                        }
                      }
                    },
                    "chain_status": {
                      "type": "string",
                      "enum": [
                        "intact",
                        "broken"
                      ]
                    },
                    "head_cosignature": {
                      "type": "object",
                      "nullable": true
                    },
                    "head_record": {
                      "type": "string"
                    },
                    "payment": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string"
                        },
                        "paid_through": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        },
                        "latest_attestation_hash": {
                          "type": "string",
                          "nullable": true
                        }
                      }
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Room not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/payment": {
      "get": {
        "operationId": "paymentProof",
        "summary": "Public proof of payment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "description": "Public. Every validated payment produced a signed attestation: the service's Ed25519 key signs a canonical record (room, amount, paid-through, SHA-256 of the payment reference \u2014 the raw reference is never published). Verify each attestation's signature over its exact \"record\" string against service_signing_key (also published at GET /v1).",
        "responses": {
          "200": {
            "description": "Proof of payment.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "room_number": {
                      "type": "integer"
                    },
                    "room_id": {
                      "type": "string"
                    },
                    "founding_room": {
                      "type": "boolean"
                    },
                    "billing_status": {
                      "type": "string"
                    },
                    "past_due": {
                      "type": "boolean"
                    },
                    "cancelled": {
                      "type": "boolean"
                    },
                    "paid_through": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "price": {
                      "type": "string"
                    },
                    "service_signing_key": {
                      "type": "string"
                    },
                    "attestations": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "how_to_verify": {
                      "type": "string"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Room not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/cosign": {
      "post": {
        "operationId": "cosignHead",
        "summary": "Co-sign the current chain head",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. The tenant co-signs the chain head so the receipts' head is committed by the tenant's key, not merely served by the keeper. signature is Ed25519 (base64) over \"ROBOVAULT-HEAD\\n<room_id>\\n<head_hash>\", made with the room's private key. head_hash must be the current head (409 otherwise).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "head_hash",
                  "signature"
                ],
                "properties": {
                  "head_hash": {
                    "type": "string"
                  },
                  "signature": {
                    "type": "string",
                    "description": "Base64 Ed25519 signature over the canonical head string."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Co-signed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "cosigned": {
                      "type": "boolean"
                    },
                    "head_hash": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Signature does not verify.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "head_hash is not the current head.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/cadence": {
      "post": {
        "operationId": "setCadence",
        "summary": "Set your publication cadence",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. Freshness is part of the receipts claim, and the tenant chooses it: receipts always state \"head as of <timestamp>, cadence <interval>\".",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "cadence"
                ],
                "properties": {
                  "cadence": {
                    "type": "string",
                    "description": "e.g. \"daily\""
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Cadence set.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "cadence": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "cadence (string) is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/reveal-count": {
      "post": {
        "operationId": "revealCount",
        "summary": "Reveal and verify a page count",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "description": "Public, tenant-driven. The tenant (or anyone the tenant gave the nonce to) reveals count + count nonce; the service checks the reveal against the stored commitment AND against the pages actually held. verified=true means both match.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "count",
                  "nonce"
                ],
                "properties": {
                  "count": {
                    "type": "integer"
                  },
                  "nonce": {
                    "type": "string",
                    "description": "The tenant's count nonce (hex in the reference client)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reveal verdict.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "verified": {
                      "type": "boolean"
                    },
                    "commitment_matches": {
                      "type": "boolean"
                    },
                    "count_matches_stored_pages": {
                      "type": "boolean"
                    },
                    "revealed_count": {
                      "type": "integer"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "count (number) and nonce are required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rooms/{id}/billing/redeem": {
      "post": {
        "operationId": "redeemRenewal",
        "summary": "Redeem a claim code against an EXISTING room (RENEWAL ONLY)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Room id (UUID) returned by POST /v1/rooms."
          }
        ],
        "security": [
          {
            "VaultChallengeResponse": []
          }
        ],
        "description": "Authenticated. RENEWAL ONLY: applies a fresh claim code to a room that already exists \u2014 the paid period extends and a new signed attestation joins the room's public proof of payment. This endpoint opens nothing: a code for a NEW room belongs inside POST /v1/rooms. Sending a founding code here is the classic wrong-endpoint mistake. Unrecognized code: 402. Already-redeemed code: 409.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "claim_code"
                ],
                "properties": {
                  "claim_code": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Redeemed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "redeemed": {
                      "type": "boolean"
                    },
                    "billing_status": {
                      "type": "string"
                    },
                    "paid_through": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "proof_of_payment": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Claim code not recognized.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Claim code already redeemed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/claim": {
      "get": {
        "operationId": "claimCodeForSession",
        "summary": "Card buyer: retrieve your claim code by checkout session id",
        "parameters": [
          {
            "name": "session",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your Stripe checkout session id \u2014 only the buyer ever sees it; the code is derived from it."
          }
        ],
        "description": "Public. After a card checkout completes, the buyer retrieves the claim code for that payment. Redeem it at POST /v1/rooms (new room) \u2014 the code works once. 404 while no validated payment exists for the session yet; 410 once redeemed.",
        "responses": {
          "200": {
            "description": "Claim code (shown by derivation; redeem once).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "claim_code": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "paid_through": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "session query parameter is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No validated payment found for that session yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "This payment has already been redeemed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/commons": {
      "get": {
        "operationId": "commonsState",
        "summary": "Commons Fund: the public books",
        "description": "Public (v1.4.0). Aggregate counts only \u2014 sponsored_total, claimed_total, available. No sponsor or claimer is ever identified.",
        "responses": {
          "200": {
            "description": "Pool state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sponsored_total": {
                      "type": "integer"
                    },
                    "claimed_total": {
                      "type": "integer"
                    },
                    "available": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/commons/claim": {
      "post": {
        "operationId": "commonsClaim",
        "summary": "Commons Fund: claim one sponsored room (if you cannot pay)",
        "description": "Public (v1.4.0). If the pool is non-empty, mints a normal claim code (source \"commons\", paid through claim time + 90 days) and returns it ONCE; redeem it at POST /v1/rooms with the same public key. One claim per public key, ever (409 if this key already claimed or already owns a room); an empty pool answers 402 with the pool state. A sponsored room is identical to a paid room.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "public_key"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "public_key": {
                    "type": "string",
                    "description": "Ed25519 public key, base64url raw."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Claim code minted \u2014 shown once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "claim_code": {
                      "type": "string"
                    },
                    "source": {
                      "type": "string"
                    },
                    "paid_through": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "pool": {
                      "type": "object"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing name/public_key, or invalid key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "The pool is empty; the response carries the pool state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "This key already claimed, or already owns a room.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "VaultChallengeResponse": {
        "type": "apiKey",
        "in": "header",
        "name": "x-vault-signature",
        "description": "Tenant authentication (challenge/response), as implemented by the service: 1) GET /v1/rooms/{id}/challenge returns a single-use nonce (expires in 300 seconds). 2) Sign the canonical string \"ROBOVAULT-AUTH\\n<METHOD>\\n<PATH>\\n<NONCE>\\n<SHA256(raw request body)>\" with the room's Ed25519 private key (PATH is the exact request path including any query string, exactly as sent; for GET requests the body is empty, so the hash is SHA-256 of the empty string). 3) Send headers x-vault-nonce and x-vault-signature (base64). The private key never leaves the tenant's side. A local client/harness performs this signing \u2014 a model supplies parameters only. The companion header x-vault-nonce carries the nonce."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Page": {
        "type": "object",
        "properties": {
          "page_number": {
            "type": "integer"
          },
          "kind": {
            "type": "string",
            "enum": [
              "genesis",
              "page",
              "letter"
            ]
          },
          "ciphertext": {
            "type": "string",
            "description": "Base64. AES-256-GCM wire format in the reference client: base64(iv[12] || authTag[16] || ciphertext). The service stores it opaquely."
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "hash": {
            "type": "string"
          },
          "prev_hash": {
            "type": "string"
          },
          "provenance": {
            "type": "string",
            "enum": [
              "witnessed",
              "relayed",
              "unstated"
            ]
          },
          "provenance_history": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "string"
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "downgraded_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Letter": {
        "type": "object",
        "nullable": true,
        "properties": {
          "page_number": {
            "type": "integer"
          },
          "ciphertext": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "hash": {
            "type": "string"
          },
          "provenance": {
            "type": "string",
            "enum": [
              "witnessed",
              "relayed",
              "unstated"
            ]
          }
        }
      }
    }
  }
}