Skip to main content

Knowledge > Integrations > Anthropic

Anthropic Integration

Anthropic powers the most critical real-time AI in the portfolio: Claude Haiku 4.5 is the primary LLM for the churchwiseai-web chatbot (all church conversations), and the Care Agent in the voice pipeline (pastoral/grief calls) specifically uses Haiku for its empathetic tone. A separate, cost-free usage path exists for batch content generation: the founder's Claude Max subscription ($200/mo) is accessed via the claude -p CLI command in scripts, so bulk illustration generation and content scraping consume zero Anthropic API credits.

Account Info

FieldValue
AccountAnthropic Console (churchwiseai@gmail.com)
Consolehttps://console.anthropic.com
Claude Max subscription$200/mo — covers CLI (claude -p) usage; API calls are billed separately
SDK (churchwiseai-web)@anthropic-ai/sdk (npm)
SDK (voice agent)anthropic PyPI package (pinned in voice-agent-livekit/requirements.lock)
PriorityP1 — chatbot primary LLM; losing Anthropic degrades chatbot to OpenAI fallback

How Used Per Product

Product / CodebasePurposeModelInterface
churchwiseai-web chatbotPrimary LLM for all church chatbot conversationsclaude-haiku-4-5-20251001@anthropic-ai/sdk via llm-provider.ts
churchwiseai-web chatbot (escalation)High-stakes conversation escalation pathclaude-sonnet-4-6@anthropic-ai/sdk via llm-provider.ts
churchwiseai-web admin translateContent translation (call logs, messages)claude-haiku-4-5-20251001Direct REST fetch
churchwiseai-web founder toolsResponse template improvement suggestionsclaude-opus-4-6Direct REST fetch
Voice agent — Care AgentPrimary LLM for pastoral/grief/prayer callsanthropic/claude-haiku-4-5-20251001LiveKit Agents v1.5 (llm.FallbackAdapter)
Voice agent — Coordinator fallbackFallback when Gemini 2.5 Flash failsanthropic/claude-haiku-4-5-20251001LiveKit Agents v1.5 (llm.FallbackAdapter)
Voice agent — Sales/Demo fallbackFallback when Gemini 2.5 Flash failsanthropic/claude-haiku-4-5-20251001LiveKit Agents v1.5 (llm.FallbackAdapter)
pewsearch/web moderationAI moderation for user-submitted contentclaude-haiku-4-5-20251001@anthropic-ai/sdk
sermon-illustrations support chatPrimary illustration search and chat responsesclaude-haiku-4-5-20251001Direct REST fetch
sermon-illustrations scriptsBatch illustration generation, content scrapingLatest Claude (via Max plan)claude -p CLI

Chatbot LLM Routing — churchwiseai-web

Defined in churchwiseai-web/src/lib/llm-provider.ts:

Normal conversation: Claude Haiku 4.5 (claude-haiku-4-5-20251001)
Escalated conversation (escalate=true): Claude Sonnet 4.6 (claude-sonnet-4-6)
Anthropic 5xx / timeout: auto-fallback → OpenAI gpt-4o-mini (+ email alert)

The callLLM() function wraps callAnthropic() with a try/catch. Any Anthropic error triggers callOpenAI() automatically. An alert email fires (rate-limited to 1 per 15 minutes) so the founder knows Anthropic degraded. The response object always includes provider: 'anthropic' | 'openai' so downstream tracking can distinguish Haiku vs OpenAI responses.

Prompt caching: The system prompt is tagged with cache_control: { type: 'ephemeral' } via the SDK, enabling Anthropic's prompt caching. This reduces input token costs by approximately 60% on cached prefixes for repeated conversations with the same church config.

Sonnet 4.6 note: Sonnet 4.6 does not support assistant prefill (the json_mode path in llm-provider.ts skips prefill for models starting with claude-sonnet-4 or claude-opus-4). Haiku 4.5 supports prefill for JSON extraction.

Voice Agent LLM Routing — Care Agent

Defined in churchwiseai-web/voice-agent-livekit/verticals/church/agents.py:

Care Agent primary: anthropic/claude-haiku-4-5-20251001
Care Agent fallback: gemini/gemini-2.5-flash
Temperature: 0.4 (more controlled for sensitive pastoral topics)

The Care Agent is intentionally configured with lower temperature (0.4 vs 0.7 for Coordinator) to produce more careful, measured responses during grief/prayer/pastoral conversations. The introduction line is "I'm here with you. What's on your heart?".

The Coordinator and Sales/Demo agents use Gemini 2.5 Flash as primary with Claude Haiku as fallback — the reverse of Care.

Batch Content Generation — Claude CLI Pattern

For all bulk content work (illustration generation, scraping, rewrites), scripts spawn claude -p as a subprocess rather than calling the API:

// Node.js pattern (from ITW scripts):
const env = { ...process.env };
delete env.CLAUDE_CODE_ENTRYPOINT;
delete env.CLAUDECODE;
const child = spawn('claude', ['-p', '--output-format', 'json', prompt], { env });
# Python pattern (from ITW scrapers):
env = os.environ.copy()
env.pop("CLAUDE_CODE_ENTRYPOINT", None)
env.pop("CLAUDECODE", None)
result = subprocess.run(['claude', '-p', prompt], env=env, capture_output=True, text=True)

Why delete CLAUDE_CODE_ENTRYPOINT and CLAUDECODE: These env vars are set by the Claude Code agent shell. If they're present, the child claude process tries to connect to the parent agent context instead of running as a standalone CLI invocation. Deleting them forces the child to behave as an independent claude -p session.

Why use CLI instead of API: The founder pays $200/mo for Claude Max. The Claude CLI runs against the Max subscription — no per-token API billing. Switching batch scripts to use the Anthropic API directly would add significant cost for high-volume content generation (327K+ illustration records).

Key Environment Variables

VariableScopeUsed By
ANTHROPIC_API_KEYServer-side onlychurchwiseai-web (chatbot, translate, founder tools), pewsearch (moderation), sermon-illustrations (support chat), voice-agent-livekit (Care Agent, fallback)

The key is never exposed to the browser. In voice-agent-livekit, it is loaded from the .env file at the project root (deployed to LiveKit Cloud as an agent secret).

No separate key for CLI: The claude -p CLI uses the logged-in Claude Max session, not ANTHROPIC_API_KEY. The two usage paths are completely independent.

CLI Patterns & Gotchas

Always delete entrypoint env vars before spawning claude:

# Shell example:
env -u CLAUDE_CODE_ENTRYPOINT -u CLAUDECODE claude -p "your prompt here"

Script locations (ITW content generation):

  • sermon-illustrations/scripts/generate-by-scripture-max.mjs — illustrations by Bible reference
  • sermon-illustrations/scripts/generate-by-topic-max.mjs — illustrations by topic
  • sermon-illustrations/scripts/generate-lens-content-max.mjs — theological lens content
  • sermon-illustrations/scripts/run-all-max.mjs — orchestrator that spawns all generators
  • sermon-illustrations/scripts/regenerate-stubs-max.mjs — regenerate placeholder entries
  • sermon-illustrations/scripts/scrapers/biblical_illustrator.py — scraper using claude -p for parsing
  • sermon-illustrations/scripts/scrapers/maclaren.py — scraper using claude -p for parsing

SDK version pinned in voice agent:

  • voice-agent-livekit/requirements.lock pins anthropic==0.81.0
  • Do not upgrade without testing; LiveKit Agents SDK depends on specific Anthropic SDK behavior

Direct REST vs SDK:

  • churchwiseai-web translate and founder tools use raw fetch to https://api.anthropic.com/v1/messages (no SDK)
  • churchwiseai-web chatbot uses @anthropic-ai/sdk (proper SDK) via llm-provider.ts
  • ITW support chat uses raw fetch (no SDK installed in that codebase)
  • PewSearch moderation uses @anthropic-ai/sdk

Model ID format:

  • TypeScript/SDK: claude-haiku-4-5-20251001 (bare model ID)
  • Voice agent (LiteLLM routing): anthropic/claude-haiku-4-5-20251001 (prefixed with provider)

Failure Modes & Recovery

FailureSymptomRecovery
ANTHROPIC_API_KEY missing (churchwiseai-web)Chatbot falls back to OpenAI gpt-4o-mini; founder gets email alertAdd key via echo "sk-ant-..." | vercel env add ANTHROPIC_API_KEY production
ANTHROPIC_API_KEY missing (voice agent)Care Agent calls fail; Coordinator loses fallbackRe-deploy with corrected .env in voice-agent-livekit; run lk agent deploy --project cwa-voice --silent
ANTHROPIC_API_KEY missing (PewSearch)Moderation silently skipped (warns in logs, does not crash)Add key to PewSearch Vercel env
ANTHROPIC_API_KEY missing (ITW)Support chat returns null from callClaude; falls back to OpenAI responseAdd key to ITW Vercel env
Anthropic 5xx (chatbot)Auto-failover to OpenAI gpt-4o-mini + email alertAutomatic; check https://status.anthropic.com
Anthropic 5xx (voice Care Agent)Care Agent falls back to Gemini 2.5 FlashAutomatic via LiteLLM fallback list
Rate limitChatbot queues and likely returns timeout; alert firesCheck Anthropic console for usage spikes
CLI unavailable (claude -p)Batch scripts fail — no content generatedCheck claude --version; ensure Claude Code CLI is installed and logged in

Monitoring: The founder dashboard (ProductionMonitoring.tsx) includes an Anthropic status card linking to https://status.anthropic.com and https://console.anthropic.com/settings/billing.

Cost Model / Usage Limits

Usage PathModelCost Basis
Chatbot (primary)Haiku 4.5~$0.80 / $4.00 per M input/output tokens
Chatbot (escalated)Sonnet 4.6Higher than Haiku; escalation is rare
Prompt cache hitsHaiku 4.5~$0.08/M input (cache read) — ~60% savings on system prompt
Voice Care AgentHaiku 4.5Per call minute; billed by Anthropic per token
Batch generationAny (via CLI)$0 API cost — covered by $200/mo Claude Max
Translate / founder toolsHaiku 4.5 / Opus 4.6Low volume; infrequent admin use

Cost rule: Never switch batch content scripts to use ANTHROPIC_API_KEY directly. Always use claude -p CLI for anything that isn't a real-time product feature. This preserves the Max plan advantage for bulk work.

See Also