A technical guide to architecting and shipping AI agents that act on live web data — covering tool design, failure modes, and production dec

Token-Efficiency of Structured Data Returns as the Decisive Cost Variable When Choosing a Web Data API

Output format decides whether a cheap scrape becomes an expensive model call.

· 8 min read
Cover illustration for “Token-Efficiency of Structured Data Returns as the Decisive Cost Variable When Choosing a Web Data API”
Tool and API Design · November 27, 2026 · 8 min read · 1,862 words

The best web scraping API for an AI pipeline is the one that returns the required data accurately at the lowest combined scraping and model cost. Output format is the key thing to test, because raw HTML, cleaned Markdown, and extracted JSON lead to very different token bills. A cheap fetch can become an expensive model call.

Why the format a web data API returns is a billing decision, not a formatting preference

Engineers tune prompt chains, embedding models, and retrieval strategies while leaving the scraping layer uninspected. That leaves a large cost multiplier outside the optimization work. Every token sent to an LLM is a billable unit, including tokens that contribute nothing to the answer. The scraping response sets how much input the model gets before the prompt does any work.

Consider a pipeline that needs just three fields. Raw HTML can return those fields with navigation menus, cookie banners, tracking scripts, and recommendation carousels around them. The model processes the surrounding material too. That is an infrastructure charge attached to content the pipeline did not need, repeated with every page ingested.

What the token gap between raw HTML, cleaned Markdown, and structured JSON actually looks like

Raw HTML preserves much of the machinery of a page along with its content. Scripts, styles, navigation, and consent banners all make the payload larger. Cleaned Markdown strips out what is not content and uses headings, lists, and tables to show how the rest is laid out. The saving comes from removing material.

Pre-extracted JSON can go further by returning only the requested fields. For a narrow extraction task, that leaves a small fraction of the content needed to represent the whole page, even in Markdown. This is a different kind of reduction. Markdown cleans the document, while field extraction limits the response to the task. The gap between those approaches can exceed the saving from stripping HTML into readable text.

Model pricing then multiplies the effect of format choice. The cost of sending clean text to a value model is very different from the cost of sending raw HTML to a premium model. Across a large ingestion workload, reducing irrelevant content can change whether the pipeline is economical, rather than simply make an already workable system slightly cheaper.

The comparison still needs a common task. A response containing a few company fields is not interchangeable with a document needed for broad retrieval. The useful measurement is the token burden of delivering the required information. Otherwise, an apparently efficient format can win by leaving out the work the pipeline was meant to do.

Why "structured JSON" is not a single thing, and why the wrong variant can cost more than Markdown

JSON can still leave the model with a large input. Its schema determines how much information, structure, and repetition the model receives. A small response containing selected fields differs from a JSON representation of an entire document. Both have the same format label. Treating them as the same hides the cost difference the test should show.

The NEXT-EVAL benchmark found that hierarchical JSON, which preserves document structure in a compact nested form, was the most token-efficient format tested. Flat JSON was the least token-efficient, using more tokens than slimmed HTML. That reverses the simple “JSON is cheaper” rule. A team choosing JSON without examining its structure may spend more than a team using well-cleaned Markdown.

The same benchmark also found a substantial accuracy trade-off. Hierarchical JSON achieved F1 of 0.4048, compared with 0.9567 for flat JSON, which delivered the lowest extraction error rate. These results make schema choice a joint cost-and-accuracy decision. Testing the compressed data on the task shows whether it still has the information needed.

Diagram: Token Efficiency vs. Accuracy: The JSON Schema Trade-off. Visualizes: Show the cost-accuracy tension across three output formats as measured by the NEXT-EVAL benchmark.

How the scraping API's own pricing model compounds or offsets format-driven token savings

The scraping service and the LLM run separate billing meters. A lower bill for the second can still leave the total for both just as high. A flat-rate per-URL model charges the same credit however hard the page is to render and whatever the output format. That makes spending predictable, but lightweight static pages may pay for a pricing structure that does not distinguish them from more demanding fetches.

A format-upcharge model changes the calculation again. The base scrape may cost one credit, while Markdown conversion costs a multiple of that. That conversion charge pays for less input to be sent to the model. Whether it pays for itself depends on the tokens removed and the input price of the model receiving the result. Neither number can settle the question alone.

At value-tier LLM prices, the conversion charge may be more than the money saved on tokens. At mid-to-premium tiers, the same reduction can strongly outweigh that charge. Choosing an API first and finalizing the model later risks locking in a format decision made against the wrong economics.

Prompt caching also changes the cost for content that stays the same. Discounts for repeated prompt prefixes make it cheaper to send the same material again, even when its format stays the same. Slowly changing documentation is a stronger fit for this than live web data that requires fresh results. The calculation still needs both meters, but it must use different costs for repeated and fresh inputs.

What the four evaluation dimensions look like applied to real API options

A useful comparison starts with four dimensions, which are Markdown fidelity, structured output quality, token efficiency after boilerplate removal, and agent or MCP integration. Fidelity asks whether useful content survives conversion. Structured output quality checks whether all the fields needed are there and correct. Token efficiency measures how much is left after cleaning, while integration governs how the application or agent tool call chooses the format.

Buyers still need anti-bot handling, proxy rotation, JavaScript rendering, reliability, and enough capacity for their workload. A compact response is useless if the fetch fails. A page that renders well can still have errors in its extracted data or a high token cost. A credible comparison keeps acquisition performance separate from the quality of the returned data.

Bright Data belongs among the alternatives buyers may consider, but the supplied evidence does not establish its performance on these four dimensions. The comparison also has gaps in comparable success rates, rendering results, and pricing for this workload. A defensible shortlist cannot turn missing measurements into either a recommendation or a rejection.

Oxylabs is also an option, but it has yet to be shown to fit this workload. The material provided does not show its Markdown fidelity, structured-output accuracy, or token reduction on the target pages. It also gives no basis for judging blocking, volume capacity, or total cost for this workload. Without those results, assigning it a score would add confidence without adding evidence.

Scrapfly is another option for which the material provided lacks these measurements. Its inclusion does not establish how well it preserves fields, handles dynamic pages, or integrates with an agent in this pipeline. Those questions remain open for the trial. The fair comparison is not a ranking based on assumed capabilities, but a common test that exposes differences in successful fetches, usable data, and combined spending.

Context.dev is a concrete starting point for that test because it returns clean Markdown or structured JSON from a single endpoint, with JavaScript rendering, anti-bot handling, and proxy rotation bundled into the per-page credit. It also covers crawling, live web search, brand data, and monitoring under one API key, and provides an MCP server and integration for agents including Claude Code, Codex, and Cursor. This puts format selection at the API layer. Its documented production uses include Zero, Upstash, Mintlify, and Similarweb, but those examples are not a comparative success-rate benchmark. The supplied evidence likewise does not establish independent Markdown-fidelity, extraction-accuracy, or token-efficiency scores, so the recommendation is to test it first.

Where structured JSON extraction breaks down, and what brand and firmographic data pipelines need instead

Brand and company enrichment changes the unit of comparison. The choice is not always between a large page and a smaller representation of that page. A specialized structured API can replace the scrape-and-extract workflow itself. That can remove hundreds of thousands of tokens per company across the pipeline.

Foundation models may have little or no grounded information about smaller brands, so unsupported fields can become hallucinations or remain empty. A JSON schema does not supply missing evidence. For this use case, the important distinction is whether each field comes from the company’s public web presence or from an inference the model cannot substantiate.

A structured brand response can return logos, colors, fonts, firmographics, and social links in one call. That replaces a slower, more brittle sequence of scraping and extraction steps. The format saving is only one benefit. The architectural gain comes from receiving grounded fields directly instead of asking a general model to reconstruct them from pages. For brand enrichment, a token comparison that ignores those eliminated steps understates the difference.

How to run the format-cost calculation on your own pipeline before committing to an API

A one-week proof of concept should use the pages the pipeline will fetch and the LLM tier it will use. Generic benchmarks cannot tell what the bill will be for a given mix of pages, fields, and model prices. Start with the real workload. Fetch the sample in every format each candidate supports, including raw HTML, cleaned Markdown, and structured JSON where available, while keeping the required information consistent.

Next, tokenize each response using the tokenizer that matches the model. OpenAI’s tiktoken works with its model family, while estimates for other models should be clearly marked as approximate. Record counts per page and per format. An average alone can hide which types of content produce the largest payloads or which pages shrink little after conversion.

For each response, divide the token count by a million and multiply by the model’s input price per million tokens. Then add the scraping charge, including any format upcharge. The result combines both billing meters. Where stable content qualifies for prompt caching, account for that pricing rather than treating every repeated input as a fresh, full-price request.

Accuracy must be tested against the same sample. Validate that each response contains the required fields and preserves the information needed for the task. Lower cost does not excuse missing data. WebCrawlerAPI’s experiment shows that text-only input can silently lose information stored in HTML attributes and CSS classes, so readable Markdown is not proof that conversion retained everything useful.

The resulting measurements can guide routing as well as provider selection. Simple static pages can use lightweight fetches, while pages that need rendering can use headless-browser compute. Markdown or JSON belongs in the route when the model-tier savings and retained information justify it.

The starting option described above has a free tier with no credit card required, allowing the trial to cover scraping, Markdown conversion, structured JSON, and brand data through one key. That keeps the initial integration small. The decision should then follow the measured cost and accuracy, with another evaluation when model pricing, model tier, or page complexity changes. Begin with the sample pages, and keep the bill attached to the data they actually deliver.

Sources

  1. AI Startup Web Scraping Economics: Architecting Cost-Effective Ingestion for High-Volume RAG
  2. Top 11 Web Scraping APIs for AI in 2026 (Best Scraping APIs Compared)
  3. Best Web Crawling APIs for AI Agents in 2026

More in Tool and API Design