Internal
Partner Gateway

Partner Gateway Setup

The Partner API Gateway provides enterprise partners with secure, rate-limited access to Pillexa services.

Partner Authentication

Database Schema

Partner API keys are stored in D1 database:

CREATE TABLE partner_api_keys (
  id TEXT PRIMARY KEY,
  api_key TEXT UNIQUE NOT NULL,
  tenant_id TEXT NOT NULL,
  partner_name TEXT NOT NULL,
  is_active INTEGER DEFAULT 1,
  created_at INTEGER NOT NULL,
  updated_at INTEGER NOT NULL
);

Creating Partner API Keys

  1. Generate a secure API key (minimum 32 characters)
  2. Create partner record in D1 database
  3. Associate API key with tenant ID
  4. Set is_active = 1 to enable

Authentication Flow

  1. Partner sends request with API key and tenant ID
  2. Middleware validates credentials against D1
  3. Partner context attached to request
  4. Route handler executes with partner info

Partner Configuration

Partners can be configured with:

  • Rate limits (requests per minute/hour/day)
  • Allowed services (brand, clinician, pharmacy, shared)
  • Webhook URLs for event notifications
  • Custom metadata

File: packages/api/src/services/partner-config.ts

Service Access Control

Partners can be granted access to specific services:

  • All services (default)
  • Specific services only
  • Service-level permissions

Access is checked before routing requests to backend services.