Configure Buddy AI with Anthropic Claude API and set up automated insight generation via cron jobs (daily, weekly, monthly). Use when setting up Buddy AI, configuring cron jobs, or troubleshooting AI insights.
Configure Buddy AI for automated financial insights using Anthropic's Claude API.
Buddy AI Setup:
- [ ] Add ANTHROPIC_API_KEY to .env
- [ ] Install anthropic package (>=0.40.0)
- [ ] Create database tables (weekly_reflections, etc.)
- [ ] Test manual insight generation
- [ ] Set up 3 cron jobs (daily, weekly, monthly)
- [ ] Create logs directory
- [ ] Verify cron jobs installed
# Add to .env file
echo "ANTHROPIC_API_KEY=sk-ant-your-key-here" >> .env
Get key from: https://console.anthropic.com/
source .venv/bin/activate
pip install anthropic>=0.40.0
sqlite3 budget_buddy.db < backend/database/migrations/create_buddy_insights_tables.sql
Verify:
sqlite3 budget_buddy.db ".tables" | grep -E "weekly|reflection"
Should show:
# Test daily insight
python backend/scripts/generate_buddy_daily.py
# Test weekly insight
python backend/scripts/generate_buddy_weekly.py
# Test monthly insight
python backend/scripts/generate_buddy_monthly.py
Expected output:
Generating daily insight...
Fetched 42 transactions from last 7 days
Calling Claude API...
Insight saved to database
Done!
# Edit crontab
crontab -e
# Add these 3 lines (use absolute paths):
0 6 * * * /full/path/to/.venv/bin/python /full/path/to/backend/scripts/generate_buddy_daily.py >> /full/path/to/logs/buddy_daily.log 2>&1
0 6 * * 1 /full/path/to/.venv/bin/python /full/path/to/backend/scripts/generate_buddy_weekly.py >> /full/path/to/logs/buddy_weekly.log 2>&1
0 6 1 * * /full/path/to/.venv/bin/python /full/path/to/backend/scripts/generate_buddy_monthly.py >> /full/path/to/logs/buddy_monthly.log 2>&1
Schedule:
mkdir -p logs
# Check cron jobs
crontab -l | grep buddy
# Should show 3 lines
Model: claude-sonnet-4-20250514
Max Tokens: 1024
Temperature: 0.7
Rate Limit: 1 refresh per insight type per day
Config file: /backend/config/buddy_config.py
Customize model, tokens, or temperature if needed.
Daily (generate_buddy_daily.py):
Weekly (generate_buddy_weekly.py):
Monthly (generate_buddy_monthly.py):
# Check format (should start with sk-ant-)
grep ANTHROPIC_API_KEY .env
# Verify at console.anthropic.com
# Regenerate if needed
# Run manually to see errors
python -u backend/scripts/generate_buddy_daily.py
# Check logs
tail -100 logs/buddy_daily.log
# Verify transactions exist
sqlite3 budget_buddy.db "SELECT COUNT(*) FROM transactions WHERE date >= date('now', '-7 days');"
# View cron logs (macOS)
log show --predicate 'process == "cron"' --last 1h
# Verify absolute paths match
which python # Should match crontab path
# Test cron syntax at https://crontab.guru/
# Make script executable
chmod +x backend/scripts/generate_buddy_daily.py
# Make logs writable
chmod 755 logs/
import anthropic
import os
from dotenv import load_dotenv
load_dotenv()
client = anthropic.Anthropic(api_key=os.getenv('ANTHROPIC_API_KEY'))
response = client.messages.create(
model='claude-sonnet-4-20250514',
max_tokens=100,
messages=[{'role': 'user', 'content': 'Say hello!'}]
)
print(response.content[0].text)
sqlite3 budget_buddy.db "
SELECT week_start_date, substr(spending_summary, 1, 100)
FROM weekly_reflections
ORDER BY created_at DESC
LIMIT 1;
"
Complete cron configuration and troubleshooting: See CRON_SETUP.md
Includes:
/backend/config/buddy_config.py - Configuration/backend/scripts/generate_buddy_*.py - Generation scriptsJanuary 1, 2026