{
  "openapi": "3.1.0",
  "info": {
    "title": "PDF Forge & Layout Diagnostics Edge API",
    "version": "1.0.0",
    "summary": "Compile Markdown or HTML into polished multi-page PDF 1.7 documents with orphan-page & wide-table diagnostics in <20ms.",
    "description": "Zero-dependency Markdown & HTML to spec-compliant PDF 1.7 compiler with corporate themes ('executive', 'invoice', 'technical', 'memo'), multi-page table header continuation, diagonal watermarks, deterministic layout diagnostics (orphan pages, wide tables, broken images), and binary PDF inspection.\n\nEliminates heavyweight headless Chromium containers, broken PDF byte-offset xref tables, clipped wide tables, and embarrassing 2-line trailing orphan pages before delivering client-facing PDFs.",
    "contact": {
      "name": "API Keg",
      "url": "https://apikeg.com"
    }
  },
  "servers": [
    {
      "url": "https://pdf-forge.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/render-document-pdf": {
      "post": {
        "operationId": "render_document_pdf",
        "summary": "Render Markdown or HTML Document to Themed PDF",
        "description": "Compiles Markdown (headings, bold/italic/code, lists, GFM tables, callouts, '---pagebreak---') or HTML into both print-ready themed HTML and a spec-compliant multi-page PDF 1.7 binary with running headers, 'Page X of Y' footers, repeated table headers across page breaks, optional watermark, and deterministic layoutDiagnostics. Why call instead of DIY: Avoids spinning up 400MB Puppeteer/Playwright containers or hand-rolling brittle PDF stream/xref math; returns both binary PDF and layout QA diagnostics in <20ms at $0.004. Pricing: $0.004 USD per rendered PDF document (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "document-generation",
          "reporting",
          "business-ops",
          "developer-tools"
        ],
        "externalDocs": {
          "description": "Render Markdown or HTML Document to Themed PDF Specification & Examples",
          "url": "https://pdf-forge.apikeg.com/tools/render-document-pdf"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.004",
          "amountAtomicUnits": "4000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "document-generation",
                "reporting",
                "business-ops",
                "developer-tools"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "title": "Q4 Cloud FinOps Executive Summary",
                    "subtitle": "Quarterly Infrastructure Margin & Savings Audit",
                    "author": "Platform FinOps Team",
                    "theme": "executive",
                    "pageSize": "Letter",
                    "orientation": "portrait",
                    "contentFormat": "markdown",
                    "headerText": "ACME CORP — Q4 FINOPS AUDIT",
                    "includePageNumbers": true,
                    "watermarkText": "CONFIDENTIAL",
                    "content": "## Highlights\n\nNet cloud margin improved **420 bps** quarter-over-quarter.\n\n| Service | Q3 Spend | Q4 Spend | Delta |\n| --- | ---: | ---: | ---: |\n| Compute | $142,000 | $118,500 | -16.5% |\n| Storage | $38,400 | $35,100 | -8.6% |\n\n> [!NOTE]\n> Reserved capacity commitments lock in an additional $95k annualized savings."
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Base64 PDF 1.7 binary, print-ready themed HTML, byteLength, and layoutDiagnostics (pageCount, lastPageFillRatio, wideTableWarnings, estimatedReadingMinutes)."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "content": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 524288,
                      "description": "Markdown (headings, bold/italic/code, lists, GFM tables, callouts, '---pagebreak---') or raw HTML body to compile."
                    },
                    "contentFormat": {
                      "type": "string",
                      "enum": [
                        "markdown",
                        "html"
                      ],
                      "default": "markdown",
                      "description": "Input syntax format ('markdown' or 'html')."
                    },
                    "title": {
                      "type": "string",
                      "maxLength": 240,
                      "description": "Optional document title rendered in the cover banner and stored in PDF /Title metadata."
                    },
                    "subtitle": {
                      "type": "string",
                      "maxLength": 320,
                      "description": "Optional subtitle rendered below the title and stored in PDF /Subject metadata."
                    },
                    "author": {
                      "type": "string",
                      "maxLength": 160,
                      "description": "Optional author or organization name rendered in the cover banner and PDF /Author metadata."
                    },
                    "theme": {
                      "type": "string",
                      "enum": [
                        "executive",
                        "invoice",
                        "technical",
                        "memo"
                      ],
                      "default": "executive",
                      "description": "Corporate print styling theme ('executive', 'invoice', 'technical', or 'memo')."
                    },
                    "pageSize": {
                      "type": "string",
                      "enum": [
                        "Letter",
                        "A4",
                        "Legal"
                      ],
                      "default": "Letter",
                      "description": "Paper size ('Letter', 'A4', or 'Legal')."
                    },
                    "orientation": {
                      "type": "string",
                      "enum": [
                        "portrait",
                        "landscape"
                      ],
                      "default": "portrait",
                      "description": "Page orientation ('portrait' or 'landscape')."
                    },
                    "headerText": {
                      "type": "string",
                      "maxLength": 180,
                      "description": "Optional running header stamped at the top margin of every page."
                    },
                    "includePageNumbers": {
                      "type": "boolean",
                      "default": true,
                      "description": "Include 'Page X of Y' running footers on every page."
                    },
                    "watermarkText": {
                      "type": "string",
                      "maxLength": 80,
                      "description": "Optional diagonal watermark text rendered across every page (e.g. 'CONFIDENTIAL' or 'DRAFT')."
                    }
                  },
                  "required": [
                    "content"
                  ],
                  "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": {
                  "content": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 524288,
                    "description": "Markdown (headings, bold/italic/code, lists, GFM tables, callouts, '---pagebreak---') or raw HTML body to compile."
                  },
                  "contentFormat": {
                    "type": "string",
                    "enum": [
                      "markdown",
                      "html"
                    ],
                    "default": "markdown",
                    "description": "Input syntax format ('markdown' or 'html')."
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 240,
                    "description": "Optional document title rendered in the cover banner and stored in PDF /Title metadata."
                  },
                  "subtitle": {
                    "type": "string",
                    "maxLength": 320,
                    "description": "Optional subtitle rendered below the title and stored in PDF /Subject metadata."
                  },
                  "author": {
                    "type": "string",
                    "maxLength": 160,
                    "description": "Optional author or organization name rendered in the cover banner and PDF /Author metadata."
                  },
                  "theme": {
                    "type": "string",
                    "enum": [
                      "executive",
                      "invoice",
                      "technical",
                      "memo"
                    ],
                    "default": "executive",
                    "description": "Corporate print styling theme ('executive', 'invoice', 'technical', or 'memo')."
                  },
                  "pageSize": {
                    "type": "string",
                    "enum": [
                      "Letter",
                      "A4",
                      "Legal"
                    ],
                    "default": "Letter",
                    "description": "Paper size ('Letter', 'A4', or 'Legal')."
                  },
                  "orientation": {
                    "type": "string",
                    "enum": [
                      "portrait",
                      "landscape"
                    ],
                    "default": "portrait",
                    "description": "Page orientation ('portrait' or 'landscape')."
                  },
                  "headerText": {
                    "type": "string",
                    "maxLength": 180,
                    "description": "Optional running header stamped at the top margin of every page."
                  },
                  "includePageNumbers": {
                    "type": "boolean",
                    "default": true,
                    "description": "Include 'Page X of Y' running footers on every page."
                  },
                  "watermarkText": {
                    "type": "string",
                    "maxLength": 80,
                    "description": "Optional diagonal watermark text rendered across every page (e.g. 'CONFIDENTIAL' or 'DRAFT')."
                  }
                },
                "required": [
                  "content"
                ],
                "additionalProperties": false
              },
              "example": {
                "title": "Q4 Cloud FinOps Executive Summary",
                "subtitle": "Quarterly Infrastructure Margin & Savings Audit",
                "author": "Platform FinOps Team",
                "theme": "executive",
                "pageSize": "Letter",
                "orientation": "portrait",
                "contentFormat": "markdown",
                "headerText": "ACME CORP — Q4 FINOPS AUDIT",
                "includePageNumbers": true,
                "watermarkText": "CONFIDENTIAL",
                "content": "## Highlights\n\nNet cloud margin improved **420 bps** quarter-over-quarter.\n\n| Service | Q3 Spend | Q4 Spend | Delta |\n| --- | ---: | ---: | ---: |\n| Compute | $142,000 | $118,500 | -16.5% |\n| Storage | $38,400 | $35,100 | -8.6% |\n\n> [!NOTE]\n> Reserved capacity commitments lock in an additional $95k annualized savings."
              }
            }
          }
        },
        "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/inspect-pdf-document": {
      "post": {
        "operationId": "inspect_pdf_document",
        "summary": "Inspect Binary PDF Structure & Metadata",
        "description": "Parses a Base64-encoded PDF binary to verify %PDF header/EOF integrity and extract pdfVersion, exact pageCount, byteLength, encryption status, AcroForm presence, and Info dictionary metadata. Why call instead of DIY: Instant deterministic PDF preflight without installing native poppler/pdfinfo binaries; $0.001 per check. Pricing: $0.001 USD per PDF binary inspection (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "document-generation",
          "reporting",
          "business-ops",
          "developer-tools"
        ],
        "externalDocs": {
          "description": "Inspect Binary PDF Structure & Metadata Specification & Examples",
          "url": "https://pdf-forge.apikeg.com/tools/inspect-pdf-document"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.001",
          "amountAtomicUnits": "1000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "document-generation",
                "reporting",
                "business-ops",
                "developer-tools"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "pdfBase64": "JVBERi0xLjcK..."
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "validPdf=true, pdfVersion='1.7', pageCount, byteLength, encrypted=false, hasAcroForm=false, and metadata."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "pdfBase64": {
                      "type": "string",
                      "minLength": 8,
                      "maxLength": 5242880,
                      "description": "Base64-encoded PDF binary (standard or URL-safe Base64, optional 'data:application/pdf;base64,' prefix)."
                    }
                  },
                  "required": [
                    "pdfBase64"
                  ],
                  "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": {
                  "pdfBase64": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 5242880,
                    "description": "Base64-encoded PDF binary (standard or URL-safe Base64, optional 'data:application/pdf;base64,' prefix)."
                  }
                },
                "required": [
                  "pdfBase64"
                ],
                "additionalProperties": false
              },
              "example": {
                "pdfBase64": "JVBERi0xLjcK..."
              }
            }
          }
        },
        "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"
                }
              }
            }
          }
        }
      }
    }
  }
}