RESTRICTED ENTERPRISE API

These endpoints map strictly to the internal Xryzex AI architecture. Access requires authorized JWT Session Cookies (xryzex_session) or master backend headers (x-admin-secret, x-cron-secret).

API Reference

Comprehensive documentation of all operational endpoints driving the Voice Routing, RAG Synthesis, Outbound Pacer, and Ledger Governance.

POST /auth/api/login

Authenticate Client

Validates the client's master phone and dashboard password. If successful, issues an HTTP-only xryzex_session JWT cookie valid for 12 hours.

JSON Body Parameters
phone_number string REQUIRED

The registered telecom string (auto-normalized internally).

password string REQUIRED

The client's secure dashboard password.

REQUEST PAYLOAD
{
  "phone_number": "919876543210",
  "password": "secure_pass_123"
}
RESPONSE (200 OK + Set-Cookie)
{
  "status": "success",
  "message": "Authenticated"
}
POST /auth/api/logout

Terminate Session

Instructs the browser to explicitly delete the xryzex_session cookie, ending dashboard access.

RESPONSE (200 OK)
{
  "status": "success",
  "message": "Logged out"
}
GET /dashboard/api/dashboard/overview

Get Account Overview

Auth: JWT Cookie Required.

Fetches high-level operational statistics including SIP routing numbers, authorized sub-users, and the total size of the AI's Knowledge Base catalog.

RESPONSE (200 OK)
{
  "status": "success",
  "factory_name": "Acme Pipes Ltd",
  "master_phone": "919876543210",
  "sip_number": "918888888888",
  "wa_daily_count": 14,
  "auth_phones_count": 2,
  "catalog_size": 156
}
GET /dashboard/api/dashboard/billing

Get Financial Ledger

Auth: JWT Cookie Required.

Returns the live status of the tenant's prepaid minute bucket, base subscription rent status, next IST billing date, and the 5 most recent payment transactions.

RESPONSE (200 OK)
{
  "status": "success",
  "minutes_remaining": 850,
  "rate_per_minute": 3.00,
  "subscription_status": true,
  "next_billing_date": "2026-08-15T12:00:00Z",
  "recent_transactions": [
    {
      "payment_date": "2026-07-15T10:00:00Z",
      "payment_category": "subscription",
      "amount_paid": 7500.00,
      "status": "success"
    }
  ]
}
GET /dashboard/api/dashboard/campaigns

List Outbound Campaigns

Auth: JWT Cookie Required.

Returns a list of all historical and active outbound dialer campaigns linked to the authenticated client, sorted by creation date.

RESPONSE (200 OK)
{
  "status": "success",
  "campaigns": [
    {
      "campaign_id": "camp_uuid_123",
      "campaign_name": "Diwali Restock",
      "status": "active",
      "total_leads": 2400,
      "calls_made": 1205,
      "orders_taken": 89
    }
  ]
}
POST /outbound/api/dashboard/process-leads

Process Campaign Leads

Auth: JWT Cookie Required. Format: multipart/form-data

The ETL batch ingestion endpoint. Uploads an Excel/CSV file. Pandas dynamic column mapping identifies phone numbers, normalizes telecom strings, and chunks DB insertion (500 rows at a time) to prevent memory timeouts.

Form Data Parameters
campaign_name string REQUIRED

The identifier for the dialer batch.

file UploadFile REQUIRED

Valid extensions: .csv, .xlsx.

RESPONSE (200 OK)
{
  "status": "success",
  "message": "Successfully mapped and loaded 2450 leads.",
  "campaign_id": "camp_uuid_123"
}
POST /outbound/api/dashboard/toggle-dialer

Toggle Dialer Pacer

Auth: JWT Cookie Required.

The Kill-Switch for the async pacer script. Updates the campaign status. If paused, the Cron pacer will instantly halt the initiation of new SIP out-dials.

JSON Body (ToggleRequest)
campaign_id string REQUIRED
action string REQUIRED

Accepts "start" or "pause".

REQUEST PAYLOAD
{
  "campaign_id": "camp_uuid_123",
  "action": "start"
}
RESPONSE (200 OK)
{
  "status": "success",
  "message": "Campaign started successfully."
}
GET /outbound/api/dashboard/terminal-stream

Live Terminal Stream

Auth: JWT Cookie Required.

Powers the dashboard HUD. Fetches the 10 most recently updated leads from the database to display real-time statuses (Dialing, Completed, Follow-Up).

RESPONSE (200 OK)
{
  "status": "success",
  "logs": [
    {
      "customer_name": "Apex Traders",
      "phone_number": "919876543211",
      "call_status": "completed",
      "next_action": "none"
    }
  ]
}
POST /onboarding/api/register

Register New Factory

Auth: x-admin-secret Header Required.

Creates core Supabase rows, triggers SQL 30-day billing cycle creation, and synchronously automates LiveKit Inbound/Outbound SIP Trunk assignments via API.

JSON Body (ClientRegistration)
factory_name REQUIRED
master_phone REQUIRED
sip_number REQUIRED
dashboard_password REQUIRED
base_prompt REQUIRED
authorized_phones Array[String]
RESPONSE (200 OK)
{
  "status": "success",
  "message": "Factory Acme Pipes Ltd registered successfully!",
  "client_id": "uuid-1234..."
}
POST /onboarding/api/process

Synthesize AI Data

Auth: x-admin-secret Header Required. Format: multipart/form-data

Passes massive, unstructured raw data (PDF, XLSX, TXT) to Gemini 2.5 Pro via Vertex AI. Forces strict application/json response MIME-type to structure data perfectly for the RAG database.

Form Data Parameters
filesList[UploadFile]
extra_textstring
RESPONSE (200 OK)
{
  "status": "success",
  "data": {
    "inventory_data": { "Product A": "Available" },
    "pricing_rules": "Flat shipping.",
    "custom_instructions": ""
  }
}
POST /onboarding/api/save

Commit Knowledge Base

Auth: x-admin-secret Header Required.

The Human-in-the-Loop redundancy step. Commits the verified JSON payload directly to the Supabase knowledge_base table, instantly updating the Voice AI's cognitive parameters.

REQUEST PAYLOAD
{
  "client_id": "uuid-1234",
  "inventory_data": { "Product A": "Available" },
  "pricing_rules": "Rules...",
  "custom_instructions": ""
}
RESPONSE (200 OK)
{
  "status": "success",
  "message": "Knowledge base locked and updated!"
}
GET /admin/api/clients

List All Tenants

Auth: x-admin-secret Header Required.

Fetches the master list of all registered clients to populate the God-Mode dashboard dropdowns.

RESPONSE (200 OK)
{
  "status": "success",
  "data": [ { "client_id": "uuid", "factory_name": "Acme", "master_phone": "91..." } ]
}
POST /admin/api/batch-update

Execute Ledger Override

Auth: x-admin-secret Header Required.

The ultimate financial control. Used to manually process physical cash payments, execute the Kill-Switch suspension, or calculate net top-up minutes after resolving grace debts.

JSON Body (BatchUpdateRequest)
client_idsList[UUID]REQUIRED
subscription_statusboolean
top_up_amountfloat
grace_minutesint
account_statusstring ("active"|"suspended")
transaction_referencestring
RESPONSE (200 OK)
{
  "status": "success",
  "message": "Successfully updated accounts and processed logic for 1 clients."
}
POST /webhook/razorpay

Razorpay Integration

Auth: x-razorpay-signature Header Required.

Listens strictly for payment.captured. Performs SHA256 cryptographic signature validation, calculates +30-day IST billing resets, logs the payment to the Vault, and pushes the accounting row to Google Sheets asynchronously.

INTERNAL MATH LOGIC (Python)
elif payment_type == "top_up":
    minutes_bought = int(amount_inr / rate)
    grace_recovered = min(minutes_bought, current_owed)
    net_minutes = minutes_bought - grace_recovered
    
    billing_updates['allocated_minutes'] = current_allocated + net_minutes
    billing_updates['unpaid_grace_minutes'] = current_owed - grace_recovered
POST /webhook/whatsapp

WhatsApp CMS Hub

Auth: Meta Hub Signature.

The inbound pipe for factory owners to message the AI. Validates sender, enforces a 50-message daily limit, compresses the RAG history to the last 15 messages, and triggers Vertex AI Tool-Calling for database queries.

RESPONSE (200 OK)
{
  "status": "ok"
}
Execution continues in BackgroundTasks.
POST /cron/outbound-tick

Trigger Outbound Pacer

Auth: x-cron-secret Header Required.

Fired every 1 minute by GCP Scheduler. Sweeps the database for all 'active' campaigns, safely locks pending leads via FOR UPDATE SKIP LOCKED, and fires mass concurrent LiveKit SIP dialed requests.

RESPONSE (200 OK)
{
  "status": "success",
  "message": "Processed 4 campaigns."
}
-->