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
| Field | Value |
|---|---|
| Account | Anthropic Console (churchwiseai@gmail.com) |
| Console | https://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) |
| Priority | P1 — chatbot primary LLM; losing Anthropic degrades chatbot to OpenAI fallback |
How Used Per Product
| Product / Codebase | Purpose | Model | Interface |
|---|---|---|---|
| churchwiseai-web chatbot | Primary LLM for all church chatbot conversations | claude-haiku-4-5-20251001 | @anthropic-ai/sdk via llm-provider.ts |
| churchwiseai-web chatbot (escalation) | High-stakes conversation escalation path | claude-sonnet-4-6 | @anthropic-ai/sdk via llm-provider.ts |
| churchwiseai-web admin translate | Content translation (call logs, messages) | claude-haiku-4-5-20251001 | Direct REST fetch |
| churchwiseai-web founder tools | Response template improvement suggestions | claude-opus-4-6 | Direct REST fetch |
| Voice agent — Care Agent | Primary LLM for pastoral/grief/prayer calls | anthropic/claude-haiku-4-5-20251001 | LiveKit Agents v1.5 (llm.FallbackAdapter) |
| Voice agent — Coordinator fallback | Fallback when Gemini 2.5 Flash fails | anthropic/claude-haiku-4-5-20251001 | LiveKit Agents v1.5 (llm.FallbackAdapter) |
| Voice agent — Sales/Demo fallback | Fallback when Gemini 2.5 Flash fails | anthropic/claude-haiku-4-5-20251001 | LiveKit Agents v1.5 (llm.FallbackAdapter) |
| pewsearch/web moderation | AI moderation for user-submitted content | claude-haiku-4-5-20251001 | @anthropic-ai/sdk |
| sermon-illustrations support chat | Primary illustration search and chat responses | claude-haiku-4-5-20251001 | Direct REST fetch |
| sermon-illustrations scripts | Batch illustration generation, content scraping | Latest 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
| Variable | Scope | Used By |
|---|---|---|
ANTHROPIC_API_KEY | Server-side only | churchwiseai-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 referencesermon-illustrations/scripts/generate-by-topic-max.mjs— illustrations by topicsermon-illustrations/scripts/generate-lens-content-max.mjs— theological lens contentsermon-illustrations/scripts/run-all-max.mjs— orchestrator that spawns all generatorssermon-illustrations/scripts/regenerate-stubs-max.mjs— regenerate placeholder entriessermon-illustrations/scripts/scrapers/biblical_illustrator.py— scraper usingclaude -pfor parsingsermon-illustrations/scripts/scrapers/maclaren.py— scraper usingclaude -pfor parsing
SDK version pinned in voice agent:
voice-agent-livekit/requirements.lockpinsanthropic==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
fetchtohttps://api.anthropic.com/v1/messages(no SDK) - churchwiseai-web chatbot uses
@anthropic-ai/sdk(proper SDK) viallm-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
| Failure | Symptom | Recovery |
|---|---|---|
ANTHROPIC_API_KEY missing (churchwiseai-web) | Chatbot falls back to OpenAI gpt-4o-mini; founder gets email alert | Add key via echo "sk-ant-..." | vercel env add ANTHROPIC_API_KEY production |
ANTHROPIC_API_KEY missing (voice agent) | Care Agent calls fail; Coordinator loses fallback | Re-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 response | Add key to ITW Vercel env |
| Anthropic 5xx (chatbot) | Auto-failover to OpenAI gpt-4o-mini + email alert | Automatic; check https://status.anthropic.com |
| Anthropic 5xx (voice Care Agent) | Care Agent falls back to Gemini 2.5 Flash | Automatic via LiteLLM fallback list |
| Rate limit | Chatbot queues and likely returns timeout; alert fires | Check Anthropic console for usage spikes |
CLI unavailable (claude -p) | Batch scripts fail — no content generated | Check 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 Path | Model | Cost Basis |
|---|---|---|
| Chatbot (primary) | Haiku 4.5 | ~$0.80 / $4.00 per M input/output tokens |
| Chatbot (escalated) | Sonnet 4.6 | Higher than Haiku; escalation is rare |
| Prompt cache hits | Haiku 4.5 | ~$0.08/M input (cache read) — ~60% savings on system prompt |
| Voice Care Agent | Haiku 4.5 | Per call minute; billed by Anthropic per token |
| Batch generation | Any (via CLI) | $0 API cost — covered by $200/mo Claude Max |
| Translate / founder tools | Haiku 4.5 / Opus 4.6 | Low 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
- OpenAI Integration — automatic fallback LLM; also handles PewSearch and ITW chat
- Google AI Integration — Gemini 2.5 Flash (voice Coordinator primary; Care fallback)
- Cartesia Integration — TTS provider for voice agent (Sonic voices)
- Infrastructure Reference — full env var matrix