API Reference

REST API

Base URL: https://pagecortex.vercel.app

All requests accept and return JSON. Authenticated endpoints require a valid Supabase session token in the Authorization: Bearer <token> header.

POST/api/chatPublic

Send a message to a bot and receive an AI answer. Supports streaming via SSE.

Request body

{
  "query": "What is your return policy?",
  "botId": "bot_abc123",
  "stream": false,
  "conversationId": "conv_xyz",   // optional
  "visitorId": "visitor_123",      // optional
  "pageUrl": "https://example.com" // optional
}

Response

{
  "answer": "Our return policy allows returns within 30 days...",
  "sources": [{ "url": "https://example.com/returns", "title": "Returns" }],
  "confidence": 0.92,
  "model": "gpt-4.1-mini",
  "responseTimeMs": 850
}
GET/api/bots?id={botId}Public

Fetch public bot configuration — name, color, welcome message.

Response

{
  "id": "bot_abc123",
  "name": "Support Assistant",
  "primary_color": "#6366f1",
  "welcome_message": "Hi! How can I help?",
  "is_active": true
}
POST/api/botsAuthenticated

Create a new bot for a user.

Request body

{
  "userId": "user_abc",
  "name": "My Bot",
  "model": "gpt-4.1-mini",
  "systemPrompt": "You are a helpful assistant...",
  "welcomeMessage": "Hi! Ask me anything.",
  "primaryColor": "#6366f1"
}

Response

{ "bot": { "id": "bot_xyz", "name": "My Bot", ... } }
GET/api/dashboard/stats?userId={userId}Authenticated

Fetch dashboard stats — bot count, conversations, plan usage.

Response

{
  "stats": { "activeBots": 3, "totalConversations": 412, "resolutionRate": "87.4" },
  "usage": { "plan": "growth", "monthly_message_count": 1420, "monthly_message_limit": 10000 },
  "bots": [...]
}

Rate limits

The /api/chat endpoint is rate-limited to 20 requests per minute per IP. Exceeding this returns HTTP 429 with a retryAfter field in milliseconds.