{
  "openapi": "3.1.0",
  "info": {
    "title": "Clearance API",
    "version": "1.1.0",
    "description": "Automated risk screening of wording patterns against publicly available UK advertising rules. Not legal advice; not a compliance determination; absence of flags is not clearance. Clearance is not affiliated with the ASA or CAP."
  },
  "servers": [
    {
      "url": "https://clearancecheck.co.uk/api/public/v1"
    }
  ],
  "paths": {
    "/check": {
      "post": {
        "summary": "Screen UK ad copy against the CAP Code rule database.",
        "security": [
          {
            "bearerAuth": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Check result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Quota reached or x402 payment required. When x402 is enabled and no key is supplied, the response body is the x402 accepts payload.",
            "content": {
              "application/json": {}
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rules": {
      "get": {
        "summary": "Rule catalogue (id, severity, citation, title, why, fix). No regex patterns.",
        "responses": {
          "200": {
            "description": "Catalogue."
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Liveness check + engine version.",
        "responses": {
          "200": {
            "description": "OK."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "clr_live_..."
      }
    },
    "schemas": {
      "CheckRequest": {
        "type": "object",
        "required": [
          "copy"
        ],
        "properties": {
          "copy": {
            "type": "string",
            "maxLength": 20000
          },
          "sector": {
            "type": "string",
            "enum": [
              "general",
              "health",
              "food",
              "alcohol",
              "gambling",
              "finance",
              "green",
              "kids",
              "motoring",
              "employment"
            ],
            "default": "general"
          },
          "channel": {
            "type": "string",
            "enum": [
              "paidsocial",
              "influencer",
              "search",
              "display",
              "email",
              "ooh",
              "web"
            ],
            "default": "paidsocial"
          }
        }
      },
      "Flag": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "high",
              "med",
              "low"
            ]
          },
          "citation": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "matches": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "why": {
            "type": "string"
          },
          "fix": {
            "type": "string"
          }
        }
      },
      "CheckResponse": {
        "type": "object",
        "properties": {
          "verdict": {
            "type": "object",
            "properties": {
              "level": {
                "type": "string",
                "enum": [
                  "green",
                  "amber",
                  "red"
                ]
              },
              "stamp": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "summary": {
                "type": "string"
              }
            }
          },
          "score": {
            "type": "integer"
          },
          "counts": {
            "type": "object",
            "properties": {
              "flags": {
                "type": "integer"
              },
              "high": {
                "type": "integer"
              },
              "med": {
                "type": "integer"
              },
              "low": {
                "type": "integer"
              }
            }
          },
          "flags": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Flag"
            }
          },
          "watchouts": {
            "type": "object",
            "properties": {
              "sector": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "channel": {
                "type": "string"
              }
            }
          },
          "meta": {
            "type": "object",
            "required": [
              "engine_version",
              "checked_at",
              "disclaimer"
            ],
            "properties": {
              "engine_version": {
                "type": "string"
              },
              "checked_at": {
                "type": "string",
                "format": "date-time"
              },
              "disclaimer": {
                "type": "string"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "invalid_request",
                  "unauthorized",
                  "payment_required",
                  "rate_limited",
                  "server_error"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}