{
  "openapi": "3.1.0",
  "info": {
    "title": "Precleared API",
    "version": "1.0.0",
    "description": "Per-address verdicts on cold marketing email, with the rule quoted and a signed receipt. Decision support with sources, not legal advice."
  },
  "servers": [
    {
      "url": "https://precleared.dev"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Optional API key, pc_live_..."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "CheckRequest": {
        "type": "object",
        "properties": {
          "recipient_email": {
            "type": "string"
          },
          "recipient_domain": {
            "type": "string"
          },
          "sender_country": {
            "type": "string",
            "enum": [
              "GB",
              "US"
            ],
            "default": "GB"
          },
          "pitch": {
            "type": "string"
          },
          "address_source": {
            "type": "string",
            "enum": [
              "published",
              "bought",
              "scraped",
              "given",
              "unknown"
            ],
            "default": "published"
          },
          "recipient_country": {
            "type": "string",
            "pattern": "^[A-Za-z]{2}$"
          },
          "company_number": {
            "type": "string"
          },
          "pitch_relevant": {
            "type": "boolean"
          },
          "existing_customer": {
            "type": "boolean",
            "default": false
          },
          "suppressed": {
            "type": "boolean"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "created_at": {
            "type": "string"
          },
          "request_hash": {
            "type": "string"
          },
          "response_hash": {
            "type": "string"
          },
          "signature": {
            "type": "string"
          },
          "algorithm": {
            "type": "string"
          },
          "key_version": {
            "type": "string"
          },
          "verify_url": {
            "type": "string"
          }
        }
      },
      "CheckResponse": {
        "type": "object",
        "properties": {
          "verdict": {
            "type": "string",
            "enum": [
              "ok_to_email",
              "consent_needed",
              "blocked",
              "unknown"
            ]
          },
          "confidence": {
            "type": "string",
            "enum": [
              "high",
              "medium",
              "low"
            ]
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "rules_applied": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "footer_text": {
            "type": [
              "string",
              "null"
            ]
          },
          "next_step": {
            "type": [
              "string",
              "null"
            ]
          },
          "facts": {
            "type": "object"
          },
          "receipt": {
            "$ref": "#/components/schemas/Receipt"
          },
          "rules_version": {
            "type": "string"
          },
          "usage": {
            "type": "object",
            "properties": {
              "free_remaining_today": {
                "type": "integer"
              },
              "credits_remaining": {
                "type": "integer"
              }
            }
          },
          "disclaimer": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/check": {
      "post": {
        "summary": "Check one address",
        "security": [
          {},
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verdict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked key"
          },
          "402": {
            "description": "No free checks or credits left"
          },
          "429": {
            "description": "Daily limit reached"
          }
        }
      }
    },
    "/api/v1/receipt": {
      "get": {
        "summary": "Read a receipt",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^cc_rcpt_[0-9A-Z]{16}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/v1/public-key": {
      "get": {
        "summary": "Receipt signing public key",
        "responses": {
          "200": {
            "description": "key_version and base64 SPKI DER public_key"
          }
        }
      }
    },
    "/api/v1/rules": {
      "get": {
        "summary": "Active rules",
        "responses": {
          "200": {
            "description": "Rules ordered by priority"
          }
        }
      }
    }
  }
}