Skip to content

Cloudflare Worker

Fresh 2026-06-03

File: cloudflare-worker.jsTarget route: andersonhemmat.com/practice-areas/car-accident-lawyers*Status: Code complete — awaiting Cloudflare DNS setup


What It Does

The Worker intercepts incoming requests to the car accident page and:

  1. Classifies the requester as bot or human using multi-signal detection
  2. Humans always receive the normal origin page — zero impact on human visitors
  3. Identified AI bots receive an AI-optimized content variant from KV storage
  4. All bot visits are logged to Cloudflare KV for monitoring

Detection Architecture

flowchart TD
    A[Incoming Request] --> B{Is GET to target path?}
    B -->|No| Z[Pass to origin unchanged]
    B -->|Yes| C[Run classifyRequest]
    C --> D{Signal 1: UA match?}
    D -->|Yes| E[High confidence bot]
    D -->|No| F{Signal 2: Bot score < 30?}
    F -->|Yes| G{Signal 3: ASN in AI list?}
    G -->|Yes| H[Medium confidence bot]
    G -->|No| I[Low confidence bot]
    F -->|No| J{Signal 4: DeepSeek spoof?}
    J -->|Yes| E
    J -->|No| K[Human — pass to origin]
    E --> L[selectVariant - high/med]
    H --> L
    I --> M[selectVariant - low, default md]
    L --> N[Fetch from KV]
    M --> N
    N --> O{Variant in KV?}
    O -->|Yes| P[Serve variant with headers]
    O -->|No| Z
    P --> Q[Log to AI_VISITS_LOG async]

Multi-Signal Classification

The Worker uses 4 independent signals, combining with AND/OR logic:

Signal 1: User-Agent Pattern Matching (Highest Specificity)

27+ patterns covering:

  • OpenAI: GPTBot, ChatGPT-User, OAI-SearchBot
  • Anthropic: anthropic-ai, ClaudeBot, Claude-Web
  • Google: Google-Extended, Gemini, Googlebot-AI
  • Perplexity: PerplexityBot
  • Meta: FacebookBot, Meta-ExternalAgent
  • Microsoft: bingbot, BingPreview
  • Apple: Applebot-Extended
  • Cohere, Amazon, ByteDance (Bytespider), and 10+ others

Signal 2: Cloudflare Bot Score

cf.botManagement.score < 30 = bot-likely. Requires Cloudflare Bot Management plan.

Signal 3: ASN (Autonomous System Number)

Known AI lab datacenter IP ranges:

  • AS8075 (Microsoft/OpenAI), AS16509/AS14618 (AWS/Anthropic), AS15169/AS396982 (Google), AS32934 (Meta), AS138699/AS62567 (ByteDance/DeepSeek), AS14061 (DigitalOcean), AS24940 (Hetzner)

Signal 4: DeepSeek Spoof Detection

DeepSeek spoofs Chrome 58 User-Agent but uses ByteDance/Chinese ASNs. Detection logic:

javascript
function isDeepSeekSpoof(request, asn) {
  const ua = request.headers.get("User-Agent") || "";
  const isFakeChrome58 = /Chrome\/58/.test(ua) && /Mozilla\/5\.0/.test(ua);
  const deepseekASNs = new Set(["AS138699", "AS62567", "AS63086", "AS45090", "AS4134", "AS4837", "AS9808"]);
  return isFakeChrome58 && deepseekASNs.has(asn);
}

Confidence Levels

ConfidenceTriggerAction
HighUA match OR DeepSeek spoofServe variant directly
MediumBot score low AND ASN matchServe variant directly
LowBot score low onlyServe variant (default: md)
NoneNo signalsPass to origin unchanged

Variant Selection

Bot TypeVariantReason
openai, anthropic, google, perplexity, microsoft, cohere, amazon, applemdLLM assistants parse Markdown best
bytedance, deepseekschemaEntity authority focus
ai_assistant_unidentified, ai_crawler_otherhtmlUniversal fallback
low confidencemdSafest option

Response Headers

All variant responses include these headers:

X-Served-By: anderson-hemmat-ai-worker
X-Variant: md|html|schema
X-Bot-Type: openai|anthropic|...
X-Bot-Confidence: high|medium|low
X-Bot-Signals: ua:GPTBot|bot_score:12|...
Cache-Control: no-store
X-Robots-Tag: noindex

noindex Header

The X-Robots-Tag: noindex header prevents AI variants from being indexed by Google as separate pages. The variants are for AI assistant consumption only, not for search indexing.


Logging

All bot visits are logged to KV namespace AI_VISITS_LOG:

json
{
  "timestamp": "2026-06-03T12:00:00.000Z",
  "url": "https://andersonhemmat.com/practice-areas/car-accident-lawyers",
  "botType": "openai",
  "confidence": "high",
  "signals": "ua:GPTBot",
  "botScore": 2,
  "asn": "AS8075",
  "variantServed": "md",
  "userAgent": "GPTBot/1.0",
  "country": "US",
  "ip": "192.0.2.1"
}

Log entries have 90-day TTL. Query examples in the Measurement Framework.


Worker Bindings Required

toml
name = "anderson-hemmat-ai-variants"
main = "cloudflare-worker.js"
compatibility_date = "2026-01-01"

[[routes]]
pattern = "andersonhemmat.com/practice-areas/car-accident-lawyers*"
zone_name = "andersonhemmat.com"

[[kv_namespaces]]
binding = "AI_VARIANTS"
id = "<KV_NAMESPACE_ID>"

[[kv_namespaces]]
binding = "AI_VISITS_LOG"
id = "<KV_LOG_NAMESPACE_ID>"

Human Traffic: Zero Impact

The Worker passes human traffic through to origin unchanged on two conditions:

  1. classification.isBot === false — no bot signals detected
  2. request.method !== 'GET' — non-GET requests (forms, AJAX, etc.) always pass through

Human visitors never see the AI variants. Google's main crawler (Googlebot) also passes through — only Google-Extended (the AI training crawler) receives the variant.

AI Agent Visibility Package — Anderson Hemmat, LLC. Confidential.