AI Website Tag Generator
Generate SEO topic tags and keywords for any website using Workers AI - useful for content classification and metadata
This is an experimental Worker. Use it as a starting point for your own projects.
The AI Website Tag Generator experiment fetches any webpage, extracts its content, and uses Workers AI to generate topic tags. Built with Hono and TypeScript, it runs on Cloudflare's edge network-no external API keys required.
Features
- Fetch and parse any public webpage
- Extract title and body text from HTML
- Generate topic tags using Workers AI (e.g. Llama 3.1)
- Sub-second responses on the edge
- Accepts full URLs or hostnames (e.g.
https://cloudflare.comorexample.com)
API Reference
GET /tags
Generate topic tags for any webpage.
Prop
Type
Response
tags string[]
An array of topic tags generated from the page content.
Example Request
curl "https://your-worker.workers.dev/tags?url=https://www.cloudflare.com"Example Response
{
"tags": ["technology", "CDN", "security", "edge computing", "DDoS protection"]
}Error Responses
error string
Human-readable error message.
code string
Machine-readable error code.
400 Bad Request - Missing or invalid URL:
{
"error": "Missing or invalid query parameter: url",
"code": "INVALID_URL"
}502 Bad Gateway - Failed to fetch webpage or AI error:
{
"error": "Failed to fetch or generate tags",
"code": "FETCH_OR_AI_ERROR"
}Use Cases
- Content tagging - Auto-tag articles or bookmarks by topic
- SEO and discovery - Suggest categories or related topics from page content
- Link previews - Enrich shared links with topic tags
- Research and curation - Quickly label pages by theme
Limitations
- JavaScript-heavy sites - Only static HTML is fetched; client-rendered content is not executed
- Workers AI limits - Subject to Workers AI usage limits by plan
- Fetch and size limits - Same constraints as other URL-based experiments (timeout, HTML size cap)
Use in your project
Copy these files into an existing Worker. Prefer Deployment to try the full experiment first. Source: apps/experiments/ai-website-tag-generator.
import type { Env } from "../types/env";import { AI_MODEL, MAX_TAG_TOKENS, MAX_TAGS } from "../constants/defaults";/** * Parse AI response into lowercase tags: split on newlines and commas, trim, dedupe, cap. */function parseTags(raw: string): string[] { const seen = new Set<string>(); const tags: string[] = []; const parts = raw .split(/[\n,]+/) .map((s) => s .replace(/^[\d.)\s\-*]+/, "") .trim() .toLowerCase() ) .filter(Boolean); for (const tag of parts) { const normalized = tag.replace(/\s+/g, "-").slice(0, 50); if (normalized && !seen.has(normalized) && tags.length < MAX_TAGS) { seen.add(normalized); tags.push(normalized); } } return tags;}export async function generateTagsWithAi( env: Env, text: string, title: string | null): Promise<string[]> { const prompt = `You are a tag generator. Based on the following webpage content, output 3 to 10 short topic tags. Use single words or short hyphenated phrases (e.g. "machine-learning"). Output ONLY the tags: one per line or comma-separated. No numbering, no preamble, no "Tags:" label, no explanation.${title ? `Page title: ${title}\n\n` : ""}Content:\n${text}`; const out = await env.AI.run(AI_MODEL, { prompt, max_tokens: MAX_TAG_TOKENS, }); const response = (out as { response?: string }).response ?? (out as { result?: string }).result ?? ""; const tags = parseTags(response); return tags.length > 0 ? tags : ["uncategorized"];}Deployment
Deploy
Enable the Workers AI binding (AI) in your Worker settings. The deploy button configures this automatically via wrangler.json. Requires a Cloudflare account with Workers AI enabled.
Test your deployment
curl "https://your-worker.workers.dev/tags?url=https://www.cloudflare.com"Local Development
cd apps/experiments/ai-website-tag-generator
npm install
npm run devTest locally:
curl "http://localhost:8787/tags?url=https://www.cloudflare.com"Cloudflare Features Used
- Workers - Serverless execution environment
- Workers AI - Run LLMs on the edge with the
AIbinding - Fetch API - HTTP client for fetching webpages