A lean, production-ready AI Secretary API powered by LangGraph + Groq, backed by Supabase, and designed to be orchestrated by n8n for WhatsApp automation.
WhatsApp User
↓
[n8n: WhatsApp Trigger]
↓
[n8n: HTTP Request → Sarah Brain API (Render)]
↓
[LangGraph Agent + Tools → Supabase DB]
↓
[n8n: WhatsApp Send Message]
↓
WhatsApp User
sarah-brain-api/
├── main.py # FastAPI entrypoint (single /api/v1/brain endpoint)
├── ai_brain.py # Sarah's LangGraph brain — DO NOT MODIFY
├── database.py # Supabase PostgreSQL data layer
├── requirements.txt # Python dependencies
├── render.yaml # One-click Render deploy config
├── .env.example # Environment variable template
└── .gitignore
- Go to https://supabase.com and sign up (free, no credit card).
- Click "New Project" → give it a name (e.g.
sarah-clinic) → set a strong database password → click Create. - Wait ~2 minutes for the project to spin up.
- Go to Project Settings → Database (left sidebar).
- Scroll to "Connection string" → select the URI tab.
- Copy the full URI. It looks like:
postgresql://postgres:[YOUR-PASSWORD]@db.xxxxxxxxxxxx.supabase.co:5432/postgres - Replace
[YOUR-PASSWORD]with the password you set. This is yourDATABASE_URL.
✅ Tables are created automatically on first startup. No manual SQL needed.
# 1. Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Mac/Linux
# 2. Install dependencies
pip install -r requirements.txt
# 3. Create your .env file
cp .env.example .env
# Fill in GROQ_API_KEY, DATABASE_URL, and ADMIN_SECRET
# 4. Run locally
uvicorn main:app --port 8000 --reloadTest it:
curl -X POST http://localhost:8000/api/v1/brain \
-H "Content-Type: application/json" \
-H "X-Admin-Token: your_secret_here" \
-d '{"phone_number": "923001234567", "message": "Hi, I want to book an appointment", "contact_name": "Ahmed Khan"}'Expected response:
{
"status": "success",
"phone_number": "923001234567",
"reply": "Hi Ahmed! Of course, let me check what we have available..."
}- Create a new GitHub repository named
sarah-brain-api. - Push this folder to it:
git init git add . git commit -m "Initial deploy" git remote add origin https://github.com/YOUR_USERNAME/sarah-brain-api.git git push -u origin main
- Go to https://render.com → New → Web Service.
- Connect your GitHub account and select the
sarah-brain-apirepository. - Render will auto-detect
render.yaml. Click Apply. - Go to Environment tab and add these variables:
Key Value GROQ_API_KEYYour Groq API key DATABASE_URLFull Supabase URI ADMIN_SECRETA strong secret (e.g. clinic_secret_2026) - Click Deploy. Wait ~3 minutes.
- Your live URL will be:
https://sarah-brain-api.onrender.com
⚠️ Free Render services "sleep" after 15 minutes of inactivity. n8n's first message after a long gap may take 30–60 seconds. To avoid this, use Render's free "Uptime Robot" integration or upgrade to the $7/month Starter plan.
- Event: Message Received
- No changes needed — this receives the inbound message.
- Method:
POST - URL:
https://sarah-brain-api.onrender.com/api/v1/brain - Headers:
X-Admin-Token: your_secret_here Content-Type: application/json - Body (JSON):
{ "phone_number": "{{ $('WhatsApp Trigger').item.json.messages[0].from }}", "message": "{{ $('WhatsApp Trigger').item.json.messages[0].text.body }}", "contact_name": "{{ $('WhatsApp Trigger').item.json.contacts[0].profile.name }}" }
- Wait:
3 Seconds - Makes Sarah feel human (not instant-bot behaviour).
- Recipient:
{{ $('WhatsApp Trigger').item.json.messages[0].from }} - Text Body:
{{ $('HTTP Request').item.json.reply }}
| Service | Plan | Cost |
|---|---|---|
| Render | Free (or $7/mo Starter for no sleep) | $0–$7 |
| Supabase | Free (500MB, 50k rows) | $0 |
| Groq | Free (fast Llama 3.3) | $0 |
| n8n Cloud | Free (5 workflows, 2500 exec/mo) | $0 |
| Meta WhatsApp | Free (1000 conversations/mo) | $0 |
Total: $0/month for a small clinic.
Q: What if the client gets more than 1,000 conversations/month?
A: Meta charges $0.005–$0.025 per conversation beyond the free tier. For a clinic, this is unlikely.
Q: Can I change Sarah's persona for a different client?
A: Yes. Set the SYSTEM_PROMPT environment variable on Render with the new persona text. No code changes needed.
Q: Is the data safe?
A: All patient data is stored in Supabase (ISO 27001 certified). The API is secured with the ADMIN_SECRET header.