METHOD 4

🤖 Claude Haiku 4.5 — Smart Rewrite (V4)

Anthropic's fastest frontier model rewrites existing AU seo_content into a 13-section Billoff article. Precise instruction-following, clean structured prose, near-frontier intelligence.

Developer Resources — reflects your saved editor config
Customize Prompt

Overview

V4 rewrites the existing seo_content from the AU pipeline JSON using Anthropic's Claude Haiku 4.5 (claude-haiku-4-5-20251001). No web search — same logic as step_04 in the Postclic pipeline, adapted for Billoff, English, Australia, with 4 article plan choices (A–D). Distinguishes itself from V2/V3 by exceptional instruction-following and natural prose quality.

Architecture: Existing AU seo_content → Rewrite prompt (Plan A/B/C/D) → Billoff-branded English article via Claude.
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 AU 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)

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',
    },
    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: 8000,
    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

"You are a senior SEO content writer for Billoff (billoff.com). "
"CRITICAL: Always use the brand name 'Billoff'. NEVER write 'Postclic'. "
"Target length: 1,600–2,200 words of pure HTML. "
"Start directly with <h2>. No markdown."

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).

Cost Breakdown

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

ComponentTokensRateCost (USD)Cost (EUR)
Input (prompt + system)~2 900$1.00 / 1M$0.00290€0.00267
Output (article)~1 800$5.00 / 1M$0.00900€0.00828
TOTAL / article~4 700~$0.0119~€0.0109
× 20 articles$0.238€0.219
× 1 000 articles$11.90€10.95
× 50 000 articles$595€548

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

ScenarioWithout cacheWith cache (90% reads)
50 000 articles$595 / €548~$300 / €276

Python Script Reference

Running the batch generator

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

# Compare all 4 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: Gemini 3.1 Pro Preview analyses all articles and produces a comparative table + recommendation (≈€0.04/analysis).