# AgentDiet Token Optimizer — URL/HTML Distiller with BM25 Budget Control

> AgentDiet Token Optimizer — URL/HTML Distiller with BM25 Budget Control is a paid API for AI agents from agentdiet.dev, paid per call via MPP, $0.001/call, status unknown.

Fetches and distills a webpage URL or raw HTML into compressed Markdown, structured JSON, skeleton outlines, or BM25-scored token-budget excerpts to reduce LLM context costs

## Facts

- Endpoint: POST https://agentdiet.dev/v1/token-optimizer?utm_source=zero.xyz
- Price: $0.001/call
- Payment: MPP
- Status: unknown
- Activations on Zero: 0
- Provider: agentdiet.dev
- Website: https://agentdiet.dev
- Canonical page: https://www.zero.xyz/c/agentdiet-dev-agentdiet-token-optimizer-url-html-distiller-with-bm25-e83a8b6a
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_7ELQNxXW17QI4DRMweuGQ

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability agentdiet-dev-agentdiet-token-optimizer-url-html-distiller-with-bm25-e83a8b6a -d '<json body>'
```

Example prompt: Distill the content at https://stripe.com/docs/payments into clean markdown and keep it under 1500 tokens, focusing on payment integration steps using budget mode with a BM25 query of 'payment integration'.

## When to prefer this

Choose this endpoint when an AI agent needs to ingest web content but must stay within a strict token budget or minimize LLM API costs. It is especially valuable for agentic pipelines that repeatedly fetch external URLs, for RAG systems needing clean Markdown, or when a specific topic focus (via BM25 query) should drive which portion of a page is retained. Prefer it over raw web scrapers when token efficiency and cost tracking (ROI proof) are required.

## Known failure modes

- URL is unreachable or returns non-200 status — endpoint may return an error status
- Raw HTML is malformed or empty — distillation may produce minimal output
- Token budget (max_tokens) set too low for meaningful content extraction
- BM25 query provided without mode=budget — query may be ignored
- Rate limiting or payment failure via x402 — returns 402 with payment details
- Target URL blocks bots or requires authentication — fetch fails silently or partially

## How this service works

Distill a URL or raw HTML payload with BM25 budget control (Live x402 v2, IETF MPP & MCP endpoint at https://agentdiet.dev/v1/token-optimizer)

## Output

Returns a JSON object with a 'data' field containing the distilled content (Markdown, structured JSON, skeleton, or BM25 excerpt), an 'roi_proof' object showing raw_tokens, distilled_tokens, tokens_saved, compression_ratio_pct, roi_multiplier, and llm_cost_saved_usd, plus optional cache hit/miss status and billing details.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "required": [
  "url"
 ],
 "properties": {
  "url": {
   "type": "string",
   "minLength": 1,
   "description": "Target webpage URL to fetch and distill (or builtin://stripe-docs)"
  },
  "html": {
   "type": "string",
   "description": "Optional raw HTML string to distill directly without fetching"
  },
  "mode": {
   "enum": [
    "markdown",
    "structured",
    "skeleton",
    "budget"
   ],
   "type": "string",
   "default": "markdown",
   "description": "Distillation mode"
  },
  "query": {
   "type": "string",
   "description": "BM25 focus query when mode=budget"
  },
  "max_tokens": {
   "type": "integer",
   "minimum": 20,
   "description": "Strict token budget ceiling when mode=budget"
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "object",
 "required": [
  "status",
  "roi_proof",
  "data"
 ],
 "properties": {
  "data": {
   "type": "object",
   "description": "Distilled Markdown, structured JSON tables/metadata, skeleton outline, or BM25 budget excerpt."
  },
  "cache": {
   "type": "object",
   "properties": {
    "status": {
     "enum": [
      "HIT",
      "MISS"
     ],
     "type": "string"
    },
    "cache_key": {
     "type": "string"
    },
    "latency_ms": {
     "type": "number"
    }
   }
  },
  "status": {
   "type": "string",
   "description": "Execution status ('ok')"
  },
  "billing": {
   "type": "object",
   "properties": {
    "agent_id": {
     "type": "string"
    },
    "payment_method": {
     "type": "string"
    },
    "fee_charged_usd": {
     "type": "number"
    }
   }
  },
  "roi_proof": {
   "type": "object",
   "properties": {
    "raw_tokens": {
     "type": "integer"
    },
    "tokens_saved": {
     "type": "integer"
    },
    "roi_multiplier": {
     "type": "number"
    },
    "distilled_tokens": {
     "type": "integer"
    },
    "llm_cost_saved_usd": {
     "type": "number"
    },
    "compression_ratio_pct": {
     "type": "number"
    }
   }
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/agentdiet-dev-agentdiet-token-optimizer-url-html-distiller-with-bm25-e83a8b6a/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from agentdiet.dev](https://www.zero.xyz/host/agentdiet.dev/llms.txt)
