This site is not affiliated with or endorsed by Cloudflare, Inc. It showcases deployable experiments across most Cloudflare products.

Blog21 min read

Summarize any webpage with Workers AI

Deep dive into edge URL summarization on Cloudflare - Workers AI models, fetch + extract, AI Gateway, prompts, errors, cost control, and the AI Website Summary experiment.

Abstract generative AI letterform on a dark digital background
Photo by Steve A Johnson on Unsplash

Support teams, research agents, and product features often need the gist of a URL without stuffing full HTML into a context window. A Cloudflare Worker can fetch the page at the edge, extract readable text, and call Workers AI so retrieval and inference stay on Cloudflare’s network - no separate GPU box required.

This post covers pipeline design, product choices (AI Gateway, embeddings, RAG), prompt and extraction quality, and the AI Website Summary experiment as a pasteable reference.

Cloudflare products in this pattern

ProductRoleDocs
WorkersOrchestrate fetch → extract → inferEdge HTTP
Workers AIText summarization models via env.AIModels + binding
AI Gateway (optional)Caching, analytics, provider routingGateway
HTMLRewriterCheap HTML extraction when staticStreaming parser
Browser RenderingJS-heavy pages before summarizeHeadless Chrome
VectorizeNext step: RAG over many docsVector DB
AI SearchManaged RAG alternativeManaged retrieval

The minimal pipeline

A reliable summarizer is four steps:

  1. Validate the URL (http/https only) - same discipline as other catalog APIs
  2. Fetch HTML with timeout and size cap (Fetch API)
  3. Extract main text (strip nav, scripts, chrome)
  4. Infer with a Workers AI text model and return JSON
Client → Worker → fetch(url) → extract text → env.AI.run(model, …) → JSON

Keep the Worker under ~60 seconds end-to-end. Cap extracted characters so prompt size stays predictable and costs do not spike on pathological pages.

Why Workers AI fits this job

From the Workers AI docs:

  • Colocated with fetch - HTML retrieval and inference share the edge
  • Binding-based - env.AI avoids shipping long-lived provider keys for core Cloudflare models
  • Composable - same binding powers tags, translation, embeddings, speech, and image models elsewhere in the catalog

When you outgrow “one model, one route,” look at:

Designing the response contract

Return structured JSON humans and agents can both consume:

{
  "url": "https://example.com/article",
  "title": "Example article",
  "summary": "…",
  "model": "@cf/…"
}

On failure, prefer stable codes aligned with the monorepo convention:

CodeWhen
INVALID_URLMissing or non-http(s) URL
FETCH_ERRORUpstream fetch failed / timed out
EXTRACT_ERRORNo usable text extracted
AI_ERRORModel binding / inference failed

Validate in the route, call lib helpers, return jsonSuccess / jsonError. Do not leak stack traces to clients.

Extraction quality matters more than model choice

Garbage HTML in → vague summary out. Practical tips:

  • Prefer main-content heuristics over dumping body text
  • Drop script, style, nav, and footer blocks early (HTMLRewriter is ideal for streaming transforms)
  • Normalize whitespace; keep headings as soft section cues
  • If the page is JS-only, plain fetch misses the article - use Browser Rendering via Browser Markdown Scrape, then summarize the markdown

For static marketing pages, Metadata Extractor may already give title + description without an LLM. Use Workers AI when you need a true synopsis, not just og:description.

Prompt sketch

Keep prompts explicit and bounded:

Summarize the following webpage text in 5-8 sentences.
Focus on facts; ignore navigation chrome.
If the text is empty or unrelated to an article, say so.

TEXT:
…

Pin the model id in constants so rollouts are deliberate (Workers AI models).

AI Gateway: when to put it in front

AI Gateway adds:

  • Request analytics and error rates
  • Caching for identical prompts (great for repeated URLs)
  • Rate limiting and provider fallbacks in larger architectures

For a single Workers AI binding on one experiment, Gateway is optional. For a product that fans out across models or teams, put Gateway early. The AI Gateway Dashboard experiment shows metadata you can surface in ops UIs.

From summary to a product surface

Once summarization works, nearby experiments extend the same product family:

GoalExperimentCloudflare product
Topic tags for a URLAI Website Tag GeneratorWorkers AI
Q&A over your corpusRAG Mini SearchWorkers AI + Vectorize
Managed RAGAI Search DemoAI Search
Generic model accessCloud AI ProxyWorkers AI
Gateway observabilityAI Gateway DashboardAI Gateway

A common product path: summarize → tag → embed → search. Each step stays a focused Worker you can deploy independently - matching the catalog’s single-responsibility rule.

Cost, latency, and safety

  • Cap input characters and max tokens
  • Cache summaries keyed by URL + content hash (Cache API or KV)
  • Do not send secrets or private HTML to a model without a data policy
  • Rate-limit public endpoints; summarizers get abused as free proxies
  • Prefer allowlisted hosts for internal “summarize our docs” tools

Try the reference

  1. Skim Workers AI get started
  2. Open AI Website Summary
  3. Deploy with the button or wrangler deploy from apps/experiments/ai-website-summary
  4. Call the documented endpoint with a public article URL
  5. Inspect JSON summary and error paths
  6. Add AI Gateway, auth, or caching before production traffic

You should have a working edge summarizer in minutes, then harden it for your traffic profile instead of starting from a blank AI template.

Production checklist

  1. Pin a model id from the Workers AI model catalog.
  2. Cap extracted characters and max tokens.
  3. Cache by URL + content hash (Cache API or KV).
  4. Put AI Gateway in front when you need analytics or cross-team controls.
  5. Escalate JS-heavy pages through Browser Rendering before summarize.
  6. Rate-limit and authenticate public summarizers.
  7. Log model, token estimates, and extract length - not raw private HTML.

Prompt and evaluation loop

Ship with a golden set of 10–20 URLs (news, docs, SPA, empty page, paywall). For each, assert:

  • Summary is non-empty when extract succeeded
  • Refusal / clear message when extract failed
  • Latency under your SLO
  • No leakage of nav chrome phrases (“Accept cookies”, “Sign in”)

Re-run the set when changing models or extractors.

FAQ

Which model should I pick?

Start with a small instruct model for cost, then upgrade only if quality fails your golden set. See Workers AI models.

Is Workers AI enough for RAG?

Summarizing one URL is not RAG. For multi-doc Q&A use Vectorize via RAG Mini Search or AI Search.

Related experiments

These deployable references implement the patterns in this article. Open the docs for API details, then Deploy or clone the source.

  • AI Website Summary - Summarize any webpage with Workers AI on Cloudflare's edge - fetch URL, extract content, return a concise AI summary
  • AI Website Tag Generator - Generate SEO topic tags and keywords for any website using Workers AI - useful for content classification and metadata
  • RAG Mini Search - Mini RAG: Vectorize retrieval + Workers AI grounded answers over experiment docs - retrieval-augmented generation reference
  • Cloud AI Proxy - Call any Workers AI model with a prompt from one public Worker endpoint - simple edge proxy for Workers AI inference
  • AI Gateway Dashboard - Route Workers AI through Cloudflare AI Gateway and surface cache hits, latency, and gateway metadata for observability demos
  • Browser Markdown Scrape - Convert any URL to Markdown or scrape CSS with Browser Rendering quickAction - JS-rendered pages to clean text for LLMs

Cloudflare Experiments is an independent open-source catalog - not affiliated with Cloudflare, Inc.