{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aipaygen.com/ai-terms/schema.json",
  "title": "AI Terms 0.1",
  "type": "object",
  "required": [
    "ai_terms",
    "site",
    "updated",
    "uses",
    "default"
  ],
  "properties": {
    "ai_terms": {
      "type": "string",
      "description": "Version of the spec the file follows."
    },
    "site": {
      "type": "string",
      "format": "uri",
      "description": "The origin the terms apply to."
    },
    "updated": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "uses": {
      "type": "object",
      "required": [
        "search",
        "answer",
        "training",
        "agent"
      ],
      "properties": {
        "search": {
          "$ref": "#/$defs/use"
        },
        "answer": {
          "$ref": "#/$defs/use"
        },
        "training": {
          "$ref": "#/$defs/use"
        },
        "agent": {
          "$ref": "#/$defs/use"
        }
      }
    },
    "default": {
      "enum": [
        "allow",
        "paid",
        "deny"
      ]
    },
    "paths": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "match",
          "uses"
        ],
        "properties": {
          "match": {
            "type": "string",
            "pattern": "^/"
          },
          "uses": {
            "type": "object",
            "minProperties": 1,
            "properties": {
              "search": {
                "$ref": "#/$defs/use"
              },
              "answer": {
                "$ref": "#/$defs/use"
              },
              "training": {
                "$ref": "#/$defs/use"
              },
              "agent": {
                "$ref": "#/$defs/use"
              }
            }
          },
          "payment": {
            "$ref": "#/$defs/payment"
          }
        }
      }
    },
    "identity": {
      "type": "object",
      "properties": {
        "verify": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "unverified": {
          "type": "string",
          "description": "A client that claims an identity and fails the check: treated-as-claimed (the terms for the use its claimed identity is documented for, with no free allowance) or treated-as-unidentified (default applies)."
        }
      }
    },
    "purpose_header": {
      "const": "AI-Purpose"
    },
    "payment": {
      "$ref": "#/$defs/payment"
    },
    "receipts": {
      "type": "string"
    },
    "preview": {
      "type": "object",
      "required": [
        "delivery"
      ],
      "description": "What a client is told about a paid page before paying (in the 402), and whether the payment is settled only when the delivered page matches it.",
      "properties": {
        "shows": {
          "type": "array",
          "items": {
            "enum": [
              "title",
              "description",
              "excerpt",
              "words"
            ]
          }
        },
        "delivery": {
          "enum": [
            "must-match",
            "per-quote",
            "not-checked"
          ]
        },
        "described_quote": {
          "type": "string",
          "description": "Where to ask for a quote that describes the page and is held to it: an RFC 6570 URI Template with one variable, path (the page's path and query, starting with a slash)."
        }
      }
    },
    "report_only": {
      "type": "boolean"
    },
    "contact": {
      "type": "object",
      "properties": {
        "licensing": {
          "type": "string"
        }
      }
    },
    "spec": {
      "type": "string"
    }
  },
  "$defs": {
    "use": {
      "type": "object",
      "required": [
        "access"
      ],
      "properties": {
        "access": {
          "enum": [
            "allow",
            "paid",
            "deny"
          ]
        },
        "price": {
          "type": "object",
          "required": [
            "amount",
            "currency",
            "per"
          ],
          "properties": {
            "amount": {
              "type": "string",
              "pattern": "^(?!0+(\\.0+)?$)\\d+(\\.\\d+)?$",
              "description": "A decimal string greater than zero."
            },
            "currency": {
              "const": "USD"
            },
            "per": {
              "enum": [
                "page",
                "request"
              ]
            }
          }
        },
        "attribution": {
          "enum": [
            "required",
            "requested",
            "none"
          ]
        },
        "free": {
          "type": "object",
          "required": [
            "requests",
            "per"
          ],
          "description": "Free allowance for a paid or denied use: requests per UTC hour or day for a verified client before access applies.",
          "properties": {
            "requests": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000000000
            },
            "per": {
              "enum": [
                "hour",
                "day"
              ]
            }
          }
        }
      }
    },
    "payment": {
      "type": "object",
      "required": [
        "protocol",
        "endpoint"
      ],
      "properties": {
        "protocol": {
          "const": "x402"
        },
        "version": {
          "type": "integer"
        },
        "endpoint": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://[^?#]+$"
        },
        "network": {
          "type": "string"
        },
        "asset": {
          "type": "string"
        }
      }
    }
  }
}