{
  "openapi": "3.1.0",
  "info": {
    "title": "ProbeMX Email Verification API",
    "version": "0.1.0",
    "description": "High-throughput email verification API with live SMTP/STARTTLS, cross-row catch-all pattern scoring, explainable score_factors, zero-retention privacy, signed webhooks, credits, and Mailgun/AWS SES feedback loops."
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": { "type": "http", "scheme": "bearer" },
      "ApiKeyHeader": { "type": "apiKey", "in": "header", "name": "X-API-Key" }
    },
    "schemas": {
      "VerifyRequest": {
        "type": "object",
        "required": ["email"],
        "properties": {
          "email": { "type": "string", "format": "email" },
          "timeout_ms": { "type": "integer", "minimum": 50, "maximum": 30000, "default": 15000 },
          "skip_smtp": { "type": "boolean", "default": false },
          "skip_catch_all": { "type": "boolean", "default": false },
          "bypass_cache": { "type": "boolean", "default": false },
          "zero_retention": { "type": "boolean", "default": false }
        }
      },
      "ScoreFactor": {
        "type": "object",
        "required": ["signal", "delta", "detail"],
        "properties": {
          "signal": { "type": "string" },
          "delta": { "type": "integer" },
          "detail": { "type": "string" }
        }
      },
      "VerificationResult": {
        "type": "object",
        "properties": {
          "email": { "type": "string" },
          "normalized_email": { "type": ["string", "null"] },
          "canonical_email": { "type": ["string", "null"] },
          "state": { "type": "string", "enum": ["deliverable", "undeliverable", "risky", "unknown"] },
          "reason": { "type": "string" },
          "score": { "type": "integer", "minimum": 0, "maximum": 100 },
          "score_factors": { "type": "array", "items": { "$ref": "#/components/schemas/ScoreFactor" } },
          "catch_all_confidence": { "type": ["integer", "null"] },
          "did_you_mean": { "type": ["string", "null"] },
          "cached": { "type": "boolean" },
          "duration_ms": { "type": "integer" },
          "verified_at": { "type": "string", "format": "date-time" }
        }
      },
      "BulkCreateRequest": {
        "type": "object",
        "required": ["emails"],
        "properties": {
          "emails": { "type": "array", "items": { "type": "string" } },
          "webhook_url": { "type": ["string", "null"], "format": "uri" },
          "dedupe_aliases": { "type": "boolean", "default": false },
          "zero_retention": { "type": "boolean", "default": false }
        }
      },
      "BulkJob": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "status": { "type": "string", "enum": ["queued", "running", "completed", "failed", "cancelled"] },
          "total_submitted": { "type": "integer" },
          "unique_count": { "type": "integer" },
          "processed_count": { "type": "integer" },
          "deliverable_count": { "type": "integer" },
          "undeliverable_count": { "type": "integer" },
          "risky_count": { "type": "integer" },
          "unknown_count": { "type": "integer" },
          "progress_percent": { "type": "number" },
          "zero_retention": { "type": "boolean" },
          "webhook_status": { "type": "string" }
        }
      },
      "SyncBatchRequest": {
        "type": "object",
        "required": ["emails"],
        "properties": {
          "emails": { "type": "array", "maxItems": 50, "items": { "type": "string" } },
          "timeout_ms": { "type": "integer", "minimum": 50, "maximum": 30000, "default": 15000 },
          "skip_smtp": { "type": "boolean", "default": false },
          "skip_catch_all": { "type": "boolean", "default": false },
          "bypass_cache": { "type": "boolean", "default": false },
          "zero_retention": { "type": "boolean", "default": false }
        }
      },
      "CreditBalanceResponse": {
        "type": "object",
        "properties": {
          "mode": { "type": "string", "enum": ["metered", "unlimited_static_key"] },
          "balance": { "type": ["integer", "null"] },
          "refund_unknowns": { "type": "boolean" },
          "ledger": { "type": "array", "items": { "type": "object" } }
        }
      },
      "FeedbackEvent": {
        "type": "object",
        "required": ["email", "event"],
        "properties": {
          "email": { "type": "string", "format": "email" },
          "event": { "type": "string", "enum": ["delivered", "hard_bounce", "soft_bounce", "complaint"] },
          "smtp_code": { "type": ["integer", "null"] },
          "enhanced_code": { "type": ["string", "null"] },
          "diagnostic": { "type": ["string", "null"] }
        }
      },
      "FeedbackRequest": {
        "type": "object",
        "required": ["events"],
        "properties": {
          "events": { "type": "array", "maxItems": 5000, "items": { "$ref": "#/components/schemas/FeedbackEvent" } }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error", "message"],
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" }
        }
      }
    }
  },
  "security": [{ "BearerAuth": [] }, { "ApiKeyHeader": [] }],
  "paths": {
    "/v1/verify": {
      "post": {
        "summary": "Verify a single email address",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VerifyRequest" } } }
        },
        "responses": {
          "200": { "description": "Verification result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/VerificationResult" } } } },
          "402": { "description": "Insufficient credits", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/v1/verify/batch": {
      "post": {
        "summary": "Synchronously verify up to 50 emails (MX-grouped session multiplexing)",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/SyncBatchRequest" } } }
        },
        "responses": { "200": { "description": "Ordered batch results" }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/bulk": {
      "get": { "summary": "List recent bulk jobs for authenticated tenant", "responses": { "200": { "description": "Bulk job list" } } },
      "post": {
        "summary": "Create async bulk verification job (JSON or text/csv)",
        "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BulkCreateRequest" } } } },
        "responses": { "202": { "description": "Job queued", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BulkJob" } } } }, "402": { "description": "Insufficient credits" } }
      }
    },
    "/v1/bulk/upload": {
      "post": { "summary": "Upload CSV file via multipart/form-data", "responses": { "202": { "description": "Job queued" }, "402": { "description": "Insufficient credits" } } }
    },
    "/v1/bulk/{job_id}": {
      "get": { "summary": "Get bulk job status & live streaming progress", "responses": { "200": { "description": "Job status" } } },
      "delete": { "summary": "Cancel running/queued bulk job and refund unused credits", "responses": { "200": { "description": "Cancelled" } } }
    },
    "/v1/bulk/{job_id}/results": {
      "get": { "summary": "Fetch paginated JSON or download full CSV results", "responses": { "200": { "description": "Results" } } }
    },
    "/v1/bulk/{job_id}/purge": {
      "delete": { "summary": "Immediately purge all email PII rows for a job", "responses": { "200": { "description": "Purged" } } }
    },
    "/v1/credits": {
      "get": {
        "summary": "Get credit balance and immutable ledger",
        "responses": {
          "200": { "description": "Credit balance & ledger", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreditBalanceResponse" } } } }
        }
      }
    },
    "/v1/feedback": {
      "post": {
        "summary": "Ingest generic mailer delivery/bounce feedback events",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/FeedbackRequest" } } }
        },
        "responses": { "200": { "description": "Ingest summary" } }
      }
    },
    "/v1/feedback/mailgun": {
      "post": { "summary": "Native Mailgun webhook receiver", "responses": { "200": { "description": "Ingest summary" } } }
    },
    "/v1/feedback/ses": {
      "post": { "summary": "Native AWS SES / SNS webhook receiver", "responses": { "200": { "description": "Ingest summary" } } }
    },
    "/v1/compat/emailable/verify": {
      "get": { "summary": "Drop-in Emailable response compatibility adapter", "responses": { "200": { "description": "Emailable-formatted response" } } }
    },
    "/v1/compat/hunter/email-verifier": {
      "get": { "summary": "Drop-in Hunter response compatibility adapter", "responses": { "200": { "description": "Hunter-formatted response" } } }
    },
    "/v1/egress/health": {
      "get": { "summary": "Inspect per-(egress, provider) IP reputation circuit breakers", "responses": { "200": { "description": "Egress health snapshot" } } }
    }
  }
}
