{
  "openapi": "3.1.0",
  "info": {
    "title": "DOM Harvest & Table Grid Edge API",
    "version": "1.0.0",
    "summary": "Turn noisy HTML tables, repeating product grids, and JSON-LD into clean typed JSON with >90% LLM token reduction.",
    "description": "Pure-TypeScript HTML structure harvester that resolves complex multi-row rowspan/colspan tables into typed 2D JSON matrices, auto-detects 100-500 repeating product/listing cards without selectors, extracts JSON-LD & OpenGraph metadata, and executes declarative CSS-schema scraping.\n\nDumping raw 300KB HTML into an LLM burns $0.05-$0.30 in context tokens and truncates past item 20; DIY regex/table parsers break on multi-row thead colspan + rowspan merges. DOM Harvest extracts all 500 items deterministically in <20ms for $0.001-$0.002.",
    "contact": {
      "name": "API Keg",
      "url": "https://apikeg.com"
    }
  },
  "servers": [
    {
      "url": "https://dom-harvest.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/harvest-page-structures": {
      "post": {
        "operationId": "harvest_page_structures",
        "summary": "Auto-Harvest Tables, Repeating Cards & Metadata",
        "description": "Zero-selector structural HTML harvester: extracts canonical/OpenGraph/Twitter metadata, Schema.org JSON-LD, normalized 2D tables (resolving multi-header rowspan/colspan merges + cell links), and repeating sibling card collections across 100-500 items without truncation. Why call instead of DIY: Compresses 250KB+ noisy DOMs by >90% tokens without dropping items 21-500 or misaligning colspan/rowspan financial columns; runs deterministically in <20ms at $0.002. Pricing: $0.002 USD per HTML page structure harvest (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "web-scraping",
          "data-extraction",
          "context-compression",
          "developer-tools"
        ],
        "externalDocs": {
          "description": "Auto-Harvest Tables, Repeating Cards & Metadata Specification & Examples",
          "url": "https://dom-harvest.apikeg.com/tools/harvest-page-structures"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.002",
          "amountAtomicUnits": "2000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "web-scraping",
                "data-extraction",
                "context-compression",
                "developer-tools"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "baseUrl": "https://shop.example.com/catalog",
                    "includeMatrix": true,
                    "minCollectionItems": 3,
                    "html": "<html><head><title>Catalog</title></head><body><table><thead><tr><th rowspan='2'>Region</th><th colspan='2'>Q1 2026</th></tr><tr><th>Revenue</th><th>Growth</th></tr></thead><tbody><tr><td>NA</td><td>$1,200,000</td><td>18%</td></tr></tbody></table></body></html>"
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Returns metadata, jsonLd, normalized tables with 'Q1 2026 / Revenue' typed numeric rows, repeatingCollections, and token-reduction metrics."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "html": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 4000000,
                      "description": "Raw HTML page or fragment to tokenize and harvest into structured JSON."
                    },
                    "baseUrl": {
                      "type": "string",
                      "maxLength": 2048,
                      "description": "Optional origin/page URL used to resolve relative href, src, canonical, and OpenGraph URLs."
                    },
                    "includeMatrix": {
                      "type": "boolean",
                      "default": true,
                      "description": "Include the resolved 2D string matrix alongside typed row records on each extracted table."
                    },
                    "minCollectionItems": {
                      "type": "integer",
                      "default": 3,
                      "minimum": 2,
                      "maximum": 50,
                      "description": "Minimum repeating sibling cards required to emit an auto-detected repeatingCollection."
                    }
                  },
                  "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": 4000000,
                    "description": "Raw HTML page or fragment to tokenize and harvest into structured JSON."
                  },
                  "baseUrl": {
                    "type": "string",
                    "maxLength": 2048,
                    "description": "Optional origin/page URL used to resolve relative href, src, canonical, and OpenGraph URLs."
                  },
                  "includeMatrix": {
                    "type": "boolean",
                    "default": true,
                    "description": "Include the resolved 2D string matrix alongside typed row records on each extracted table."
                  },
                  "minCollectionItems": {
                    "type": "integer",
                    "default": 3,
                    "minimum": 2,
                    "maximum": 50,
                    "description": "Minimum repeating sibling cards required to emit an auto-detected repeatingCollection."
                  }
                },
                "required": [
                  "html"
                ],
                "additionalProperties": false
              },
              "example": {
                "baseUrl": "https://shop.example.com/catalog",
                "includeMatrix": true,
                "minCollectionItems": 3,
                "html": "<html><head><title>Catalog</title></head><body><table><thead><tr><th rowspan='2'>Region</th><th colspan='2'>Q1 2026</th></tr><tr><th>Revenue</th><th>Growth</th></tr></thead><tbody><tr><td>NA</td><td>$1,200,000</td><td>18%</td></tr></tbody></table></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-by-schema": {
      "post": {
        "operationId": "extract_by_schema",
        "summary": "Extract Records by Declarative CSS Schema",
        "description": "Deterministic CSS-selector record extractor supporting descendant/child/attribute/group selectors, relative URL resolution against baseUrl, numeric currency/comma coercion, boolean flags, inner HTML serialization, and multi-value arrays. Why call instead of DIY: Eliminates brittle ad-hoc cheerio/regex glue code and runs identically at the Cloudflare edge in <10ms for $0.001. Pricing: $0.001 USD per declarative CSS-schema extraction (x402 instant micropayment). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "web-scraping",
          "data-extraction",
          "context-compression",
          "developer-tools"
        ],
        "externalDocs": {
          "description": "Extract Records by Declarative CSS Schema Specification & Examples",
          "url": "https://dom-harvest.apikeg.com/tools/extract-by-schema"
        },
        "x-x402": {
          "version": 2,
          "scheme": "exact",
          "priceUsd": "0.001",
          "amountAtomicUnits": "1000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "web-scraping",
                "data-extraction",
                "context-compression",
                "developer-tools"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "baseUrl": "https://store.example.com/deals/",
                    "itemSelector": "article.product-card",
                    "fields": {
                      "sku": {
                        "selector": ":scope",
                        "attribute": "data-sku",
                        "type": "string"
                      },
                      "title": {
                        "selector": "h3.title",
                        "type": "string"
                      },
                      "url": {
                        "selector": "a.card-link",
                        "attribute": "href",
                        "type": "url"
                      },
                      "price": {
                        "selector": ".price-current",
                        "type": "number"
                      },
                      "inStock": {
                        "selector": ".badge-in-stock",
                        "type": "boolean"
                      },
                      "tags": {
                        "selector": "ul.tags > li",
                        "type": "string",
                        "multiple": true
                      }
                    },
                    "html": "<div class='grid'><article class='product-card' data-sku='SKU-9'><a class='card-link' href='../p/sku-9'><h3 class='title'>Pro Dock</h3></a><span class='price-current'>$189.99</span><span class='badge-in-stock'>In Stock</span><ul class='tags'><li>USB4</li><li>100W PD</li></ul></article></div>"
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Returns 1 typed item with url='https://store.example.com/p/sku-9', price=189.99, inStock=true, tags=['USB4', '100W PD']."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "html": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 4000000,
                      "description": "Raw HTML page or fragment."
                    },
                    "baseUrl": {
                      "type": "string",
                      "maxLength": 2048,
                      "description": "Optional page URL used to resolve relative URLs when field type is 'url'."
                    },
                    "itemSelector": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 512,
                      "description": "CSS selector matching each repeating record element (or 'body' / 'html' for single-object page extraction)."
                    },
                    "fields": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "object",
                        "properties": {
                          "selector": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 512,
                            "description": "CSS selector evaluated within each matched item element (use ':scope' to target the item element itself)."
                          },
                          "attribute": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128,
                            "description": "Optional HTML attribute name to read (e.g. 'href', 'src', 'data-price'). Omit to extract text or inner HTML."
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "string",
                              "number",
                              "url",
                              "boolean",
                              "html"
                            ],
                            "default": "string",
                            "description": "Coercion type: 'string', 'number' (strips currency/commas), 'url' (resolves against baseUrl), 'boolean', or 'html'."
                          },
                          "multiple": {
                            "type": "boolean",
                            "default": false,
                            "description": "When true, extracts an array across all matching elements inside each item instead of the first match."
                          }
                        },
                        "required": [
                          "selector"
                        ],
                        "additionalProperties": false,
                        "description": "Declarative extraction rule for a single field."
                      },
                      "description": "Map of output property names to declarative CSS selector + type coercion rules."
                    }
                  },
                  "required": [
                    "html",
                    "itemSelector",
                    "fields"
                  ],
                  "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": 4000000,
                    "description": "Raw HTML page or fragment."
                  },
                  "baseUrl": {
                    "type": "string",
                    "maxLength": 2048,
                    "description": "Optional page URL used to resolve relative URLs when field type is 'url'."
                  },
                  "itemSelector": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512,
                    "description": "CSS selector matching each repeating record element (or 'body' / 'html' for single-object page extraction)."
                  },
                  "fields": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "selector": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 512,
                          "description": "CSS selector evaluated within each matched item element (use ':scope' to target the item element itself)."
                        },
                        "attribute": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 128,
                          "description": "Optional HTML attribute name to read (e.g. 'href', 'src', 'data-price'). Omit to extract text or inner HTML."
                        },
                        "type": {
                          "type": "string",
                          "enum": [
                            "string",
                            "number",
                            "url",
                            "boolean",
                            "html"
                          ],
                          "default": "string",
                          "description": "Coercion type: 'string', 'number' (strips currency/commas), 'url' (resolves against baseUrl), 'boolean', or 'html'."
                        },
                        "multiple": {
                          "type": "boolean",
                          "default": false,
                          "description": "When true, extracts an array across all matching elements inside each item instead of the first match."
                        }
                      },
                      "required": [
                        "selector"
                      ],
                      "additionalProperties": false,
                      "description": "Declarative extraction rule for a single field."
                    },
                    "description": "Map of output property names to declarative CSS selector + type coercion rules."
                  }
                },
                "required": [
                  "html",
                  "itemSelector",
                  "fields"
                ],
                "additionalProperties": false
              },
              "example": {
                "baseUrl": "https://store.example.com/deals/",
                "itemSelector": "article.product-card",
                "fields": {
                  "sku": {
                    "selector": ":scope",
                    "attribute": "data-sku",
                    "type": "string"
                  },
                  "title": {
                    "selector": "h3.title",
                    "type": "string"
                  },
                  "url": {
                    "selector": "a.card-link",
                    "attribute": "href",
                    "type": "url"
                  },
                  "price": {
                    "selector": ".price-current",
                    "type": "number"
                  },
                  "inStock": {
                    "selector": ".badge-in-stock",
                    "type": "boolean"
                  },
                  "tags": {
                    "selector": "ul.tags > li",
                    "type": "string",
                    "multiple": true
                  }
                },
                "html": "<div class='grid'><article class='product-card' data-sku='SKU-9'><a class='card-link' href='../p/sku-9'><h3 class='title'>Pro Dock</h3></a><span class='price-current'>$189.99</span><span class='badge-in-stock'>In Stock</span><ul class='tags'><li>USB4</li><li>100W PD</li></ul></article></div>"
              }
            }
          }
        },
        "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"
                }
              }
            }
          }
        }
      }
    }
  }
}