{
  "openapi": "3.0.3",
  "info": {
    "title": "ProvablyFair.click REST & MCP API",
    "version": "0.3.0",
    "description": "REST API and MCP service for supported provably-fair reference verification, certificate-status lookups, prepaid agent credit, and customer subscriptions. Customer subscription invoices support native ETH and official Ethereum USDC. Agent prepaid-credit invoices currently support Ethereum USDC only. Payment collection is live: subscriptions and agent credit are billed through server-created invoices verified on-chain. Never transfer funds without a valid server-created invoice. Automated reference checks and signed evidence records are not independent audits or certificates. Certification requires a separately scoped human review.",
    "contact": {
      "name": "ProvablyFair.click Support",
      "email": "support@provablyfair.click"
    }
  },
  "servers": [
    {
      "url": "https://api.provablyfair.click",
      "description": "Production API custom domain"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Verification"
    },
    {
      "name": "Agents"
    },
    {
      "name": "Certificates"
    },
    {
      "name": "Payments"
    },
    {
      "name": "Operations"
    },
    {
      "name": "Monitoring"
    }
  ],
  "paths": {
    "/admin/agents": {
      "post": {
        "tags": [
          "Operations"
        ],
        "security": [
          {
            "adminToken": []
          }
        ],
        "summary": "Create an agent API key",
        "description": "Creates an agent identity and returns a bearer API key (pfc_...). The key is shown once and never returned again; store it securely. The agent starts with a zero prepaid USDC balance and tops up through the credits invoice flow.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Human-readable agent name"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Agent created; apiKey is returned exactly once"
          },
          "400": {
            "description": "Invalid name"
          },
          "403": {
            "description": "Admin authorization required"
          }
        }
      }
    },
    "/admin/audits/{engagementId}/findings": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Record an audit finding",
        "description": "Admin-only reviewer action. Stores severity, description, reproduction steps, recommendation and evidence references. AI output cannot create an authoritative finding.",
        "security": [
          {
            "adminToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditFinding"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Finding created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/admin/audits/{engagementId}/findings/{findingId}/status": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Update finding remediation status",
        "description": "Admin-only reviewer action. Records remediation submitted, verified fixed or accepted risk. Verified-fixed and accepted-risk are reviewer determinations.",
        "security": [
          {
            "adminToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditFindingStatus"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Finding status updated"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/admin/audits/{engagementId}/reports": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Create a versioned draft audit report",
        "description": "Admin-only reviewer action. Builds a report draft from recorded engagement scope, evidence, stage reviews and findings. It is not published, a certificate or a promise of a passing result.",
        "security": [
          {
            "adminToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditPublish"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Draft report created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/admin/audits/{engagementId}/reports/{reportId}/publish": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Publish a reviewed audit report",
        "description": "Admin-only reviewer action. Publication is blocked unless every requested stage has an explicit final status and no critical finding remains open. A published audit report is not an automatically issued certificate; certificate issuance remains a separate policy and approval action.",
        "security": [
          {
            "adminToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditPublish"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Report published"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/admin/audits/{engagementId}/stages": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Record a human-reviewed stage outcome",
        "description": "Admin-only reviewer action. Records a stage status, summary and evidence references for a stage included in the agreed engagement scope.",
        "security": [
          {
            "adminToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditStageReview"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stage review saved"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/admin/certificates": {
      "post": {
        "tags": [
          "Operations"
        ],
        "security": [
          {
            "adminToken": []
          }
        ],
        "summary": "Issue a certificate for a published audit report",
        "description": "Issues a certificate (PFC-YYYY-NNNN, 12-month default validity) only for an engagement whose audit report is published. Operator, game and version come from the engagement; the ruleset hash is supplied by the reviewer. Rejected if an active certificate already covers the same operator, game and version.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "engagementId",
                  "reportId",
                  "rulesetHash"
                ],
                "properties": {
                  "engagementId": {
                    "type": "string",
                    "description": "Audit engagement id"
                  },
                  "reportId": {
                    "type": "string",
                    "description": "Published audit report id"
                  },
                  "rulesetHash": {
                    "type": "string",
                    "description": "Ruleset/build hash the certificate binds to"
                  },
                  "reportUrl": {
                    "type": "string",
                    "description": "Optional public report URL (defaults to the certificate page)"
                  },
                  "validityMonths": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 24,
                    "default": 12,
                    "description": "Certificate validity in months"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Certificate issued"
          },
          "400": {
            "description": "Invalid input"
          },
          "403": {
            "description": "Admin authorization required"
          },
          "404": {
            "description": "Engagement or report not found"
          },
          "409": {
            "description": "Report not published, or an active certificate already covers this game and version"
          },
          "503": {
            "description": "Issuance disabled"
          }
        }
      }
    },
    "/admin/certificates/{certificateId}/status": {
      "post": {
        "tags": [
          "Operations"
        ],
        "security": [
          {
            "adminToken": []
          }
        ],
        "summary": "Change a certificate lifecycle status",
        "description": "Suspend, revoke, expire or reactivate a certificate. The public lookup, directory and live status badge reflect the new status immediately.",
        "parameters": [
          {
            "name": "certificateId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "status"
                ],
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "expired",
                      "suspended",
                      "revoked"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Status updated"
          },
          "400": {
            "description": "Invalid status"
          },
          "403": {
            "description": "Admin authorization required"
          },
          "404": {
            "description": "Certificate not found"
          }
        }
      }
    },
    "/admin/licenses": {
      "post": {
        "tags": [
          "Operations"
        ],
        "security": [
          {
            "adminToken": []
          }
        ],
        "summary": "Mint a desktop license",
        "description": "Creates a desktop license key (pfc-lic-...). The key is shown once and never returned again. Default 3 machines, 365-day validity.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 100
                  },
                  "ownerUserId": {
                    "type": "string",
                    "description": "Customer account id that owns the license"
                  },
                  "maxMachines": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 50,
                    "default": 3
                  },
                  "validityDays": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1095,
                    "default": 365
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "License created; key returned exactly once"
          },
          "400": {
            "description": "Invalid input"
          },
          "403": {
            "description": "Admin authorization required"
          }
        }
      }
    },
    "/admin/qa/latest": {
      "get": {
        "tags": [
          "Operations"
        ],
        "security": [
          {
            "adminToken": []
          }
        ],
        "summary": "Read latest QA agent run",
        "responses": {
          "200": {
            "description": "Latest persisted QA report or null"
          },
          "403": {
            "description": "Admin authorization required"
          }
        }
      }
    },
    "/admin/qa/run": {
      "post": {
        "tags": [
          "Operations"
        ],
        "security": [
          {
            "adminToken": []
          }
        ],
        "summary": "Run read-only production QA suite",
        "description": "Runs D1 migration/table/trigger checks, Ethereum RPC read-only probes, unauthenticated REST authorization tests, CORS preflight, MCP initialize/tools-list and Workers AI failure analysis. It does not submit money, mutate customer balances or issue certificates. Frontend builds and repository unit tests require a separate CI/test runner.",
        "responses": {
          "200": {
            "description": "Structured QA report, counts and AI summary"
          },
          "403": {
            "description": "Admin authorization required"
          }
        }
      }
    },
    "/api/v1/account": {
      "get": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Read customer account and subscription",
        "responses": {
          "200": {
            "description": "Customer and subscription entitlement"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/v1/agents": {
      "get": {
        "tags": [
          "Agents"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "List your agent API keys",
        "description": "Lists the agent keys created by the signed-in customer account (id, name, balance, status). Key values are never returned.",
        "responses": {
          "200": {
            "description": "List of agent keys"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "tags": [
          "Agents"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Create an agent API key (self-serve)",
        "description": "Creates an agent API key owned by the signed-in customer account. The key is shown once and never returned again; store it securely. Each key gets 1,000 free verifications per month before per-call billing (5,000 with Verifier Pro, 25,000 with Studio Integrity). Maximum 5 active keys per account.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100,
                    "description": "Human-readable agent name"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Agent created; apiKey is returned exactly once"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "429": {
            "description": "Key limit reached (5 active keys)"
          }
        }
      }
    },
    "/api/v1/agents/{agentId}/disable": {
      "post": {
        "tags": [
          "Agents"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Disable one of your agent API keys",
        "description": "Permanently disables an agent key owned by the signed-in customer account. Disabled keys cannot call paid tools or use the free allowance.",
        "parameters": [
          {
            "name": "agentId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Agent key id"
          }
        ],
        "responses": {
          "200": {
            "description": "Key disabled"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Agent key not found"
          }
        }
      }
    },
    "/api/v1/audits/engagements": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Submit an S1\u2013S7 audit engagement request",
        "description": "Creates a customer-owned engagement intake. It records requested game/version/protocol/stages and scope notes. Submission is not acceptance, payment, an audit result or a certificate. A human reviewer must confirm the statement of work, scope, access and fee before work starts.",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditEngagementRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Engagement request accepted"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      },
      "get": {
        "tags": [
          "Audits & Certification"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "List the signed-in customer's audit engagements",
        "responses": {
          "200": {
            "description": "Engagement list"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/v1/audits/engagements/{engagementId}": {
      "get": {
        "tags": [
          "Audits & Certification"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Get an audit engagement, evidence, stage reviews, findings and published reports",
        "parameters": [
          {
            "name": "engagementId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customer-owned audit engagement"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Engagement not found"
          }
        }
      }
    },
    "/api/v1/audits/engagements/{engagementId}/evidence": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Add structured evidence metadata",
        "description": "Adds a structured JSON evidence record to the customer's engagement, calculates a SHA-256 digest, and stores metadata. Maximum payload 64 KiB. The API rejects credential-like keys such as private keys, passwords, recovery phrases, auth tokens and unrevealed seeds. Binary file upload/storage is not supported by this endpoint.",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditEvidenceRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Evidence record stored"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/api/v1/audits/engagements/{engagementId}/plan": {
      "post": {
        "tags": [
          "Audits & Certification"
        ],
        "summary": "Generate an AI-assisted draft S1\u2013S7 test plan",
        "description": "Uses Workers AI to draft stage questions, evidence gaps, candidate reproducible tests and limitations from the engagement scope and evidence metadata. It does not execute the tests, assign stage verdicts, invent evidence, certify a game or approve a statement of work.",
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditPlanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "AI draft plan stored"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Authentication required"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Engagement or item not found"
          },
          "409": {
            "description": "Workflow precondition not satisfied"
          }
        }
      }
    },
    "/api/v1/auth/forgot-password": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [],
        "summary": "Request password reset",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmailOnly"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Request accepted"
          }
        }
      }
    },
    "/api/v1/auth/login": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [],
        "summary": "Sign in customer",
        "description": "Sets the HttpOnly Secure pfc_session cookie after email verification.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuthCredentials"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in and session cookie set",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Invalid credentials"
          },
          "403": {
            "description": "Email not verified"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/api/v1/auth/logout": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Sign out customer",
        "responses": {
          "200": {
            "description": "Session revoked and cookie cleared"
          },
          "401": {
            "description": "Session missing or expired"
          }
        }
      }
    },
    "/api/v1/auth/register": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [],
        "summary": "Register a customer account",
        "description": "Creates an account and sends a 24-hour email verification link. Passwords are PBKDF2-SHA256 hashed.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuthCredentials"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Registration accepted; check email"
          },
          "400": {
            "description": "Invalid email or password"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Email or database unavailable"
          }
        }
      }
    },
    "/api/v1/auth/resend-verification": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [],
        "summary": "Resend verification email",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmailOnly"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Request accepted"
          }
        }
      }
    },
    "/api/v1/auth/reset-password": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [],
        "summary": "Reset password",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PasswordReset"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password changed; existing sessions revoked"
          },
          "400": {
            "description": "Invalid or expired reset token"
          }
        }
      }
    },
    "/api/v1/auth/verify-email": {
      "post": {
        "tags": [
          "Customer Accounts"
        ],
        "security": [],
        "summary": "Verify customer email",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EmailToken"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Email verified"
          },
          "400": {
            "description": "Invalid or expired token"
          }
        }
      }
    },
    "/api/v1/certificates/{certificateId}": {
      "get": {
        "tags": [
          "Certificates"
        ],
        "security": [],
        "summary": "Look up issued certificate status",
        "parameters": [
          {
            "name": "certificateId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Certificate record"
          },
          "404": {
            "description": "No certificate exists"
          }
        },
        "description": "Includes next_review_at (quarterly review date)."
      }
    },
    "/api/v1/certificates/{certificateId}/badge": {
      "get": {
        "tags": [
          "Certificates"
        ],
        "summary": "Live status badge (SVG) for a certificate",
        "description": "Returns an embeddable SVG badge showing the certificate's current status (active, expired, suspended, revoked, or NOT VERIFIED for unknown ids). Operators embed it on their site; the badge always reflects live status. Cached for 5 minutes.",
        "parameters": [
          {
            "name": "certificateId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "SVG badge",
            "content": {
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/credits": {
      "get": {
        "tags": [
          "Agents"
        ],
        "summary": "Read authenticated agent prepaid USDC balance",
        "responses": {
          "200": {
            "description": "Balance JSON"
          },
          "401": {
            "description": "Invalid API key"
          }
        }
      }
    },
    "/api/v1/credits/claim": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Claim previously confirmed USDC transfer (DISABLED UNTIL VALIDATED)",
        "description": "Claims a previously issued agent-credit invoice after server-side Ethereum USDC receipt/log, recipient, exact amount, canonical block, time-window and 12-confirmation verification. A transaction hash alone cannot create credit.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "invoiceId",
                  "transaction"
                ],
                "properties": {
                  "invoiceId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "transaction": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Credited amount, only if enabled"
          },
          "503": {
            "description": "Payment service disabled"
          }
        }
      }
    },
    "/api/v1/credits/invoices": {
      "post": {
        "tags": [
          "Payments"
        ],
        "summary": "Create agent-owned Ethereum USDC prepaid invoice",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "chain"
                ],
                "properties": {
                  "chain": {
                    "type": "string",
                    "enum": [
                      "ethereum"
                    ],
                    "description": "Ethereum mainnet only"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Issued invoice reference and exact amount"
          },
          "503": {
            "description": "Payment collection disabled"
          }
        },
        "description": "Creates a unique 30-minute agent-credit invoice for at least 10 USDC on Ethereum mainnet. This path is protected by the agent bearer key and the payment gate."
      }
    },
    "/api/v1/desktop/plan": {
      "post": {
        "tags": [
          "Desktop"
        ],
        "security": [
          {
            "licenseKey": []
          }
        ],
        "summary": "Draft an S1\u2013S7 audit plan (desktop AI connector)",
        "description": "Uses Cloudflare Workers AI to draft an S1\u2013S7 audit plan from a scope and evidence metadata. Authenticated by desktop license key. The AI drafts the plan only; it never performs tests, assigns verdicts, or issues certificates.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "game",
                  "gameVersion"
                ],
                "properties": {
                  "game": {
                    "type": "string"
                  },
                  "gameVersion": {
                    "type": "string"
                  },
                  "protocol": {
                    "type": "string",
                    "default": "pfc-hmac-v1"
                  },
                  "description": {
                    "type": "string"
                  },
                  "requestedStages": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "S1",
                        "S2",
                        "S3",
                        "S4",
                        "S5",
                        "S6",
                        "S7"
                      ]
                    }
                  },
                  "evidence": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "title": {
                          "type": "string"
                        },
                        "description": {
                          "type": "string"
                        },
                        "sha256": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Draft audit plan"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "License key required or not recognized"
          },
          "403": {
            "description": "License inactive or expired"
          },
          "503": {
            "description": "Workers AI unavailable"
          }
        }
      }
    },
    "/api/v1/desktop/reports": {
      "get": {
        "tags": [
          "Desktop"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "List your synced desktop audit reports",
        "description": "Lists desktop audit reports synced from licenses owned by the signed-in customer account (latest 100).",
        "responses": {
          "200": {
            "description": "List of desktop reports"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      },
      "post": {
        "tags": [
          "Desktop"
        ],
        "security": [
          {
            "licenseKey": []
          }
        ],
        "summary": "Sync a desktop audit report",
        "description": "Stores a desktop audit report produced by the licensed pfc runner. verified + failed + inconclusive must equal roundsChecked. Report body is capped at 256 KiB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "game",
                  "gameVersion",
                  "roundsChecked",
                  "verified",
                  "failed",
                  "inconclusive",
                  "report"
                ],
                "properties": {
                  "game": {
                    "type": "string"
                  },
                  "gameVersion": {
                    "type": "string"
                  },
                  "roundsChecked": {
                    "type": "integer"
                  },
                  "verified": {
                    "type": "integer"
                  },
                  "failed": {
                    "type": "integer"
                  },
                  "inconclusive": {
                    "type": "integer"
                  },
                  "rtpObserved": {
                    "type": "number"
                  },
                  "rtpTheoretical": {
                    "type": "number"
                  },
                  "report": {
                    "type": "object",
                    "description": "Full report document"
                  },
                  "machineId": {
                    "type": "string",
                    "description": "Machine the report was produced on"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Report stored"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "License key required or not recognized"
          },
          "403": {
            "description": "License inactive or expired"
          },
          "413": {
            "description": "Report too large"
          }
        }
      }
    },
    "/api/v1/evidence": {
      "post": {
        "tags": [
          "Verification"
        ],
        "summary": "Generate HMAC-sealed reference evidence (5 USDC)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Round"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed record (not an issued certificate)"
          }
        },
        "description": "Creates an HMAC-sealed reference-round evidence record when the signing key is configured. This is not an independently issued audit certificate."
      }
    },
    "/api/v1/games": {
      "get": {
        "summary": "List supported games",
        "description": "Free, no key. The full catalog of 12 supported pfc-hmac-v1 games with parameters, outcome shapes and reference RTP where applicable.",
        "tags": [
          "Agents"
        ],
        "responses": {
          "200": {
            "description": "Game catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "protocol": {
                      "type": "string",
                      "example": "pfc-hmac-v1"
                    },
                    "count": {
                      "type": "integer",
                      "example": 12
                    },
                    "games": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/licenses": {
      "get": {
        "tags": [
          "Desktop"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "List your desktop licenses",
        "description": "Lists the desktop licenses owned by the signed-in customer account. Key values are never returned.",
        "responses": {
          "200": {
            "description": "List of licenses"
          },
          "401": {
            "description": "Authentication required"
          }
        }
      }
    },
    "/api/v1/licenses/validate": {
      "post": {
        "tags": [
          "Desktop"
        ],
        "summary": "Validate a desktop license key",
        "description": "Validates a desktop license key and records (or refreshes) a machine activation. A new machine counts against the license seat limit (default 3).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "description": "License key (pfc-lic-...)"
                  },
                  "machineId": {
                    "type": "string",
                    "description": "Stable machine identifier (defaults to the hostname in the CLI)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "License status"
          },
          "401": {
            "description": "License key not recognized"
          },
          "403": {
            "description": "License suspended, revoked or expired"
          },
          "409": {
            "description": "Machine seat limit reached"
          }
        }
      }
    },
    "/api/v1/licenses/{licenseId}/deactivate": {
      "post": {
        "tags": [
          "Desktop"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Deactivate a machine on one of your licenses",
        "description": "Frees a machine seat on a license owned by the signed-in customer account.",
        "parameters": [
          {
            "name": "licenseId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "machineId"
                ],
                "properties": {
                  "machineId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Machine deactivated"
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "License or activation not found"
          }
        }
      }
    },
    "/api/v1/slots/rtp": {
      "post": {
        "summary": "Exact analytic slots RTP",
        "description": "Free, no key. Computes the exact analytic RTP (no simulation) for a slots configuration. Defaults to the reference configuration: 95.72% (5 reels) or 93.87% (3 reels).",
        "tags": [
          "Agents"
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "reels": {
                    "type": "integer",
                    "enum": [
                      3,
                      5
                    ],
                    "default": 5
                  },
                  "reelStrips": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  },
                  "stripWeights": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "number"
                      }
                    }
                  },
                  "paylines": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    }
                  },
                  "paytable": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object"
                    }
                  },
                  "wild": {
                    "type": "string"
                  },
                  "scatter": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Exact RTP result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "rtp": {
                      "type": "number",
                      "example": 0.9572
                    },
                    "rtpPercent": {
                      "type": "number",
                      "example": 95.72
                    },
                    "expectedWinPerSpin": {
                      "type": "number"
                    },
                    "lines": {
                      "type": "integer",
                      "example": 5
                    },
                    "reels": {
                      "type": "integer",
                      "example": 5
                    },
                    "method": {
                      "type": "string",
                      "example": "analytic (exact, no simulation)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid slots configuration"
          }
        }
      }
    },
    "/api/v1/stats": {
      "get": {
        "summary": "Public service statistics",
        "description": "Free, no key. Verification counts by outcome, batch/suite/evidence usage, and when counting began. Counters record API reference-round checks, not audited or certified games.",
        "tags": [
          "Agents"
        ],
        "responses": {
          "200": {
            "description": "Service statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "verifications_total": {
                      "type": "integer"
                    },
                    "verified": {
                      "type": "integer"
                    },
                    "failed": {
                      "type": "integer"
                    },
                    "inconclusive": {
                      "type": "integer"
                    },
                    "unsupported": {
                      "type": "integer"
                    },
                    "batches": {
                      "type": "integer"
                    },
                    "suites": {
                      "type": "integer"
                    },
                    "evidence": {
                      "type": "integer"
                    },
                    "started_at": {
                      "type": "string"
                    },
                    "games": {
                      "type": "integer",
                      "example": 12
                    },
                    "protocol": {
                      "type": "string",
                      "example": "pfc-hmac-v1"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/subscriptions/claim": {
      "post": {
        "tags": [
          "Payments"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Verify customer payment and activate subscription",
        "description": "Server verifies Ethereum mainnet, transaction receipt, canonical block, exact asset/amount/recipient, invoice expiry and 12 confirmations. Claim is atomic and transaction hashes cannot be replayed across customer and agent billing.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentClaimRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment verified and 30-day subscription activated or extended"
          },
          "409": {
            "description": "Not confirmed, mismatched, expired or previously claimed transaction"
          },
          "503": {
            "description": "Payment service disabled or chain verification unavailable"
          }
        }
      }
    },
    "/api/v1/subscriptions/free": {
      "post": {
        "tags": [
          "Payments"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Activate the free Public Verifier plan ($0, 1-year term)",
        "description": "Requires a verified customer session. No payment and no invoice. Activates the free plan for 1 year (365 days); the plan covers the audit filing path (engagement, evidence, stage reviews, draft report, publish, certificate) while metered tools stay pay-per-use. Re-activating while the free plan is active is idempotent and returns the current subscription. Note: this endpoint ships with the free-plan API release and returns 404 on the currently deployed API until that release is deployed.",
        "responses": {
          "200": {
            "description": "Free subscription activated (or the current free subscription, if already active)"
          },
          "401": {
            "description": "Authentication required"
          },
          "409": {
            "description": "Account already holds an active paid subscription; the free plan cannot replace it"
          }
        }
      }
    },
    "/api/v1/subscriptions/invoices": {
      "post": {
        "tags": [
          "Payments"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Create customer ETH or USDC subscription invoice",
        "description": "Requires a verified customer session. Invoice is unique and expires in 30 minutes. ETH uses a fresh Chainlink ETH/USD quote; USDC uses exact six-decimal units.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubscriptionInvoiceRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invoice with exact amount, recipient and expiry"
          },
          "400": {
            "description": "Unsupported plan or asset"
          },
          "503": {
            "description": "Payment gate closed, RPC or invoice reservation unavailable"
          }
        }
      }
    },
    "/api/v1/suites/prelaunch": {
      "post": {
        "tags": [
          "Verification"
        ],
        "summary": "Run a prelaunch assessment: up to 50 reference rounds plus cross-round checks (15 USDC; not certification)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Batch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reference-check suite results"
          }
        },
        "description": "Runs up to 50 reference-protocol test vectors as a software prelaunch check. Does not perform source-code security review or issue certification."
      }
    },
    "/api/v1/tools": {
      "get": {
        "tags": [
          "Agents"
        ],
        "security": [],
        "summary": "Discover MCP tool definitions",
        "responses": {
          "200": {
            "description": "Tool catalog"
          }
        },
        "description": "Public discovery list for the MCP tool catalog. Paid tool calls require an authenticated agent key and applicable prepaid balance."
      }
    },
    "/api/v1/verify": {
      "post": {
        "tags": [
          "Verification"
        ],
        "summary": "Check one committed reference-protocol round (free tier, then 0.002 USDC)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Round"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reference outcome check"
          },
          "402": {
            "description": "Insufficient prepaid credit"
          },
          "409": {
            "description": "Duplicate idempotency key"
          },
          "429": {
            "description": "Free tier exhausted for the day (no key) or key limit reached"
          }
        },
        "description": "Free tier: 10 verifications per day with no key at all, and 1,000 free calls per calendar month on each agent key (more with a subscription). Free calls return the result plus a freeTier object showing the remaining allowance, and do not need an idempotency key. After the free allowance, a paid call requires an agent bearer key and X-Idempotency-Key (0.002 USDC). Recomputes only supported pfc-hmac-v1 reference rounds; it is not an operator audit or certification."
      }
    },
    "/api/v1/verify/batch": {
      "post": {
        "tags": [
          "Verification"
        ],
        "summary": "Check 1\u201350 reference rounds (0.001 USDC each)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Batch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch results"
          },
          "402": {
            "description": "Insufficient prepaid credit"
          }
        },
        "description": "Requires an agent bearer API key and X-Idempotency-Key. Accepts 1\u201350 reference rounds; not an audit or certification."
      }
    },
    "/health": {
      "get": {
        "tags": [
          "Operations"
        ],
        "security": [],
        "summary": "Service, payment gate and Workers AI status",
        "responses": {
          "200": {
            "description": "Returns ok, service, version, paymentsEnabled, certIssuanceEnabled and workersAiAvailable"
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": [
          "Agents"
        ],
        "summary": "MCP Streamable HTTP JSON-RPC 2.0 endpoint",
        "description": "Streamable HTTP JSON-RPC endpoint. initialize, ping, tools/list and tools/call are supported. Discovery is public; authenticated agent bearer credentials are required for paid tool calls. certificate_status is a public read-only status lookup. MCP transport does not grant certification authority. Tools (see tools/list): verify_bet \u2014 single-bet reference verification (free tier 10/day without a key, then 0.002 USDC per call); verify_batch \u2014 0.001 USDC per round, maximum 50 rounds; prelaunch_suite \u2014 15 USDC prelaunch assessment, up to 50 rounds; signed_evidence \u2014 5 USDC HMAC-sealed reference round report; certificate_status \u2014 free public certificate-status lookup; credit_balance \u2014 free authenticated prepaid-credit check; list_games \u2014 free, no key, catalog of 12 supported games; slots_rtp \u2014 free, no key, exact analytic slots RTP; verification_stats \u2014 free, no key, public service statistics; monitoring_status \u2014 free, key required, monitored-game status; monitoring_alerts \u2014 free, key required, unacknowledged monitoring alerts.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": {
                    "type": "string",
                    "enum": [
                      "2.0"
                    ]
                  },
                  "id": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "integer"
                      }
                    ]
                  },
                  "method": {
                    "type": "string"
                  },
                  "params": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "MCP JSON-RPC response"
          },
          "202": {
            "description": "Notification accepted"
          }
        }
      }
    },
    "/api/v1/licenses/invoices": {
      "post": {
        "summary": "Create a desktop license invoice",
        "description": "Verified customer session. Creates a 30-minute pay-confirm-unlock invoice for a desktop license tier (Solo $299/year, Studio $990/year; Enterprise is custom-priced and minted by an admin). Pay the exact amount in ETH, USDC, BTC or SOL, then claim with the transaction hash to receive the license key.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tier": {
                    "type": "string",
                    "enum": [
                      "solo",
                      "studio"
                    ]
                  },
                  "asset": {
                    "type": "string",
                    "enum": [
                      "ETH",
                      "USDC",
                      "BTC",
                      "SOL"
                    ]
                  }
                },
                "required": [
                  "tier",
                  "asset"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invoice created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invoiceId": {
                      "type": "string"
                    },
                    "plan": {
                      "type": "string"
                    },
                    "tier": {
                      "type": "string"
                    },
                    "machines": {
                      "type": "integer"
                    },
                    "asset": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "string"
                    },
                    "amountDisplay": {
                      "type": "string"
                    },
                    "usdPrice": {
                      "type": "string"
                    },
                    "recipient": {
                      "type": "string"
                    },
                    "expiresAt": {
                      "type": "string"
                    },
                    "confirmations": {
                      "type": [
                        "integer",
                        "string"
                      ]
                    },
                    "explorer": {
                      "type": "string"
                    },
                    "notice": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid tier or asset"
          },
          "401": {
            "description": "Sign in required"
          },
          "503": {
            "description": "Payments disabled"
          }
        }
      }
    },
    "/api/v1/licenses/claim": {
      "post": {
        "summary": "Claim a desktop license invoice",
        "description": "Verified customer session. Verifies the on-chain payment (12 ETH / 6 BTC confirmations, Solana finality) and mints the license atomically. The license key is returned once \u2014 store it securely.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "invoiceId": {
                    "type": "string"
                  },
                  "transaction": {
                    "type": "string"
                  }
                },
                "required": [
                  "invoiceId",
                  "transaction"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "License minted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invoiceId": {
                      "type": "string"
                    },
                    "transaction": {
                      "type": "string"
                    },
                    "plan": {
                      "type": "string"
                    },
                    "license": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "key": {
                          "type": "string"
                        },
                        "maxMachines": {
                          "type": "integer"
                        },
                        "expiresAt": {
                          "type": "string"
                        }
                      }
                    },
                    "warning": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Invoice not found for this account"
          },
          "409": {
            "description": "Payment mismatch, unconfirmed, or invoice already claimed"
          }
        }
      }
    },
    "/api/v1/invoices": {
      "get": {
        "summary": "List my invoices",
        "description": "Verified customer session. The customer's own subscription and desktop-license invoices, newest first (limit 100).",
        "responses": {
          "200": {
            "description": "Invoice list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invoices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "plan": {
                            "type": "string"
                          },
                          "chain": {
                            "type": "string"
                          },
                          "asset": {
                            "type": "string"
                          },
                          "amount_display": {
                            "type": "string"
                          },
                          "usd_price_cents": {
                            "type": "integer"
                          },
                          "recipient": {
                            "type": "string"
                          },
                          "created_at": {
                            "type": "integer"
                          },
                          "expires_at": {
                            "type": "integer"
                          },
                          "claimed_at": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "tx_hash": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/certificates/{certificateId}/monitoring": {
      "get": {
        "summary": "Monitoring history for a certificate",
        "description": "Public. The automated S6 re-verification record for a certificate: validity, evidence integrity, and stored test-vector checks, newest first.",
        "parameters": [
          {
            "name": "certificateId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Monitoring history",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "certificateId": {
                      "type": "string"
                    },
                    "checks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "checkedAt": {
                            "type": "string"
                          },
                          "checkType": {
                            "type": "string"
                          },
                          "result": {
                            "type": "string"
                          },
                          "detail": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Certificate not found"
          }
        }
      }
    },
    "/admin/monitoring/run": {
      "post": {
        "summary": "Run S6 monitoring now (admin)",
        "description": "Admin token required. Runs monitoring for one certificate (certificateId) or all active certificates. Results are recorded in the public monitoring history.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "certificateId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Monitoring results"
          },
          "403": {
            "description": "Admin token required"
          }
        }
      }
    },
    "/api/v1/monitoring/invoices": {
      "post": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Create a monitoring-plan invoice",
        "description": "Verified customer session. Creates a 30-minute pay-confirm-unlock invoice for a monitoring plan (Starter $99/month, Studio $299/month, Enterprise $999/month). Pay the exact amount in ETH, USDC, BTC or SOL, then claim with the transaction hash to activate the 30-day plan.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tier": {
                    "type": "string",
                    "enum": [
                      "starter",
                      "studio",
                      "enterprise"
                    ]
                  },
                  "asset": {
                    "type": "string",
                    "enum": [
                      "ETH",
                      "USDC",
                      "BTC",
                      "SOL"
                    ]
                  }
                },
                "required": [
                  "tier",
                  "asset"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Invoice created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "invoiceId": {
                      "type": "string"
                    },
                    "plan": {
                      "type": "string"
                    },
                    "tier": {
                      "type": "string"
                    },
                    "asset": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "string"
                    },
                    "amountDisplay": {
                      "type": "string"
                    },
                    "usdPrice": {
                      "type": "string"
                    },
                    "recipient": {
                      "type": "string"
                    },
                    "expiresAt": {
                      "type": "string"
                    },
                    "confirmations": {
                      "type": [
                        "integer",
                        "string"
                      ]
                    },
                    "explorer": {
                      "type": "string"
                    },
                    "notice": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid tier or asset"
          },
          "401": {
            "description": "Sign in required"
          },
          "503": {
            "description": "Payments disabled"
          }
        }
      }
    },
    "/api/v1/monitoring/claim": {
      "post": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Claim a paid monitoring invoice",
        "description": "Verified customer session. Claims a paid monitoring invoice by transaction hash; the 30-day plan activates in the same atomic step. Returns the monitoring subscription with its expiry.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PaymentClaimRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Plan activated"
          },
          "400": {
            "description": "Invalid claim"
          },
          "401": {
            "description": "Sign in required"
          },
          "404": {
            "description": "Invoice not found"
          },
          "409": {
            "description": "Payment mismatch, unconfirmed, or invoice already claimed"
          }
        }
      }
    },
    "/api/v1/monitors": {
      "post": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Register a game for monitoring",
        "description": "Verified customer session with an active monitoring plan and a free game slot. The game must be one of the 12 supported games. Optional ruleset hash (64 lowercase hex) enables ruleset-drift detection; an optional certificate ID enables expiry alerts; an optional https webhook URL needs the Studio tier or higher.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "game": {
                    "type": "string",
                    "enum": [
                      "dice",
                      "limbo",
                      "plinko",
                      "mines",
                      "bingo",
                      "roulette",
                      "keno",
                      "blackjack",
                      "poker",
                      "baccarat",
                      "videopoker",
                      "slots"
                    ]
                  },
                  "gameVersion": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "rulesetHash": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "certificateId": {
                    "type": "string",
                    "maxLength": 20
                  },
                  "webhookUrl": {
                    "type": "string",
                    "format": "uri"
                  }
                },
                "required": [
                  "name",
                  "game",
                  "gameVersion"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Monitor created"
          },
          "400": {
            "description": "Invalid game, ruleset hash or webhook URL"
          },
          "401": {
            "description": "Sign in required"
          },
          "402": {
            "description": "No active monitoring plan, game limit reached, or webhooks not included in the plan"
          },
          "404": {
            "description": "Linked certificate not found"
          },
          "409": {
            "description": "A monitor with this name already exists"
          }
        }
      },
      "get": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "List your monitors",
        "description": "Verified customer session. Returns the active monitoring subscription (or null), all monitors with their last scheduled run and open alert count, and this month's rounds usage against the plan quota.",
        "responses": {
          "200": {
            "description": "Monitors and subscription"
          },
          "401": {
            "description": "Sign in required"
          }
        }
      }
    },
    "/api/v1/monitors/{monitorId}": {
      "get": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Get one monitor with runs and alerts",
        "description": "Verified customer session. Returns the monitor, its 20 most recent scheduled runs, its 20 most recent alerts, and the total rounds verified.",
        "parameters": [
          {
            "name": "monitorId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Monitor id"
          }
        ],
        "responses": {
          "200": {
            "description": "Monitor detail"
          },
          "401": {
            "description": "Sign in required"
          },
          "404": {
            "description": "Monitor not found"
          }
        }
      },
      "patch": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Update a monitor",
        "description": "Verified customer session. Updates name, game version, ruleset hash, webhook URL, or pauses/resumes the monitor. A paused monitor accepts no rounds and runs no scheduled checks.",
        "parameters": [
          {
            "name": "monitorId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Monitor id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "gameVersion": {
                    "type": "string",
                    "maxLength": 40
                  },
                  "rulesetHash": {
                    "type": "string",
                    "pattern": "^[0-9a-f]{64}$"
                  },
                  "webhookUrl": {
                    "type": "string",
                    "format": "uri"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "paused"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Monitor updated"
          },
          "400": {
            "description": "Invalid field"
          },
          "401": {
            "description": "Sign in required"
          },
          "402": {
            "description": "Webhooks not included in the plan"
          },
          "404": {
            "description": "Monitor not found"
          },
          "409": {
            "description": "Another monitor already uses that name"
          }
        }
      }
    },
    "/api/v1/monitors/{monitorId}/rounds": {
      "post": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Ingest rounds for a monitor",
        "description": "Agent key of the monitor's owner (admin-minted keys have no owner and cannot ingest). 1-50 round objects per request, verified on receipt; only the seed hash, a hash of the client seed, the outcome and the display string are stored \u2014 never the server seed. Rounds count against the plan's monthly quota. The monitor must be active and the plan current.",
        "parameters": [
          {
            "name": "monitorId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Monitor id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Batch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rounds accepted with verification counts and remaining quota"
          },
          "400": {
            "description": "Invalid round input"
          },
          "401": {
            "description": "Invalid API key"
          },
          "402": {
            "description": "No active monitoring plan"
          },
          "403": {
            "description": "Key has no owner"
          },
          "404": {
            "description": "Monitor not found"
          },
          "409": {
            "description": "Monitor is paused"
          },
          "429": {
            "description": "Monthly rounds quota reached"
          }
        }
      }
    },
    "/api/v1/monitors/alerts/{alertId}/acknowledge": {
      "post": {
        "tags": [
          "Monitoring"
        ],
        "security": [
          {
            "cookieAuth": []
          }
        ],
        "summary": "Acknowledge a monitoring alert",
        "description": "Verified customer session. Marks one of your monitoring alerts acknowledged. A new alert of the same type can only be raised once the open one is acknowledged.",
        "parameters": [
          {
            "name": "alertId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Alert id"
          }
        ],
        "responses": {
          "200": {
            "description": "Alert acknowledged"
          },
          "401": {
            "description": "Sign in required"
          },
          "404": {
            "description": "Alert not found"
          }
        }
      }
    },
    "/api/v1/anchors": {
      "get": {
        "summary": "List proof anchors",
        "description": "Free, no key. The ProvablyFairAnchors registry contract address on Base and every anchored document digest with its status, transaction and block.",
        "tags": [
          "Agents"
        ],
        "responses": {
          "200": {
            "description": "Anchor list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "contractAddress": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "contractDeployed": {
                      "type": "boolean"
                    },
                    "anchors": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "basescan": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/anchors/{digest}": {
      "get": {
        "summary": "Check whether a digest is anchored on Base",
        "description": "Free, no key. Checks our anchor records first, then reads the registry contract live when it is deployed.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "digest",
            "in": "path",
            "required": true,
            "description": "SHA-256 digest as 64 lowercase hex characters.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Anchor check",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "digest": {
                      "type": "string"
                    },
                    "anchored": {
                      "type": "boolean"
                    },
                    "source": {
                      "type": "string"
                    },
                    "ref": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    },
                    "txHash": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "blockNumber": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "chainTimestamp": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid digest format",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/anchors/{digest}/document": {
      "get": {
        "summary": "Download an anchored document",
        "description": "Free, no key. Returns the exact document bytes whose SHA-256 digest was anchored, so anyone can hash it and compare.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "digest",
            "in": "path",
            "required": true,
            "description": "SHA-256 digest as 64 lowercase hex characters.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Anchored document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "digest": {
                      "type": "string"
                    },
                    "ref": {
                      "type": "string"
                    },
                    "document": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid digest format",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "No anchor with that digest",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "opaque agent key"
      },
      "cookieAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "pfc_session",
        "description": "HttpOnly customer session cookie set by successful login."
      },
      "adminToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Admin-Token",
        "description": "Administrative Worker secret. Never expose it in browser code or commit it to source."
      },
      "licenseKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-License-Key",
        "description": "Desktop license key (pfc-lic-...), issued by the operator."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "X-Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 12,
          "maxLength": 120
        },
        "description": "Unique key for charge replay prevention"
      }
    },
    "schemas": {
      "Round": {
        "type": "object",
        "required": [
          "protocol",
          "game",
          "serverSeed",
          "clientSeed",
          "nonce",
          "serverSeedHash",
          "observedOutcome"
        ],
        "properties": {
          "protocol": {
            "type": "string",
            "enum": [
              "pfc-hmac-v1"
            ]
          },
          "game": {
            "type": "string",
            "enum": [
              "dice",
              "limbo",
              "plinko",
              "mines",
              "bingo",
              "roulette",
              "keno",
              "blackjack",
              "poker",
              "baccarat",
              "videopoker",
              "slots"
            ]
          },
          "serverSeed": {
            "type": "string",
            "description": "Revealed seed only"
          },
          "clientSeed": {
            "type": "string"
          },
          "nonce": {
            "type": "integer",
            "minimum": 0
          },
          "serverSeedHash": {
            "type": "string",
            "pattern": "^[0-9a-fA-F]{64}$"
          },
          "observedOutcome": {
            "description": "Exact displayed outcome or complete reference result object"
          }
        }
      },
      "Batch": {
        "type": "object",
        "required": [
          "rounds"
        ],
        "properties": {
          "rounds": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/Round"
            }
          }
        }
      },
      "AuthCredentials": {
        "type": "object",
        "required": [
          "email",
          "password"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          },
          "password": {
            "type": "string",
            "minLength": 12,
            "maxLength": 128
          }
        }
      },
      "EmailOnly": {
        "type": "object",
        "required": [
          "email"
        ],
        "properties": {
          "email": {
            "type": "string",
            "format": "email"
          }
        }
      },
      "EmailToken": {
        "type": "object",
        "required": [
          "token"
        ],
        "properties": {
          "token": {
            "type": "string",
            "maxLength": 128
          }
        }
      },
      "PasswordReset": {
        "type": "object",
        "required": [
          "token",
          "password"
        ],
        "properties": {
          "token": {
            "type": "string",
            "maxLength": 128
          },
          "password": {
            "type": "string",
            "minLength": 12,
            "maxLength": 128
          }
        }
      },
      "SubscriptionInvoiceRequest": {
        "type": "object",
        "required": [
          "plan",
          "asset"
        ],
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "verifier",
              "studio"
            ]
          },
          "asset": {
            "type": "string",
            "enum": [
              "ETH",
              "USDC"
            ]
          }
        }
      },
      "PaymentClaimRequest": {
        "type": "object",
        "required": [
          "invoiceId",
          "transaction"
        ],
        "properties": {
          "invoiceId": {
            "type": "string",
            "format": "uuid"
          },
          "transaction": {
            "type": "string",
            "pattern": "^0x[0-9a-fA-F]{64}$"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "AuditEngagementRequest": {
        "type": "object",
        "required": [
          "operatorName",
          "websiteUrl",
          "gameName",
          "gameVersion",
          "protocol",
          "description"
        ],
        "properties": {
          "operatorName": {
            "type": "string",
            "maxLength": 120
          },
          "websiteUrl": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS URL only"
          },
          "gameName": {
            "type": "string",
            "maxLength": 100
          },
          "gameVersion": {
            "type": "string",
            "maxLength": 80
          },
          "protocol": {
            "type": "string",
            "maxLength": 100
          },
          "description": {
            "type": "string",
            "maxLength": 5000
          },
          "requestedStages": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "S1",
                "S2",
                "S3",
                "S4",
                "S5",
                "S6",
                "S7"
              ]
            },
            "minItems": 1,
            "maxItems": 7
          },
          "scopeNotes": {
            "type": "string",
            "maxLength": 4000
          }
        }
      },
      "AuditEvidenceRequest": {
        "type": "object",
        "required": [
          "evidenceType",
          "title",
          "payload"
        ],
        "properties": {
          "evidenceType": {
            "type": "string",
            "enum": [
              "protocol_spec",
              "game_rules",
              "payout_table",
              "round_samples",
              "build_manifest",
              "architecture",
              "test_vectors",
              "source_reference",
              "other"
            ]
          },
          "title": {
            "type": "string",
            "maxLength": 160
          },
          "description": {
            "type": "string",
            "maxLength": 2000
          },
          "sourceUrl": {
            "type": "string",
            "format": "uri",
            "description": "HTTPS source reference; not downloaded by API"
          },
          "payload": {
            "type": "object",
            "description": "Structured metadata or test evidence JSON, maximum 64 KiB. Never include credentials or unrevealed seeds."
          }
        }
      },
      "AuditPlanRequest": {
        "type": "object",
        "properties": {}
      },
      "AuditStageReview": {
        "type": "object",
        "required": [
          "stageId",
          "status",
          "summary"
        ],
        "properties": {
          "stageId": {
            "type": "string",
            "enum": [
              "S1",
              "S2",
              "S3",
              "S4",
              "S5",
              "S6",
              "S7"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "not_started",
              "in_progress",
              "passed",
              "failed",
              "inconclusive",
              "untested"
            ]
          },
          "summary": {
            "type": "string",
            "maxLength": 5000
          },
          "evidenceIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          }
        }
      },
      "AuditFinding": {
        "type": "object",
        "required": [
          "stageId",
          "severity",
          "title",
          "description"
        ],
        "properties": {
          "stageId": {
            "type": "string",
            "enum": [
              "S1",
              "S2",
              "S3",
              "S4",
              "S5",
              "S6",
              "S7"
            ]
          },
          "severity": {
            "type": "string",
            "enum": [
              "critical",
              "high",
              "medium",
              "low",
              "info"
            ]
          },
          "title": {
            "type": "string",
            "maxLength": 200
          },
          "description": {
            "type": "string",
            "maxLength": 8000
          },
          "reproduction": {
            "type": "string",
            "maxLength": 8000
          },
          "recommendation": {
            "type": "string",
            "maxLength": 8000
          },
          "evidenceIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 100
          }
        }
      },
      "AuditFindingStatus": {
        "type": "object",
        "required": [
          "status"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "remediation_submitted",
              "verified_fixed",
              "accepted_risk"
            ]
          }
        }
      },
      "AuditPublish": {
        "type": "object",
        "properties": {}
      }
    }
  }
}
