{
  "openapi": "3.1.0",
  "info": {
    "title": "Trace Diet — HAR & Log Context Distiller API",
    "version": "1.0.0",
    "summary": "Shrink 5MB .har captures and 50,000-line crash logs by 95–99% while scrubbing live tokens before they hit your LLM context.",
    "description": "Deterministic context-window compression and secret-scrubbing engine for debugging agents: distills bloated Chrome DevTools / Playwright .har captures into typed API routes & failures, and collapses 50,000+ noisy plain-text/K8s/NDJSON log lines by 95–99% via Drain prefix-tree clustering.\n\nSaves $0.25–$1.50 of wasted frontier-LLM input tokens per debugging turn, prevents live JWT/Cookie leakage into conversation history, folds multi-language stack traces accurately, and infers TypeScript API schemas in <40ms.",
    "contact": {
      "name": "API Keg",
      "url": "https://apikeg.com"
    }
  },
  "servers": [
    {
      "url": "https://trace-diet.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/distill-har-capture": {
      "post": {
        "operationId": "distill_har_capture",
        "summary": "Distill & Scrub HAR Network Capture",
        "description": "Parses Chrome DevTools / Playwright .har captures, strips static assets (.js/.css/fonts/images), analytics beacons, and OPTIONS preflights, scrubs credentials (Authorization, Cookie, Set-Cookie, X-Api-Key, token params, JWTs) into [REDACTED:<type>], groups dynamic :id/:uuid routes and polling loops, surfaces 4xx/5xx failures and slowestEndpoints, and infers compact TypeScript request/response schemas. Why call instead of DIY: Replaces ad-hoc jq/Python HAR scripts that miss base64 bodies, leak Bearer JWTs/cookies into LLM prompts, or fail to merge nullable JSON types across repeated API calls. Pricing: $0.002 base (up to $0.008 max ($0.002 base + $0.001 per 250KB of .har input, capped at $0.008), x402 variable settlement). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "developer-tools",
          "observability",
          "context-optimization",
          "security-hygiene"
        ],
        "externalDocs": {
          "description": "Distill & Scrub HAR Network Capture Specification & Examples",
          "url": "https://trace-diet.apikeg.com/tools/distill-har-capture"
        },
        "x-x402": {
          "version": 2,
          "scheme": "upto",
          "priceUsd": "0.002",
          "maxPriceUsd": "0.008",
          "amountAtomicUnits": "8000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "developer-tools",
                "observability",
                "context-optimization",
                "security-hygiene"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "redactSecrets": true,
                    "inferSchemas": true,
                    "includeStaticAssets": false,
                    "includeTelemetry": false,
                    "includeOptionsPreflight": false,
                    "maxFailureBodyChars": 512,
                    "maxSlowestEndpoints": 10,
                    "har": {
                      "log": {
                        "version": "1.2",
                        "entries": [
                          {
                            "startedDateTime": "2026-11-30T08:15:00.000Z",
                            "time": 412,
                            "request": {
                              "method": "POST",
                              "url": "https://api.shop.io/users/94821/orders/550e8400-e29b-41d4-a716-446655440000?api_key=live_secret",
                              "headers": [
                                {
                                  "name": "Authorization",
                                  "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5NDgyMSJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
                                }
                              ],
                              "postData": {
                                "mimeType": "application/json",
                                "text": "{\"sku\":\"PRO-ANNUAL\",\"Seats\":5}"
                              }
                            },
                            "response": {
                              "status": 500,
                              "statusText": "Internal Server Error",
                              "headers": [
                                {
                                  "name": "Content-Type",
                                  "value": "application/json"
                                }
                              ],
                              "content": {
                                "mimeType": "application/json",
                                "text": "{\"error\":\"stripe_upstream_timeout\",\"retryable\":true}"
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "1 grouped endpoint POST https://api.shop.io/users/:id/orders/:uuid, 1 failure with redacted JWT + api_key, and inferred TypeScript Request/Error interfaces."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "har": {
                      "type": "object",
                      "properties": {},
                      "additionalProperties": true,
                      "description": "Parsed HAR 1.2 JSON object containing log.entries (exported from Chrome DevTools, Playwright, or mitmproxy)."
                    },
                    "harJson": {
                      "type": "string",
                      "minLength": 2,
                      "maxLength": 5000000,
                      "description": "Raw serialized .har JSON text when passing unparsed file contents directly."
                    },
                    "includeStaticAssets": {
                      "type": "boolean",
                      "default": false,
                      "description": "Keep static asset requests (.js, .css, .woff2, .png, .svg, .ico, images/fonts). Defaults to false."
                    },
                    "includeTelemetry": {
                      "type": "boolean",
                      "default": false,
                      "description": "Keep analytics and telemetry beacons (Google Analytics, Segment, Datadog, Sentry, Mixpanel). Defaults to false."
                    },
                    "includeOptionsPreflight": {
                      "type": "boolean",
                      "default": false,
                      "description": "Keep CORS OPTIONS preflight requests. Defaults to false."
                    },
                    "redactSecrets": {
                      "type": "boolean",
                      "default": true,
                      "description": "Scrub Authorization, Cookie, Set-Cookie, X-Api-Key, api_key/token query params, and JWTs into [REDACTED:<type>]."
                    },
                    "inferSchemas": {
                      "type": "boolean",
                      "default": true,
                      "description": "Infer compact TypeScript interfaces/types for JSON request and response payloads across endpoint calls."
                    },
                    "maxFailureBodyChars": {
                      "type": "integer",
                      "default": 512,
                      "minimum": 64,
                      "maximum": 4096,
                      "description": "Maximum characters retained per 4xx/5xx/network failure body snippet."
                    },
                    "maxSlowestEndpoints": {
                      "type": "integer",
                      "default": 10,
                      "minimum": 1,
                      "maximum": 50,
                      "description": "Maximum number of slowest endpoints ranked by p95 latency."
                    },
                    "allowedHosts": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      },
                      "maxItems": 50,
                      "description": "Optional hostname allowlist (e.g. ['api.acme.com']) to isolate target traffic."
                    }
                  },
                  "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": {
                  "har": {
                    "type": "object",
                    "properties": {},
                    "additionalProperties": true,
                    "description": "Parsed HAR 1.2 JSON object containing log.entries (exported from Chrome DevTools, Playwright, or mitmproxy)."
                  },
                  "harJson": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 5000000,
                    "description": "Raw serialized .har JSON text when passing unparsed file contents directly."
                  },
                  "includeStaticAssets": {
                    "type": "boolean",
                    "default": false,
                    "description": "Keep static asset requests (.js, .css, .woff2, .png, .svg, .ico, images/fonts). Defaults to false."
                  },
                  "includeTelemetry": {
                    "type": "boolean",
                    "default": false,
                    "description": "Keep analytics and telemetry beacons (Google Analytics, Segment, Datadog, Sentry, Mixpanel). Defaults to false."
                  },
                  "includeOptionsPreflight": {
                    "type": "boolean",
                    "default": false,
                    "description": "Keep CORS OPTIONS preflight requests. Defaults to false."
                  },
                  "redactSecrets": {
                    "type": "boolean",
                    "default": true,
                    "description": "Scrub Authorization, Cookie, Set-Cookie, X-Api-Key, api_key/token query params, and JWTs into [REDACTED:<type>]."
                  },
                  "inferSchemas": {
                    "type": "boolean",
                    "default": true,
                    "description": "Infer compact TypeScript interfaces/types for JSON request and response payloads across endpoint calls."
                  },
                  "maxFailureBodyChars": {
                    "type": "integer",
                    "default": 512,
                    "minimum": 64,
                    "maximum": 4096,
                    "description": "Maximum characters retained per 4xx/5xx/network failure body snippet."
                  },
                  "maxSlowestEndpoints": {
                    "type": "integer",
                    "default": 10,
                    "minimum": 1,
                    "maximum": 50,
                    "description": "Maximum number of slowest endpoints ranked by p95 latency."
                  },
                  "allowedHosts": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 255
                    },
                    "maxItems": 50,
                    "description": "Optional hostname allowlist (e.g. ['api.acme.com']) to isolate target traffic."
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "redactSecrets": true,
                "inferSchemas": true,
                "includeStaticAssets": false,
                "includeTelemetry": false,
                "includeOptionsPreflight": false,
                "maxFailureBodyChars": 512,
                "maxSlowestEndpoints": 10,
                "har": {
                  "log": {
                    "version": "1.2",
                    "entries": [
                      {
                        "startedDateTime": "2026-11-30T08:15:00.000Z",
                        "time": 412,
                        "request": {
                          "method": "POST",
                          "url": "https://api.shop.io/users/94821/orders/550e8400-e29b-41d4-a716-446655440000?api_key=live_secret",
                          "headers": [
                            {
                              "name": "Authorization",
                              "value": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5NDgyMSJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
                            }
                          ],
                          "postData": {
                            "mimeType": "application/json",
                            "text": "{\"sku\":\"PRO-ANNUAL\",\"Seats\":5}"
                          }
                        },
                        "response": {
                          "status": 500,
                          "statusText": "Internal Server Error",
                          "headers": [
                            {
                              "name": "Content-Type",
                              "value": "application/json"
                            }
                          ],
                          "content": {
                            "mimeType": "application/json",
                            "text": "{\"error\":\"stripe_upstream_timeout\",\"retryable\":true}"
                          }
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "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/cluster-logs": {
      "post": {
        "operationId": "cluster_logs",
        "summary": "Cluster Noisy Logs via Drain Prefix-Tree",
        "description": "Folds multi-line stack traces (JS/Java 'at ...', Python Traceback, Go panics, Java 'Caused by:'), parses plain-text, Docker/Kubernetes CRI, and NDJSON logs, pre-masks <UUID>/<IP>/<HEX>/<ISO_TS>/<URL>/<NUM>, and runs a fixed-depth Drain prefix-tree clusterer to collapse 50,000+ log lines by 95–99% with errorClusters highlighted first. Why call instead of DIY: Avoids naive grep/head truncation that misses rare fatal stack traces buried at line 41,000, cutting 500k-token log dumps to ~2k tokens in <50ms. Pricing: $0.002 base (up to $0.008 max ($0.002 base + $0.001 per 2,000 log lines, capped at $0.008), x402 variable settlement). Pass ?dry_run=true on REST to validate schema free.",
        "tags": [
          "developer-tools",
          "observability",
          "context-optimization",
          "security-hygiene"
        ],
        "externalDocs": {
          "description": "Cluster Noisy Logs via Drain Prefix-Tree Specification & Examples",
          "url": "https://trace-diet.apikeg.com/tools/cluster-logs"
        },
        "x-x402": {
          "version": 2,
          "scheme": "upto",
          "priceUsd": "0.002",
          "maxPriceUsd": "0.008",
          "amountAtomicUnits": "8000",
          "network": "eip155:8453",
          "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "payTo": "0x000000000000000000000000000000000000dEaD",
          "extensions": {
            "bazaar": {
              "discoverable": true,
              "category": [
                "developer-tools",
                "observability",
                "context-optimization",
                "security-hygiene"
              ],
              "info": {
                "input": {
                  "type": "http",
                  "method": "POST",
                  "bodyType": "json",
                  "example": {
                    "similarityThreshold": 0.6,
                    "treeDepth": 4,
                    "maxClusters": 300,
                    "maxReturnedClusters": 100,
                    "maxStackTraceChars": 1500,
                    "logs": "2026-11-30T08:00:01.100Z INFO [http] GET /healthz from 10.244.1.8 completed in 2ms\n2026-11-30T08:00:02.100Z INFO [http] GET /healthz from 10.244.1.9 completed in 3ms\n2026-11-30T08:00:03.250Z ERROR [db] Deadlock detected for tx 550e8400-e29b-41d4-a716-446655440000 after 3 retries\n    at PoolClient.query (/srv/app/db.ts:118:13)\n    at OrderRepo.commit (/srv/app/orders.ts:74:9)"
                  }
                },
                "output": {
                  "type": "json",
                  "summary": "Highlights 1 ERROR cluster (with folded stack trace) ahead of 1 INFO template (<IP>, <NUM> masked)."
                }
              },
              "schema": {
                "inputSchema": {
                  "type": "object",
                  "properties": {
                    "logs": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 5000000,
                      "description": "Raw plain-text, Docker/Kubernetes CRI, or newline-delimited JSON (ndjson) log stream."
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "maxLength": 32768
                      },
                      "minItems": 1,
                      "maxItems": 100000,
                      "description": "Pre-split array of log lines (alternative to passing a single 'logs' string)."
                    },
                    "similarityThreshold": {
                      "type": "number",
                      "default": 0.6,
                      "minimum": 0.2,
                      "maximum": 1,
                      "description": "Drain token-similarity threshold [0.2-1.0] required to merge a log line into an existing canonical template."
                    },
                    "treeDepth": {
                      "type": "integer",
                      "default": 4,
                      "minimum": 3,
                      "maximum": 8,
                      "description": "Fixed Drain prefix-tree depth (length -> leading tokens -> leaf templates)."
                    },
                    "maxClusters": {
                      "type": "integer",
                      "default": 300,
                      "minimum": 10,
                      "maximum": 1000,
                      "description": "Maximum canonical Drain clusters maintained before routing outliers to overflow."
                    },
                    "maxReturnedClusters": {
                      "type": "integer",
                      "default": 100,
                      "minimum": 1,
                      "maximum": 500,
                      "description": "Maximum ranked clusters returned in the response payload."
                    },
                    "maxStackTraceChars": {
                      "type": "integer",
                      "default": 1500,
                      "minimum": 128,
                      "maximum": 8192,
                      "description": "Maximum characters retained per cluster sampleStackTrace."
                    }
                  },
                  "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": {
                  "logs": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 5000000,
                    "description": "Raw plain-text, Docker/Kubernetes CRI, or newline-delimited JSON (ndjson) log stream."
                  },
                  "lines": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 32768
                    },
                    "minItems": 1,
                    "maxItems": 100000,
                    "description": "Pre-split array of log lines (alternative to passing a single 'logs' string)."
                  },
                  "similarityThreshold": {
                    "type": "number",
                    "default": 0.6,
                    "minimum": 0.2,
                    "maximum": 1,
                    "description": "Drain token-similarity threshold [0.2-1.0] required to merge a log line into an existing canonical template."
                  },
                  "treeDepth": {
                    "type": "integer",
                    "default": 4,
                    "minimum": 3,
                    "maximum": 8,
                    "description": "Fixed Drain prefix-tree depth (length -> leading tokens -> leaf templates)."
                  },
                  "maxClusters": {
                    "type": "integer",
                    "default": 300,
                    "minimum": 10,
                    "maximum": 1000,
                    "description": "Maximum canonical Drain clusters maintained before routing outliers to overflow."
                  },
                  "maxReturnedClusters": {
                    "type": "integer",
                    "default": 100,
                    "minimum": 1,
                    "maximum": 500,
                    "description": "Maximum ranked clusters returned in the response payload."
                  },
                  "maxStackTraceChars": {
                    "type": "integer",
                    "default": 1500,
                    "minimum": 128,
                    "maximum": 8192,
                    "description": "Maximum characters retained per cluster sampleStackTrace."
                  }
                },
                "additionalProperties": false
              },
              "example": {
                "similarityThreshold": 0.6,
                "treeDepth": 4,
                "maxClusters": 300,
                "maxReturnedClusters": 100,
                "maxStackTraceChars": 1500,
                "logs": "2026-11-30T08:00:01.100Z INFO [http] GET /healthz from 10.244.1.8 completed in 2ms\n2026-11-30T08:00:02.100Z INFO [http] GET /healthz from 10.244.1.9 completed in 3ms\n2026-11-30T08:00:03.250Z ERROR [db] Deadlock detected for tx 550e8400-e29b-41d4-a716-446655440000 after 3 retries\n    at PoolClient.query (/srv/app/db.ts:118:13)\n    at OrderRepo.commit (/srv/app/orders.ts:74:9)"
              }
            }
          }
        },
        "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"
                }
              }
            }
          }
        }
      }
    }
  }
}