{
  "openapi": "3.0.3",
  "info": {
    "title": "checkmails REST API",
    "version": "1.0.0",
    "description": "Public REST API for verifying email addresses via SMTP. Authentication uses Bearer tokens. Each verified email costs 1 credit. An MCP server is also available at https://checkmails.eu/api/mcp (connect guide: https://checkmails.eu/mcp).",
    "contact": {
      "name": "checkmails support",
      "url": "https://checkmails.eu"
    }
  },
  "servers": [
    {
      "url": "https://checkmails.eu",
      "description": "Production"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "chk_<32hex>"
      }
    },
    "schemas": {
      "Result": {
        "type": "object",
        "properties": {
          "email":      { "type": "string", "format": "email" },
          "valid":      { "type": "boolean", "description": "true ssi verdict == 'valid' (champ conservé pour compatibilité, lire verdict pour 3 états)" },
          "verdict":    { "type": "string", "enum": ["valid", "invalid", "indeterminate"], "description": "Verdict canonique à 3 états. 'indeterminate' signifie qu'aucune réponse définitive n'a pu être obtenue (4xx persistant, 421, greylist, proxy indisponible…). Ne PAS envoyer en froid sur 'indeterminate'." },
          "blocked":    { "type": "boolean" },
          "reason":     { "type": "string" },
          "mx_host":    { "type": "string" },
          "smtp_code":  { "type": "integer" },
          "flags":      { "type": "array", "items": { "type": "string" } },
          "risk_score": { "type": "integer", "minimum": 0, "maximum": 100 }
        },
        "required": ["email", "valid", "reason"]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error":   { "type": "string", "description": "Machine-readable error code" },
          "message": { "type": "string", "description": "Human-readable explanation" }
        },
        "required": ["error", "message"]
      }
    }
  },
  "security": [
    { "BearerAuth": [] }
  ],
  "paths": {
    "/api/v1/verify": {
      "post": {
        "summary": "Verify a single email synchronously",
        "description": "Returns an enriched Result blocking until the SMTP probe completes. Costs 1 credit on success.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "email": { "type": "string", "format": "email" } },
                "required": ["email"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Verification result",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Result" } } }
          },
          "400": { "description": "Invalid email or body", "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": "Insufficient credits", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Rate limit exceeded (60/min/api-key)" }
        }
      }
    },
    "/api/v1/bulk": {
      "post": {
        "summary": "Verify a batch of emails asynchronously",
        "description": "Returns 202 with a job_id. Poll /api/v1/jobs/{id} until done=true. Max 1000 emails per call. Credits deducted upfront for syntactically valid emails.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "emails": {
                    "type": "array",
                    "items": { "type": "string", "format": "email" },
                    "maxItems": 1000
                  }
                },
                "required": ["emails"]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "job_id": { "type": "string" },
                    "count":  { "type": "integer" },
                    "status": { "type": "string", "enum": ["processing"] },
                    "poll":   { "type": "string" }
                  }
                }
              }
            }
          },
          "400": { "description": "Empty array, too many emails, or all syntactically invalid" },
          "401": { "description": "Missing or invalid API key" },
          "402": { "description": "Insufficient credits" },
          "429": { "description": "Rate limit exceeded (10/min/api-key)" }
        }
      }
    },
    "/api/v1/jobs/{id}": {
      "get": {
        "summary": "Get the status of a bulk job",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Job status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "job_id":    { "type": "string" },
                    "total":     { "type": "integer" },
                    "processed": { "type": "integer" },
                    "done":      { "type": "boolean" },
                    "results":   { "type": "array", "items": { "$ref": "#/components/schemas/Result" } }
                  }
                }
              }
            }
          },
          "400": { "description": "Missing job ID" },
          "401": { "description": "Missing or invalid API key" },
          "403": { "description": "Job belongs to another account" },
          "404": { "description": "Job not found" }
        }
      }
    }
  },
  "externalDocs": { "description": "Docs & MCP", "url": "https://checkmails.eu/docs" }
}
