{
  "openapi": "3.0.3",
  "info": {
    "title": "PolicyCheck API",
    "version": "2.1.0",
    "description": "Independent seller policy facts with source excerpts and signed provenance. The calling agent makes purchase decisions."
  },
  "servers": [
    {
      "url": "https://policycheck.tools"
    }
  ],
  "paths": {
    "/api/check": {
      "post": {
        "operationId": "checkPolicies",
        "summary": "Extract signed seller policy facts",
        "description": "No scores or purchase verdicts. Missing facts do not mean false. Inspect status, provenance and limitations.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "seller_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Discover common seller policy paths"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Fetch exactly this policy page"
                  },
                  "policy_text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000
                  },
                  "text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000,
                    "description": "Alias for policy_text"
                  },
                  "agent_id": {
                    "type": "string",
                    "maxLength": 256
                  },
                  "transaction_ref": {
                    "type": "string",
                    "maxLength": 256
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "seller_url"
                    ]
                  },
                  {
                    "required": [
                      "url"
                    ]
                  },
                  {
                    "required": [
                      "policy_text"
                    ]
                  },
                  {
                    "required": [
                      "text"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed result; may disclose incomplete or failed extraction",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Analysis"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "503": {
            "description": "Analysis or signing unavailable"
          }
        }
      }
    },
    "/api/v1/signed-assessment": {
      "post": {
        "operationId": "createSignedAssessment",
        "summary": "Extract signed seller policy facts",
        "description": "No scores or purchase verdicts. Missing facts do not mean false. Inspect status, provenance and limitations.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "seller_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Discover common seller policy paths"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Fetch exactly this policy page"
                  },
                  "policy_text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000
                  },
                  "text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000,
                    "description": "Alias for policy_text"
                  },
                  "agent_id": {
                    "type": "string",
                    "maxLength": 256
                  },
                  "transaction_ref": {
                    "type": "string",
                    "maxLength": 256
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "seller_url"
                    ]
                  },
                  {
                    "required": [
                      "url"
                    ]
                  },
                  {
                    "required": [
                      "policy_text"
                    ]
                  },
                  {
                    "required": [
                      "text"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed result; may disclose incomplete or failed extraction",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Analysis"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "503": {
            "description": "Analysis or signing unavailable"
          }
        }
      }
    },
    "/api/chatgpt/analyze": {
      "post": {
        "operationId": "analyzeLegalDocument",
        "summary": "Extract signed seller policy facts",
        "description": "No scores or purchase verdicts. Missing facts do not mean false. Inspect status, provenance and limitations.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "seller_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Discover common seller policy paths"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Fetch exactly this policy page"
                  },
                  "policy_text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000
                  },
                  "text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000,
                    "description": "Alias for policy_text"
                  },
                  "agent_id": {
                    "type": "string",
                    "maxLength": 256
                  },
                  "transaction_ref": {
                    "type": "string",
                    "maxLength": 256
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "seller_url"
                    ]
                  },
                  {
                    "required": [
                      "url"
                    ]
                  },
                  {
                    "required": [
                      "policy_text"
                    ]
                  },
                  {
                    "required": [
                      "text"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed result; may disclose incomplete or failed extraction",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Analysis"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "503": {
            "description": "Analysis or signing unavailable"
          }
        }
      }
    },
    "/api/chatgpt/analyze-url": {
      "post": {
        "operationId": "analyzePolicyUrl",
        "summary": "Extract signed seller policy facts",
        "description": "No scores or purchase verdicts. Missing facts do not mean false. Inspect status, provenance and limitations.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "seller_url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Discover common seller policy paths"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "Fetch exactly this policy page"
                  },
                  "policy_text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000
                  },
                  "text": {
                    "type": "string",
                    "minLength": 50,
                    "maxLength": 100000,
                    "description": "Alias for policy_text"
                  },
                  "agent_id": {
                    "type": "string",
                    "maxLength": 256
                  },
                  "transaction_ref": {
                    "type": "string",
                    "maxLength": 256
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "seller_url"
                    ]
                  },
                  {
                    "required": [
                      "url"
                    ]
                  },
                  {
                    "required": [
                      "policy_text"
                    ]
                  },
                  {
                    "required": [
                      "text"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed result; may disclose incomplete or failed extraction",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Analysis"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "503": {
            "description": "Analysis or signing unavailable"
          }
        }
      }
    },
    "/api/v1/verify": {
      "post": {
        "operationId": "verifyAssessment",
        "summary": "Verify signature and freshness separately",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "signed_assessment",
                  "signature"
                ],
                "properties": {
                  "signed_assessment": {
                    "type": "object"
                  },
                  "signature": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validity result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "valid": {
                      "type": "boolean"
                    },
                    "signature_valid": {
                      "type": "boolean"
                    },
                    "fresh": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid verification request"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Analysis": {
        "type": "object",
        "required": [
          "analysis_status",
          "policies",
          "sources",
          "limitations",
          "signed_assessment",
          "signature"
        ],
        "properties": {
          "analysis_status": {
            "type": "string",
            "enum": [
              "complete",
              "partial",
              "text_provided",
              "no_content",
              "no_facts",
              "extraction_failed"
            ]
          },
          "policies": {
            "type": "object",
            "additionalProperties": true
          },
          "clauses": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "coverage": {
            "type": "object"
          },
          "limitations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "signed_assessment": {
            "type": "object",
            "description": "Exact signed v2.1 payload binding facts, provenance, timestamps, context and limitations"
          },
          "signature": {
            "type": "string",
            "description": "Ed25519 signature, base64url"
          },
          "audit_recorded": {
            "type": "boolean"
          }
        }
      }
    }
  }
}
