API Reference
Cloudflare Pages Function endpoints for the Owner Chat widget.
Chat Endpoints
/api/chat/aiMain AI conversation endpoint — sends messages to Claude Haiku
Input: { messages: [{ role, content }] }
Output: { reply, tool_call?: { name, result } }
Model: claude-haiku-4-5-20251001, max 400 tokens
Tools: create_lead, handoff_to_human
/api/chat/sendSend conversation to Slack for human handoff
Input: { messages, visitorInfo?: { name, phone } }
Output: { thread_ts } (Slack thread timestamp for polling)
Posts formatted conversation history to the configured Slack channel.
/api/chat/messages?thread=THREAD_TSPoll Slack thread for team replies
Returns only human replies (excludes bots). Client polls every 4 seconds.
Output: [{ text, user, ts }]
/api/chat/statusCheck if team members are online via Slack presence
Output: { online: boolean }
Checks presence of CHAT_RESPONDER_IDS. Cached 60 seconds in Cloudflare KV.
Utility Endpoints
/api/healthHealth check — returns { status: 'ok' }
/api/sentry-testTest Sentry error tracking integration
CORS Configuration
All /api/ routes have CORS middleware applied. Allowed origins:
https://ownerinspections.com.auhttps://chat.ownerinspections.com.auhttp://localhost:3000(development)
Configured via ALLOWED_ORIGINS environment variable. Handles preflight OPTIONS requests.