{
  "openapi": "3.1.0",
  "info": {
    "title": "Document Redline & Table Diff Edge API",
    "version": "1.0.0",
    "summary": "Deterministic Myers redlines, numeric/date edit alerts, Word .docx Track Changes, and composite-key table diffs in milliseconds.",
    "description": "Deterministic two-level Myers O(ND) paragraph and word-level document diffing, automatic numeric/currency/percentage/duration/date change extraction, native OpenXML .docx Track Changes generation, and composite-key CSV/JSON table diffing.\n\nPrevents middle-of-context LLM skimming misses on buried numeric/date edits, cuts 40-page document review payloads by 90-98% in tokens, and emits real OpenXML <w:ins>/<w:del> .docx archives without brittle Python/LibreOffice dependencies.",
    "contact": {
      "name": "API Keg",
      "url": "https://apikeg.com"
    }
  },
  "servers": [
    {
      "url": "https://doc-redline.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/diff-documents": {
      "post": {
        "operationId": "diff_documents",
        "summary": "Redline & Audit Two Document Versions",
        "description": "Runs two-level Myers O(ND) section/paragraph and inline word-and-punctuation diffing across two document versions, returning sectionBreadcrumb-tagged hunks, CriticMarkup ({--old--}{++new++}), inline HTML (<del>/<ins>), dedicated numericAndDateChanges alerts, and optional native .docx Track Changes. Why call instead of DIY: Eliminates 95% of unchanged context tokens on multi-section specs/RFPs/SOWs, catches every altered number/currency/duration/date deterministically, and packages valid ECMA-376 .docx Track Changes ZIP archives on the edge. Pricing: $0.002 USD per document redline comparison (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "document-processing",
          "procurement-ops",
          "revops",
          "developer-tools"
        ],
        "externalDocs": {
          "description": "Redline & Audit Two Document Versions Specification & Examples",
          "url": "https://doc-redline.apikeg.com/tools/diff-documents"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.002",
          "amountAtomicUnits": "2000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "document-processing",
                "procurement-ops",
                "revops",
                "developer-tools"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "original": "# Statement of Work\n\n## Section 4.2: Payment Terms\nCustomer shall pay all undisputed invoices within 30 days of receipt at $150/hour.",
                    "revised": "# Statement of Work\n\n## Section 4.2: Payment Terms\nCustomer shall pay all undisputed invoices within 45 days of receipt at $175/hour.",
                    "changedHunksOnly": true,
                    "contextParagraphs": 0,
                    "ignoreWhitespace": true,
                    "includeDocxTrackChanges": true,
                    "docxAuthor": "Procurement Ops Bot"
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "1 changed hunk under 'Statement of Work > Section 4.2: Payment Terms', 2 numericAndDateChanges ('30 days' -> '45 days', '$150' -> '$175'), and a valid base64 .docx with <w:del> and <w:ins>."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "original": {
                      "type": "string",
                      "maxLength": 900000,
                      "description": "Baseline/original document text or Markdown (e.g. RFP, SOW, specification, SLA, or policy v1)."
                    },
                    "revised": {
                      "type": "string",
                      "maxLength": 900000,
                      "description": "Revised/updated document text or Markdown to compare deterministically against original."
                    },
                    "changedHunksOnly": {
                      "type": "boolean",
                      "default": true,
                      "description": "When true (default), omits 100% identical sections from hunks, criticMarkup, and htmlRedline so multi-page documents shrink by 90-98% in tokens."
                    },
                    "contextParagraphs": {
                      "type": "integer",
                      "default": 0,
                      "minimum": 0,
                      "maximum": 5,
                      "description": "Number of surrounding unchanged paragraphs to include around each changed hunk (0-5)."
                    },
                    "ignoreWhitespace": {
                      "type": "boolean",
                      "default": true,
                      "description": "Normalize repeated inline whitespace when aligning paragraphs while preserving exact text inside word-level diffs."
                    },
                    "includeDocxTrackChanges": {
                      "type": "boolean",
                      "default": false,
                      "description": "When true, generates a base64 OpenXML .docx archive containing native Microsoft Word Track Changes (<w:ins> and <w:del>/<w:delText>) for Accept/Reject review."
                    },
                    "docxAuthor": {
                      "type": "string",
                      "default": "API Keg Redline Engine",
                      "maxLength": 120,
                      "description": "Author attribution recorded on OpenXML <w:ins> and <w:del> Track Changes tags when includeDocxTrackChanges is true."
                    },
                    "docxTitle": {
                      "type": "string",
                      "maxLength": 200,
                      "description": "Optional document title stored in .docx Dublin Core package metadata."
                    }
                  },
                  "required": [
                    "original",
                    "revised"
                  ],
                  "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": {
                  "original": {
                    "type": "string",
                    "maxLength": 900000,
                    "description": "Baseline/original document text or Markdown (e.g. RFP, SOW, specification, SLA, or policy v1)."
                  },
                  "revised": {
                    "type": "string",
                    "maxLength": 900000,
                    "description": "Revised/updated document text or Markdown to compare deterministically against original."
                  },
                  "changedHunksOnly": {
                    "type": "boolean",
                    "default": true,
                    "description": "When true (default), omits 100% identical sections from hunks, criticMarkup, and htmlRedline so multi-page documents shrink by 90-98% in tokens."
                  },
                  "contextParagraphs": {
                    "type": "integer",
                    "default": 0,
                    "minimum": 0,
                    "maximum": 5,
                    "description": "Number of surrounding unchanged paragraphs to include around each changed hunk (0-5)."
                  },
                  "ignoreWhitespace": {
                    "type": "boolean",
                    "default": true,
                    "description": "Normalize repeated inline whitespace when aligning paragraphs while preserving exact text inside word-level diffs."
                  },
                  "includeDocxTrackChanges": {
                    "type": "boolean",
                    "default": false,
                    "description": "When true, generates a base64 OpenXML .docx archive containing native Microsoft Word Track Changes (<w:ins> and <w:del>/<w:delText>) for Accept/Reject review."
                  },
                  "docxAuthor": {
                    "type": "string",
                    "default": "API Keg Redline Engine",
                    "maxLength": 120,
                    "description": "Author attribution recorded on OpenXML <w:ins> and <w:del> Track Changes tags when includeDocxTrackChanges is true."
                  },
                  "docxTitle": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Optional document title stored in .docx Dublin Core package metadata."
                  }
                },
                "required": [
                  "original",
                  "revised"
                ],
                "additionalProperties": false
              },
              "example": {
                "original": "# Statement of Work\n\n## Section 4.2: Payment Terms\nCustomer shall pay all undisputed invoices within 30 days of receipt at $150/hour.",
                "revised": "# Statement of Work\n\n## Section 4.2: Payment Terms\nCustomer shall pay all undisputed invoices within 45 days of receipt at $175/hour.",
                "changedHunksOnly": true,
                "contextParagraphs": 0,
                "ignoreWhitespace": true,
                "includeDocxTrackChanges": true,
                "docxAuthor": "Procurement Ops Bot"
              }
            }
          }
        },
        "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/diff-tables": {
      "post": {
        "operationId": "diff_tables",
        "summary": "Compare Two Structured CSV or JSON Tables by Primary Key",
        "description": "Compares two JSON object arrays or RFC 4180 CSV strings keyed by a single or composite primaryKey, returning exact summary counts, added rows, removed rows, and cell-level modified diffs with exact decimal numericDelta. Why call instead of DIY: Avoids row-order false positives in line-based diffs and floating-point drift on price/inventory catalogs; supports composite keys like ['sku', 'region'] in <10ms. Pricing: $0.002 USD per structured table or catalog diff (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "document-processing",
          "procurement-ops",
          "revops",
          "developer-tools"
        ],
        "externalDocs": {
          "description": "Compare Two Structured CSV or JSON Tables by Primary Key Specification & Examples",
          "url": "https://doc-redline.apikeg.com/tools/diff-tables"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.002",
          "amountAtomicUnits": "2000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "document-processing",
                "procurement-ops",
                "revops",
                "developer-tools"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "primaryKey": [
                      "sku",
                      "region"
                    ],
                    "csvDelimiter": ",",
                    "coerceCsvTypes": true,
                    "numericTolerance": 0,
                    "before": "sku,region,price,stock\nPRO-100,US,49.99,120\nPRO-100,EU,54.99,80\nLEGACY-1,US,19.00,10",
                    "after": "sku,region,price,stock\nPRO-100,US,59.99,95\nPRO-100,EU,54.99,80\nNEW-200,US,99.00,250"
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "unchangedCount=1, addedCount=1 (NEW-200::US), removedCount=1 (LEGACY-1::US), modifiedCount=1 (PRO-100::US price +10, stock -25)."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "before": {
                      "description": "Table dataset passed either as a JSON array of row objects (e.g. [{\"sku\":\"A1\",\"region\":\"US\",\"price\":49.99}]) or an RFC 4180 CSV string with a header row."
                    },
                    "after": {
                      "description": "Table dataset passed either as a JSON array of row objects (e.g. [{\"sku\":\"A1\",\"region\":\"US\",\"price\":49.99}]) or an RFC 4180 CSV string with a header row."
                    },
                    "primaryKey": {
                      "description": "Single primary-key column name (e.g. \"sku\") or composite primary-key column list (e.g. [\"sku\", \"region\"])."
                    },
                    "ignoreFields": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128
                      },
                      "maxItems": 64,
                      "description": "Optional column names (such as \"updated_at\" or \"etag\") to exclude from cell comparison."
                    },
                    "csvDelimiter": {
                      "type": "string",
                      "default": ",",
                      "minLength": 1,
                      "maxLength": 1,
                      "description": "Single-character column delimiter used when before or after is a CSV string (default ',')."
                    },
                    "coerceCsvTypes": {
                      "type": "boolean",
                      "default": true,
                      "description": "Automatically parse unquoted numeric and boolean literals in CSV cells while preserving leading-zero identifiers."
                    },
                    "numericTolerance": {
                      "type": "number",
                      "default": 0,
                      "minimum": 0,
                      "maximum": 1000000,
                      "description": "Optional non-negative tolerance; numeric cell differences with |delta| <= numericTolerance are treated as unchanged."
                    }
                  },
                  "required": [
                    "before",
                    "after",
                    "primaryKey"
                  ],
                  "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": {
                  "before": {
                    "description": "Table dataset passed either as a JSON array of row objects (e.g. [{\"sku\":\"A1\",\"region\":\"US\",\"price\":49.99}]) or an RFC 4180 CSV string with a header row."
                  },
                  "after": {
                    "description": "Table dataset passed either as a JSON array of row objects (e.g. [{\"sku\":\"A1\",\"region\":\"US\",\"price\":49.99}]) or an RFC 4180 CSV string with a header row."
                  },
                  "primaryKey": {
                    "description": "Single primary-key column name (e.g. \"sku\") or composite primary-key column list (e.g. [\"sku\", \"region\"])."
                  },
                  "ignoreFields": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    },
                    "maxItems": 64,
                    "description": "Optional column names (such as \"updated_at\" or \"etag\") to exclude from cell comparison."
                  },
                  "csvDelimiter": {
                    "type": "string",
                    "default": ",",
                    "minLength": 1,
                    "maxLength": 1,
                    "description": "Single-character column delimiter used when before or after is a CSV string (default ',')."
                  },
                  "coerceCsvTypes": {
                    "type": "boolean",
                    "default": true,
                    "description": "Automatically parse unquoted numeric and boolean literals in CSV cells while preserving leading-zero identifiers."
                  },
                  "numericTolerance": {
                    "type": "number",
                    "default": 0,
                    "minimum": 0,
                    "maximum": 1000000,
                    "description": "Optional non-negative tolerance; numeric cell differences with |delta| <= numericTolerance are treated as unchanged."
                  }
                },
                "required": [
                  "before",
                  "after",
                  "primaryKey"
                ],
                "additionalProperties": false
              },
              "example": {
                "primaryKey": [
                  "sku",
                  "region"
                ],
                "csvDelimiter": ",",
                "coerceCsvTypes": true,
                "numericTolerance": 0,
                "before": "sku,region,price,stock\nPRO-100,US,49.99,120\nPRO-100,EU,54.99,80\nLEGACY-1,US,19.00,10",
                "after": "sku,region,price,stock\nPRO-100,US,59.99,95\nPRO-100,EU,54.99,80\nNEW-200,US,99.00,250"
              }
            }
          }
        },
        "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"
                }
              }
            }
          }
        }
      }
    }
  }
}