{
  "openapi": "3.1.0",
  "info": {
    "title": "Office OOXML Template Merge & Markdown Extractor API",
    "version": "1.0.0",
    "summary": "Brand-safe .docx/.pptx template merging (fixing Word split XML runs & table loops) and 85%+ token-saving .docx/.pptx/.xlsx Markdown extraction.",
    "description": "Zero-dependency Cloudflare Edge OOXML engine that merges .docx and .pptx templates (healing split XML runs, preserving run/cell styles, and expanding repeating table rows) and extracts .docx, .pptx, and .xlsx files into token-minimal Markdown.\n\nTyping {{customer_name}} in Word or PowerPoint shatters placeholders across multiple <w:r>/<a:r> runs with <w:proofErr/> tags, breaking naive regex scripts and corrupting PKZIP CRC32 headers. This API heals split runs, clones styled table rows, and extracts clean Markdown in milliseconds.",
    "contact": {
      "name": "API Keg",
      "url": "https://apikeg.com"
    }
  },
  "servers": [
    {
      "url": "https://office-template.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/merge-office-template": {
      "post": {
        "operationId": "merge_office_template",
        "summary": "Merge .docx or .pptx Office Template",
        "description": "Coalesces split {{variable}} runs across Word (<w:r>) and PowerPoint (<a:r>) paragraphs while preserving opening-run typography, expands {{#loop}}...{{/loop}} table rows, replaces variables across body/headers/footers/slides, and returns a valid PKZIP Base64 document plus any unmatchedPlaceholders. Why call instead of DIY: Eliminates broken {{tags}} caused by Word/PowerPoint spellcheck run-splitting, <a:br/> vs <w:br/> schema errors, and corrupt PKZIP Central Directory CRCs. Pricing: $0.004 USD per Office template merge (.docx or .pptx) (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "document-automation",
          "office-ooxml",
          "context-compression",
          "business-ops"
        ],
        "externalDocs": {
          "description": "Merge .docx or .pptx Office Template Specification & Examples",
          "url": "https://office-template.apikeg.com/tools/merge-office-template"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.004",
          "amountAtomicUnits": "4000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "document-automation",
                "office-ooxml",
                "context-compression",
                "business-ops"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "fileBase64": "UEsDBBQAAAAIA...",
                    "format": "docx",
                    "variables": {
                      "customer_name": "Acme Robotics, Inc.",
                      "billing_address": "500 Market St\nSuite 1200\nSan Francisco, CA",
                      "contract_id": "MSA-2026-089"
                    },
                    "tableLoops": {
                      "items": [
                        {
                          "sku": "ENT-SEAT",
                          "description": "Enterprise Agent Seat",
                          "qty": 25,
                          "total": "$2,500"
                        },
                        {
                          "sku": "DED-EDGE",
                          "description": "Dedicated Edge Worker",
                          "qty": 1,
                          "total": "$500"
                        }
                      ]
                    }
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Returns merged .docx Base64 bytes, replacementsCount=11, and unmatchedPlaceholders=[] ready to open in Microsoft Word."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "fileBase64": {
                      "type": "string",
                      "minLength": 16,
                      "description": "Base64-encoded .docx or .pptx OOXML template file (accepts raw Base64 or data:...;base64, URI)."
                    },
                    "format": {
                      "type": "string",
                      "enum": [
                        "auto",
                        "docx",
                        "pptx"
                      ],
                      "default": "auto",
                      "description": "Template format ('auto' inspects internal OOXML ZIP entries)."
                    },
                    "variables": {
                      "type": "object",
                      "additionalProperties": {
                        "description": "Scalar replacement value (string, finite number, or boolean)."
                      },
                      "description": "Key-value map for {{placeholder}} variables across body, headers, footers, and slides. Multi-line '\\n' values expand to <w:br/> / <a:br/>."
                    },
                    "tableLoops": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "additionalProperties": {
                            "description": "Scalar replacement value (string, finite number, or boolean)."
                          },
                          "description": "Per-row variable map merged into the cloned table row."
                        },
                        "maxItems": 2000,
                        "description": "Rows cloned for {{#loopKey}}...{{/loopKey}} inside <w:tr> or <a:tr>."
                      },
                      "description": "Repeating table row arrays keyed by loop name (matching {{#items}}...{{/items}} inside a Word or PowerPoint table row)."
                    }
                  },
                  "required": [
                    "fileBase64"
                  ],
                  "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": {
                  "fileBase64": {
                    "type": "string",
                    "minLength": 16,
                    "description": "Base64-encoded .docx or .pptx OOXML template file (accepts raw Base64 or data:...;base64, URI)."
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "docx",
                      "pptx"
                    ],
                    "default": "auto",
                    "description": "Template format ('auto' inspects internal OOXML ZIP entries)."
                  },
                  "variables": {
                    "type": "object",
                    "additionalProperties": {
                      "description": "Scalar replacement value (string, finite number, or boolean)."
                    },
                    "description": "Key-value map for {{placeholder}} variables across body, headers, footers, and slides. Multi-line '\\n' values expand to <w:br/> / <a:br/>."
                  },
                  "tableLoops": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": {
                          "description": "Scalar replacement value (string, finite number, or boolean)."
                        },
                        "description": "Per-row variable map merged into the cloned table row."
                      },
                      "maxItems": 2000,
                      "description": "Rows cloned for {{#loopKey}}...{{/loopKey}} inside <w:tr> or <a:tr>."
                    },
                    "description": "Repeating table row arrays keyed by loop name (matching {{#items}}...{{/items}} inside a Word or PowerPoint table row)."
                  }
                },
                "required": [
                  "fileBase64"
                ],
                "additionalProperties": false
              },
              "example": {
                "fileBase64": "UEsDBBQAAAAIA...",
                "format": "docx",
                "variables": {
                  "customer_name": "Acme Robotics, Inc.",
                  "billing_address": "500 Market St\nSuite 1200\nSan Francisco, CA",
                  "contract_id": "MSA-2026-089"
                },
                "tableLoops": {
                  "items": [
                    {
                      "sku": "ENT-SEAT",
                      "description": "Enterprise Agent Seat",
                      "qty": 25,
                      "total": "$2,500"
                    },
                    {
                      "sku": "DED-EDGE",
                      "description": "Dedicated Edge Worker",
                      "qty": 1,
                      "total": "$500"
                    }
                  ]
                }
              }
            }
          }
        },
        "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-office-markdown": {
      "post": {
        "operationId": "extract_office_markdown",
        "summary": "Extract Token-Minimal Markdown from .docx, .pptx, or .xlsx",
        "description": "Auto-detects .docx, .pptx, or .xlsx from OOXML structure and converts headings, lists, Word/PowerPoint tables, numerically ordered slides, speaker notes, and sparse Excel worksheets into compact GitHub-Flavored Markdown with token-savings telemetry. Why call instead of DIY: Saves 80-95% of context window tokens vs raw OOXML dumps and handles Excel sharedStrings.xml + sparse cell coordinates (A1, D5) without external libraries. Pricing: $0.002 USD per Office document extraction (.docx, .pptx, or .xlsx) (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "document-automation",
          "office-ooxml",
          "context-compression",
          "business-ops"
        ],
        "externalDocs": {
          "description": "Extract Token-Minimal Markdown from .docx, .pptx, or .xlsx Specification & Examples",
          "url": "https://office-template.apikeg.com/tools/extract-office-markdown"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.002",
          "amountAtomicUnits": "2000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "document-automation",
                "office-ooxml",
                "context-compression",
                "business-ops"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "fileBase64": "UEsDBBQAAAAIA...",
                    "includeSpeakerNotes": true,
                    "maxRowsPerSheet": 500
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Returns format='pptx', ordered '## Slide N: Title' Markdown with pipe tables and speaker notes, plus token reduction stats."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "fileBase64": {
                      "type": "string",
                      "minLength": 16,
                      "description": "Base64-encoded .docx, .pptx, or .xlsx OOXML file to convert into token-minimal Markdown."
                    },
                    "includeSpeakerNotes": {
                      "type": "boolean",
                      "default": true,
                      "description": "Include speaker notes from ppt/notesSlides/notesSlide*.xml when extracting .pptx presentations."
                    },
                    "maxRowsPerSheet": {
                      "type": "integer",
                      "default": 500,
                      "minimum": 1,
                      "maximum": 5000,
                      "description": "Maximum non-empty rows emitted per .xlsx worksheet."
                    }
                  },
                  "required": [
                    "fileBase64"
                  ],
                  "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": {
                  "fileBase64": {
                    "type": "string",
                    "minLength": 16,
                    "description": "Base64-encoded .docx, .pptx, or .xlsx OOXML file to convert into token-minimal Markdown."
                  },
                  "includeSpeakerNotes": {
                    "type": "boolean",
                    "default": true,
                    "description": "Include speaker notes from ppt/notesSlides/notesSlide*.xml when extracting .pptx presentations."
                  },
                  "maxRowsPerSheet": {
                    "type": "integer",
                    "default": 500,
                    "minimum": 1,
                    "maximum": 5000,
                    "description": "Maximum non-empty rows emitted per .xlsx worksheet."
                  }
                },
                "required": [
                  "fileBase64"
                ],
                "additionalProperties": false
              },
              "example": {
                "fileBase64": "UEsDBBQAAAAIA...",
                "includeSpeakerNotes": true,
                "maxRowsPerSheet": 500
              }
            }
          }
        },
        "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"
                }
              }
            }
          }
        }
      }
    }
  }
}