# `distill_har_capture` — Distill & Scrub HAR Network Capture

> Part of [Trace Diet — HAR & Log Context Distiller API](https://trace-diet.apikeg.com/llms.txt) (`com.apikeg/trace-diet`)

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.

- **REST Endpoint:** `POST https://trace-diet.apikeg.com/v1/distill-har-capture`
- **MCP Server:** `https://trace-diet.apikeg.com/mcp` (tool: `distill_har_capture`)
- **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)
- **Free Dry-Run:** `POST https://trace-diet.apikeg.com/v1/distill-har-capture?dry_run=true`

## Input JSON Schema
```json
{
  "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
}
```

## Examples
### Distill Playwright checkout failure HAR
```bash
curl -X POST "https://trace-diet.apikeg.com/v1/distill-har-capture" \
  -H "Content-Type: application/json" \
  -d '{"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}"}}}]}}}'
```
Expected output: 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.
