# Trace Diet — HAR & Log Context Distiller API (v1.0.0)

> Shrink 5MB .har captures and 50,000-line crash logs by 95–99% while scrubbing live tokens before they hit your LLM context.

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.

## Why Agents Use This API Instead of DIY
Saves $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.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://trace-diet.apikeg.com/mcp` (Registry ID: `com.apikeg/trace-diet` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://trace-diet.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://trace-diet.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://trace-diet.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://trace-diet.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://trace-diet.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://trace-diet.apikeg.com/.well-known/agent-card.json)
- **Primary Payment (Zero Signup):** Cloudflare Monetization Gateway (`HTTP 402` / `x402` v2 with USDC on Base).
- **Optional Monthly API Key:** Pass `Authorization: Bearer ak_live_...` ($5 / $20 / $50 monthly per-product Stripe plans at [apikeg.com/account](https://apikeg.com/account)).
- **Free Preflight:** Append `?dry_run=true` (or header `X-Dry-Run: true`) to validate any request payload at `$0.00` cost.

## Tools & REST Endpoints
- [`distill_har_capture`](https://trace-diet.apikeg.com/tools/distill-har-capture.md) (`POST https://trace-diet.apikeg.com/v1/distill-har-capture`) — $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): 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.
- [`cluster_logs`](https://trace-diet.apikeg.com/tools/cluster-logs.md) (`POST https://trace-diet.apikeg.com/v1/cluster-logs`) — $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): 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.

## Instant MCP Configuration
```json
{
  "mcpServers": {
    "trace-diet": {
      "type": "streamable-http",
      "url": "https://trace-diet.apikeg.com/mcp"
    }
  }
}
```

## Common Agent Use Cases
- compress Chrome HAR file for LLM agent MCP
- redact JWT Authorization cookies from HAR capture API
- infer TypeScript interfaces from network HAR requests
- Drain log clustering algorithm API MCP
- summarize 50000 Kubernetes Docker NDJSON logs for AI debugging
- reduce Playwright trace and log token usage
