METHOD 4

๐Ÿค– Claude Haiku 4.5 โ€” Smart Rewrite (V4)

Anthropic's fastest frontier model rewrites existing seo_content into a Billoff article โ€” any language, any country. Exceptional instruction-following, natural prose quality, and locale constraints respected with near-zero mixing errors.

Developer Resources โ€” reflects your saved editor config
Customize Prompt

Overview

V4 rewrites the existing seo_content from your service JSON using Anthropic's Claude Haiku 4.5 (claude-haiku-4-5-20251001). No web search โ€” with 4 article plan choices (Aโ€“D), multi-country locale support, and service registry injection. Distinguishes itself from V2/V3 by exceptional instruction-following and natural prose quality.

Architecture: Existing seo_content โ†’ Rewrite prompt (Plan A/B/C/D) โ†’ Billoff-branded article via Claude (target language from locale).
Strength: Anthropic models are known for clear, human-like writing that closely respects formatting constraints and brand guidelines.
AttributeValue
Modelclaude-haiku-4-5-20251001 (Anthropic)
API endpointapi.anthropic.com/v1/messages
API version headeranthropic-version: 2023-06-01
Web searchNone
Input sourceExisting seo_content from service JSON (up to 4,000 chars)
Article plansAuto / Plan A / Plan B / Plan C / Plan D
StreamingYes โ€” Anthropic SSE (multi-event format)
Max output tokens16 000 (increased to prevent truncation)
Context window200 000 tokens
Avg article length1 800โ€“2 200 words
Avg quality score8โ€“9/10
Cost per articleโ‰ˆ โ‚ฌ0.003โ€“0.005
Avg generation time20โ€“35 seconds
Cost ร— 1 000 articlesโ‰ˆ โ‚ฌ3โ€“5
Cost ร— 50 000 articlesโ‰ˆ โ‚ฌ150โ€“250

Architecture

Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  SERVICE DATA (name, category, website, keywords, etc.) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚  REWRITE INPUT BLOCK             โ”‚
         โ”‚  โ€ข Existing seo_content (~4K ch)  โ”‚
         โ”‚  โ€ข Service metadata               โ”‚
         โ”‚  โ€ข Cancellation methods           โ”‚
         โ”‚  โ€ข Keywords                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
         โ”‚      REWRITE PHASE               โ”‚
         โ”‚  Rewrite Prompt (Plan A/B/C/D)    โ”‚  claude-haiku-4-5-20251001
         โ”‚  + system message (brand)         โ”‚  max_tokens=16000
         โ”‚  + messages [{role:user, ...}]    โ”‚  stream=true
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                        โ”‚
                  FINAL ARTICLE
                  (HTML, ~1 900 words, 14 H2, 2+ tables)

Heading capitalisation โ€” enforced in system message + QUALITY CHECK self-scan: sentence case on every H1/H2/H3/H4. First word capitalised, proper nouns capitalised, everything else lowercase. Post-generation sanitiser applies as final safety net.

Files involved

Proxy โ€” Cloudflare Pages Function

The Anthropic API key is never exposed to the browser. All calls go through /api/claude:

// functions/api/claude.js โ€” key logic
export async function onRequestPost(context) {
  const apiKey = context.env.ANTHROPIC_API_KEY;     // Cloudflare secret
  const body = await request.text();

  const upstream = await fetch('https://api.anthropic.com/v1/messages', {
    method: 'POST',
    headers: {
      'x-api-key':         apiKey,
      'anthropic-version': '2023-06-01',
      'content-type':      'application/json',
      // Auto-added when body.thinking.type === 'enabled' (used by Analysis):
      // 'anthropic-beta': 'interleaved-thinking-2025-05-14'
    },
    body,
  });
  return new Response(upstream.body, {
    headers: { 'Content-Type': upstream.headers.get('Content-Type') }
  });
}

Client request format

// openai.js โ€” streamClaude()
await fetch('/api/claude', {
  method: 'POST',
  body: JSON.stringify({
    model:      'claude-haiku-4-5-20251001',
    max_tokens: 16000,
    stream:     true,
    system:     systemMsg,
    messages:   [{ role: 'user', content: prompt }],
  })
});

Streaming โ€” Anthropic SSE Format

Claude SSE uses a multi-event protocol. Unlike OpenAI (single data: lines), Anthropic sends pairs of event: + data: lines:

// Stream events (in order)
event: message_start
data: {"type":"message_start","message":{"usage":{"input_tokens":2847,"output_tokens":1}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"<h2>1"}}

// ... more content_block_delta events ...

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":1823}}

event: message_stop
data: {"type":"message_stop"}

The parser in streamClaude() accumulates input_tokens from message_start and output_tokens from message_delta, normalising to {prompt_tokens, completion_tokens} for cost calculation.

Prompt

V4 uses the Rewrite Prompt Template (shared with V2/V3) โ€” an English/AU/Billoff adaptation of the Postclic PROMPT_SEO_CONTENT.txt, plus a dedicated system message:

System message

"Senior consumer advocate at Billoff (billoff.com). "
"'Billoff' MUST appear 5+ times. NEVER 'Postclic'. Active voice. "
"Start with <h1> (creative, non-generic title) then <h2> sections. "
"NEVER write: 'I hope', 'As an AI', 'Based on my knowledge', 'Please note'."
// + WRITING PERSONA block appended (e.g. cancellation_specialist)

Why Claude excels at instruction-following

Sections 2, 4โ€“14 are identical to V1/V2/V3. Section 3 uses "Cancellation Considerations" (no competitor table โ€” no live data).

๐ŸŒ Multi-country & Locale Support

V4 is fully locale-aware. Add locale fields to each service row โ€” get_locale(svc) resolves them and injects country, language, currency and consumer-law references directly into both the system message and the rewrite prompt.

FieldExample (AU)Example (BR)Effect in prompt
countryAustraliaBrazilMarket name in mission & rights section
languageEnglishPortugueseLANGUAGE: Portuguese only โ€” all content
currency / currency_symbolAUD / A$BRL / R$Pricing tables and inline amounts
cancel_wordCancelCancelamentoHow-to-cancel section headings + step wording
consumer_lawACL/ACCCCรณdigo de Defesa do Consumidor (PROCON)Consumer rights section โ€” law name injected verbatim into the article

Claude-specific advantage: Claude's strong instruction-following means locale constraints are respected precisely โ€” language mixing and wrong currency symbols are extremely rare.

Output JSON includes cost_usd, cost_eur, elapsed, and stop_reason per article. If stop_reason is max_tokens (truncation), increase MAX_TOKENS or reduce TARGET_WORDS.

Fallback chain: svc.country โ†’ editor config โ†’ script defaults.

Cost Breakdown

Pricing source: docs.anthropic.com/en/docs/about-claude/pricing (verified Feb 2026)

ComponentTokensRateCost (USD)Cost (EUR)
Input (prompt + system)~2 900$0.80 / 1M$0.00232โ‚ฌ0.00213
Output (article)~1 800$4.00 / 1M$0.00720โ‚ฌ0.00662
TOTAL / article~4 700โ€”~$0.0095~โ‚ฌ0.0087
ร— 20 articles$0.190โ‚ฌ0.175
ร— 1 000 articles$9.52โ‚ฌ8.76
ร— 50 000 articles$476โ‚ฌ438

Model pricing: Input $0.80/1M tokens, Output $4.00/1M tokens (claude-haiku-4-5-20251001).

Prompt caching (available on Claude): if you repeatedly send the same system message + service template, Anthropic charges $0.08/1M for cached reads (vs $0.80/1M). At scale with consistent prompts, this can reduce input costs by up to 90%.

ScenarioWithout cacheWith cache (90% reads)
50 000 articles$476 / โ‚ฌ438~$360 / โ‚ฌ331

Python Script Reference

Running the batch generator

# From Billoff/ directory
python scripts/04_generate_v4.py

# Compare all 5 methods on 1 service
python scripts/test_compare_3methods.py

Direct API call (Python)

import anthropic

client = anthropic.Anthropic(api_key="sk-ant-...")
message = client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=8000,
    system="You are a senior SEO writer for Billoff...",
    messages=[{ "role": "user", "content": prompt }],
)
html = message.content[0].text
usage = message.usage   # input_tokens, output_tokens

Environment variables

ANTHROPIC_API_KEY=sk-ant-api03-...
# Cloudflare: set as ANTHROPIC_API_KEY secret in Pages project settings

Pros & Cons

โœ… ProsโŒ Cons
Best instruction-following among V2/V3/V42โ€“3ร— more expensive than V3
Natural, human-like prose qualityNo real-time data (pricing, competitors)
Consistent HTML structure (14 H2 guaranteed)Slower than V3 Gemini Flash
200K token context โ€” handles very long inputsAnthropic-specific SSE format (proxy required)
Word count targets respected within ยฑ10%Training cutoff limits knowledge recency
Prompt caching can cut costs by 90% at scaleMax 64K output tokens (generous, but fixed)
Fully parallelisable (100+ workers)Brand may need explicit system enforcement
Highest Anthropic safety/reliability scoreโ€”

When to use V4

PriorityBest method
Maximum quality + fresh dataV1 (web research)
Best prose quality, no searchV4 Claude โ† here
Best cost/quality balanceV2 or V4
Maximum throughput / lowest costV3 Gemini Flash

All 4 Methods โ€” Head-to-Head

MethodModelWeb searchCost/articleSpeedQuality
V1gpt-4.1 + gpt-5-miniโœ… 4 passes~โ‚ฌ0.10~120s9โ€“10/10
V2gpt-5-miniโŒ~โ‚ฌ0.011~90s9/10
V3gemini-2.5-flashโŒ~โ‚ฌ0.003~20s7โ€“8/10
V4claude-haiku-4-5โŒ~โ‚ฌ0.005~25s8โ€“9/10
After all 4 methods: 2-phase AI analysis โ€” 4ร— Claude Haiku evals (parallel) โ†’ Claude Sonnet 4.6 synthesis (extended thinking). Produces a full scorecard, E-E-A-T deep-dive, tone analysis, category winners, production recommendation and improvement plan. Saved to history automatically.

Writing Persona

A writing persona is appended to the V4 system message for every article. Set PERSONA_ID at the top of the downloaded Python script to switch voice. Claude's superior instruction-following means the persona constraints are respected more precisely than any other method. Available: cancellation_specialist (default), consumer_rights_expert, contract_lawyer, financial_advisor. See V1 Docs for the full persona reference.

๐Ÿ”ฌ AI Comparative Analysis (after all 4 methods)

Once all 4 methods complete, the Lab runs a 2-phase parallel analysis and displays a full comparison report. The analysis is automatically saved to history alongside the article results.

PhaseModelRole
Phase 1 (parallel)claude-haiku-4-5 ร— 4One eval per method โ†’ structured JSON (scores, E-E-A-T, improvements)
Phase 2 (streaming)claude-sonnet-4-6 + Extended ThinkingComparative synthesis โ†’ full HTML report (scorecard ยท E-E-A-T ยท winners ยท recommendation ยท improvement plan)

Note: the /api/claude proxy automatically adds the anthropic-beta: interleaved-thinking-2025-05-14 header when the request body contains thinking.type = "enabled". This is required for Claude's Extended Thinking feature used in Phase 2.

Total cost per analysis: โ‰ˆโ‚ฌ0.04โ€“0.06. See V1 Docs for the full specification.