{
  "openapi": "3.1.0",
  "info": {
    "title": "MailPreflight Email QA & Deliverability API",
    "version": "1.0.0",
    "summary": "Catch broken merge tags, Gmail 102KB clipping, Outlook CSS bugs, and spam triggers before your agent hits send.",
    "description": "Deterministic pre-send QA for outbound HTML emails: catches Gmail 102KB clipping, Outlook Word-engine & Gmail CSS incompatibilities, unmerged ESP placeholders, phishing/shortener link triggers, and generates clean plain-text MIME fallbacks at the edge.\n\nReplaces brittle regexes and heavyweight headless browsers with a <15ms deterministic HTML/CSS & deliverability parser covering Outlook Word VML/ghost-table quirks, 6 ESP placeholder syntaxes, phishing host-mismatch checks, and RFC 5322 plain-text conversion.",
    "contact": {
      "name": "API Keg",
      "url": "https://apikeg.com"
    }
  },
  "servers": [
    {
      "url": "https://mail-preflight.apikeg.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Keg Key (ak_live_...)",
        "description": "Optional per-email monthly subscription API key ($5/$20/$50 tiers at https://apikeg.com/account). Omit this header to pay per request inline via HTTP 402 (x402 USDC)."
      }
    }
  },
  "security": [
    {},
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/v1/audit-email-template": {
      "post": {
        "operationId": "audit_email_template",
        "summary": "Audit Outbound Email Template",
        "description": "Runs a full pre-send deliverability, merge-tag, link-hygiene, Gmail 102KB clipping, and cross-client CSS compatibility audit (Outlook Windows, Gmail, Apple Mail Dark Mode) on an HTML email. Why call instead of DIY: Audits 30+ email-client CSS quirks, 6 ESP merge syntaxes, and phishing/spam heuristics in <10ms for $0.003 without maintaining Can-I-Email rulesets. Pricing: $0.003 USD per email template preflight audit (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "marketing-ops",
          "email-deliverability",
          "developer-tools",
          "revops"
        ],
        "externalDocs": {
          "description": "Audit Outbound Email Template Specification & Examples",
          "url": "https://mail-preflight.apikeg.com/tools/audit-email-template"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.003",
          "amountAtomicUnits": "3000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "marketing-ops",
                "email-deliverability",
                "developer-tools",
                "revops"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "subject": "Welcome to Acme, {{first_name}}!",
                    "preheader": "Your workspace is provisioned.",
                    "emailCategory": "marketing",
                    "html": "<!DOCTYPE html><html><head><meta name=\"color-scheme\" content=\"light dark\"></head><body style=\"background-color:#f9fafb;\"><p>Hi there, <a href=\"https://acme.com/start\">Launch Workspace</a> · <a href=\"https://acme.com/unsubscribe\">Unsubscribe</a></p></body></html>"
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Flags unmerged {{first_name}} in subject as blocked with prioritized actionableFixes."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "html": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 900000,
                      "description": "Complete outbound HTML email payload to inspect for Gmail 102KB clipping, Outlook/Gmail/Dark Mode CSS support, link hygiene, and spam triggers."
                    },
                    "subject": {
                      "type": "string",
                      "maxLength": 998,
                      "description": "Optional Subject header evaluated for unmerged placeholders, fake Re:/Fwd: prefixes, ALL-CAPS shouting, and punctuation triggers."
                    },
                    "preheader": {
                      "type": "string",
                      "maxLength": 1000,
                      "description": "Optional preview/preheader snippet checked for unmerged merge tags and spam triggers."
                    },
                    "plainText": {
                      "type": "string",
                      "maxLength": 500000,
                      "description": "Optional text/plain MIME companion body checked for unmerged placeholders and unsubscribe compliance."
                    },
                    "emailCategory": {
                      "type": "string",
                      "enum": [
                        "transactional",
                        "marketing",
                        "cold_outreach"
                      ],
                      "default": "transactional",
                      "description": "Outbound email class controlling compliance rules (marketing and cold_outreach require an unsubscribe mechanism)."
                    }
                  },
                  "required": [
                    "html"
                  ],
                  "additionalProperties": false
                },
                "outputSchema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "_meta"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "description": "Deterministic structured tool result payload."
                    },
                    "_meta": {
                      "type": "object",
                      "required": [
                        "requestId",
                        "durationMs",
                        "chargedUsd",
                        "dryRun"
                      ],
                      "properties": {
                        "requestId": {
                          "type": "string"
                        },
                        "durationMs": {
                          "type": "number"
                        },
                        "chargedUsd": {
                          "type": "string"
                        },
                        "dryRun": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "dry_run",
            "in": "query",
            "required": false,
            "description": "Validate request schema for free ($0.00) without executing or settling payment.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "html": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 900000,
                    "description": "Complete outbound HTML email payload to inspect for Gmail 102KB clipping, Outlook/Gmail/Dark Mode CSS support, link hygiene, and spam triggers."
                  },
                  "subject": {
                    "type": "string",
                    "maxLength": 998,
                    "description": "Optional Subject header evaluated for unmerged placeholders, fake Re:/Fwd: prefixes, ALL-CAPS shouting, and punctuation triggers."
                  },
                  "preheader": {
                    "type": "string",
                    "maxLength": 1000,
                    "description": "Optional preview/preheader snippet checked for unmerged merge tags and spam triggers."
                  },
                  "plainText": {
                    "type": "string",
                    "maxLength": 500000,
                    "description": "Optional text/plain MIME companion body checked for unmerged placeholders and unsubscribe compliance."
                  },
                  "emailCategory": {
                    "type": "string",
                    "enum": [
                      "transactional",
                      "marketing",
                      "cold_outreach"
                    ],
                    "default": "transactional",
                    "description": "Outbound email class controlling compliance rules (marketing and cold_outreach require an unsubscribe mechanism)."
                  }
                },
                "required": [
                  "html"
                ],
                "additionalProperties": false
              },
              "example": {
                "subject": "Welcome to Acme, {{first_name}}!",
                "preheader": "Your workspace is provisioned.",
                "emailCategory": "marketing",
                "html": "<!DOCTYPE html><html><head><meta name=\"color-scheme\" content=\"light dark\"></head><body style=\"background-color:#f9fafb;\"><p>Hi there, <a href=\"https://acme.com/start\">Launch Workspace</a> · <a href=\"https://acme.com/unsubscribe\">Unsubscribe</a></p></body></html>"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful execution result.",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64-encoded x402 v2 payment settlement receipt (when paid).",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object"
                    },
                    "_meta": {
                      "type": "object",
                      "properties": {
                        "requestId": {
                          "type": "string"
                        },
                        "durationMs": {
                          "type": "number"
                        },
                        "chargedUsd": {
                          "type": "string"
                        },
                        "dryRun": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Schema validation error (unbilled, $0.00)."
          },
          "402": {
            "description": "Payment Required. Decode the Base64 PAYMENT-REQUIRED header and retry with PAYMENT-SIGNATURE.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 PaymentRequired JSON object.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/extract-plain-text-fallback": {
      "post": {
        "operationId": "extract_plain_text_fallback",
        "summary": "Extract Plain-Text MIME Fallback",
        "description": "Converts an HTML email into a clean, RFC 5322-wrapped text/plain MIME companion, preserving CTA links inline as 'Label (https://...)' and stripping invisible &#847; / &zwnj; preheader padding hacks. Why call instead of DIY: Strips email-specific &zwnj;/&#847; preheader spacers and formats multi-column/CTA HTML cleanly in <5ms for $0.001 instead of naive strip-tags regexes. Pricing: $0.001 USD per HTML-to-plain-text MIME fallback conversion (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "marketing-ops",
          "email-deliverability",
          "developer-tools",
          "revops"
        ],
        "externalDocs": {
          "description": "Extract Plain-Text MIME Fallback Specification & Examples",
          "url": "https://mail-preflight.apikeg.com/tools/extract-plain-text-fallback"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.001",
          "amountAtomicUnits": "1000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "marketing-ops",
                "email-deliverability",
                "developer-tools",
                "revops"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "html": "<div>Preview text &zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;</div><h1>Payment Received</h1><p>View your invoice: <a href=\"https://acme.com/inv/42\">Download PDF</a></p>",
                    "wrapWidth": 78
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Returns clean wrapped text with 'Download PDF (https://acme.com/inv/42)' and zero invisible spacer characters."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "html": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 900000,
                      "description": "HTML email body to convert into a formatted text/plain MIME fallback with inline CTA URLs and stripped preheader padding."
                    },
                    "wrapWidth": {
                      "type": "integer",
                      "minimum": 40,
                      "maximum": 120,
                      "default": 78,
                      "description": "Soft line-wrap width in characters (default 78 per RFC 5322; URLs are never split)."
                    }
                  },
                  "required": [
                    "html"
                  ],
                  "additionalProperties": false
                },
                "outputSchema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "data",
                    "_meta"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "description": "Deterministic structured tool result payload."
                    },
                    "_meta": {
                      "type": "object",
                      "required": [
                        "requestId",
                        "durationMs",
                        "chargedUsd",
                        "dryRun"
                      ],
                      "properties": {
                        "requestId": {
                          "type": "string"
                        },
                        "durationMs": {
                          "type": "number"
                        },
                        "chargedUsd": {
                          "type": "string"
                        },
                        "dryRun": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "dry_run",
            "in": "query",
            "required": false,
            "description": "Validate request schema for free ($0.00) without executing or settling payment.",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "html": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 900000,
                    "description": "HTML email body to convert into a formatted text/plain MIME fallback with inline CTA URLs and stripped preheader padding."
                  },
                  "wrapWidth": {
                    "type": "integer",
                    "minimum": 40,
                    "maximum": 120,
                    "default": 78,
                    "description": "Soft line-wrap width in characters (default 78 per RFC 5322; URLs are never split)."
                  }
                },
                "required": [
                  "html"
                ],
                "additionalProperties": false
              },
              "example": {
                "html": "<div>Preview text &zwnj;&nbsp;&#847;&zwnj;&nbsp;&#847;</div><h1>Payment Received</h1><p>View your invoice: <a href=\"https://acme.com/inv/42\">Download PDF</a></p>",
                "wrapWidth": 78
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful execution result.",
            "headers": {
              "PAYMENT-RESPONSE": {
                "description": "Base64-encoded x402 v2 payment settlement receipt (when paid).",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "data": {
                      "type": "object"
                    },
                    "_meta": {
                      "type": "object",
                      "properties": {
                        "requestId": {
                          "type": "string"
                        },
                        "durationMs": {
                          "type": "number"
                        },
                        "chargedUsd": {
                          "type": "string"
                        },
                        "dryRun": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Schema validation error (unbilled, $0.00)."
          },
          "402": {
            "description": "Payment Required. Decode the Base64 PAYMENT-REQUIRED header and retry with PAYMENT-SIGNATURE.",
            "headers": {
              "PAYMENT-REQUIRED": {
                "description": "Base64-encoded x402 v2 PaymentRequired JSON object.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}