Multi-Tenancy
SynapseX provides complete multi-tenant architecture for B2B applications, enabling customer isolation, per-tenant customization, and centralized management.
Overviewβ
Multi-tenancy in SynapseX means:
- Data Isolation - Each tenant's data is completely separated
- Custom Models - Per-tenant LoRA adapters and configurations
- Independent Rate Limits - Separate quotas per customer
- Billing Separation - Track usage per tenant
- API Key Management - Unique keys per tenant
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MULTI-TENANT ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Tenant A β β Tenant B β β Tenant C β β Tenant D β β
β β Pharmacy β β Hospital β β Retailer β β Bank β β
β ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ ββββββββ¬βββββββ β
β β β β β β
β β X-Tenant-ID β X-Tenant-ID β X-Tenant-ID β X-Tenant-ID β
β β β β β β
β βΌ βΌ βΌ βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β SYNAPSEX API GATEWAY β β
β β β β
β β β’ Authenticate tenant β β
β β β’ Apply rate limits β β
β β β’ Route to tenant context β β
β β β’ Load tenant LoRA β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββΌββββββββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Tenant A β β Tenant B β β Tenant C β β
β β Context β β Context β β Context β β
β β β β β β β β
β β β’ LoRA v3 β β β’ LoRA v5 β β β’ LoRA v2 β β
β β β’ RAG docs β β β’ RAG docs β β β’ RAG docs β β
β β β’ Settings β β β’ Settings β β β’ Settings β β
β β β’ Feedback β β β’ Feedback β β β’ Feedback β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Tenant Managementβ
Create Tenantβ
import requests
response = requests.post(
"https://api.synapsex.ai/v1/tenants",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"name": "FarmΓ‘cia Santa Casa",
"slug": "farmacia_santa_casa",
"tier": "pro",
"contact_email": "admin@farmacia.com",
"settings": {
"default_model": "synapsex-chat",
"max_tokens_per_request": 2048,
"enable_rerank": True,
"rerank_tier": "quantum_cpu",
"custom_system_prompt": "You are a pharmacy assistant for FarmΓ‘cia Santa Casa."
}
}
)
tenant = response.json()
print(f"Tenant ID: {tenant['id']}")
print(f"API Key: {tenant['api_key']}")
Tenant Tiersβ
| Tier | Rate Limit | Tokens/Day | Features |
|---|---|---|---|
free | 20 req/min | 10,000 | Basic |
pro | 100 req/min | 100,000 | + Quantum CPU |
business | 500 req/min | 1,000,000 | + Training |
enterprise | Custom | Unlimited | + Quantum GPU, SLA |
List Tenantsβ
response = requests.get(
"https://api.synapsex.ai/v1/tenants",
headers={"Authorization": "Bearer sk-admin-xxx"},
params={"tier": "pro", "limit": 50}
)
for tenant in response.json()['tenants']:
print(f"{tenant['name']} ({tenant['slug']}): {tenant['tier']}")
Update Tenantβ
response = requests.patch(
"https://api.synapsex.ai/v1/tenants/tenant_abc123",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"tier": "business",
"settings": {
"rerank_tier": "quantum_gpu"
}
}
)
Delete Tenantβ
response = requests.delete(
"https://api.synapsex.ai/v1/tenants/tenant_abc123",
headers={"Authorization": "Bearer sk-admin-xxx"}
)
Tenant Authenticationβ
Using Tenant API Keyβ
Each tenant gets a unique API key:
from openai import OpenAI
# Tenant-specific client
client = OpenAI(
api_key="sk-farmacia-santa-casa-xxx", # Tenant's API key
base_url="https://api.synapsex.ai/v1"
)
response = client.chat.completions.create(
model="synapsex-chat",
messages=[{"role": "user", "content": "What medications interact with aspirin?"}]
)
Using X-Tenant-ID Headerβ
For platform-level access with tenant routing:
response = requests.post(
"https://api.synapsex.ai/v1/chat/completions",
headers={
"Authorization": "Bearer sk-platform-xxx", # Platform key
"X-Tenant-ID": "farmacia_santa_casa" # Route to tenant
},
json={
"model": "synapsex-chat",
"messages": [{"role": "user", "content": "..."}]
}
)
Tenant Settingsβ
Configuration Optionsβ
response = requests.patch(
"https://api.synapsex.ai/v1/tenants/tenant_abc/settings",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
# Model settings
"default_model": "synapsex-chat-32k",
"max_tokens_per_request": 4096,
"default_temperature": 0.7,
# Reranking
"enable_rerank": True,
"rerank_tier": "quantum_cpu",
"rerank_k": 4,
# Custom behavior
"custom_system_prompt": "You are a helpful assistant for...",
"allowed_topics": ["healthcare", "products", "orders"],
"blocked_topics": ["competitors", "legal_advice"],
# RAG
"enable_rag": True,
"rag_top_k": 5,
"rag_threshold": 0.7,
# Rate limits (overrides tier defaults)
"rate_limit_rpm": 150,
"daily_token_limit": 500000
}
)
Get Settingsβ
response = requests.get(
"https://api.synapsex.ai/v1/tenants/tenant_abc/settings",
headers={"Authorization": "Bearer sk-admin-xxx"}
)
settings = response.json()
print(f"Model: {settings['default_model']}")
print(f"Rerank: {settings['rerank_tier']}")
Per-Tenant RAGβ
Upload Documentsβ
# Register dataset for tenant
response = requests.post(
"https://api.synapsex.ai/v1/tenants/farmacia_santa_casa/datasets/register",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"name": "product_catalog",
"type": "documents",
"data_use": {"allow_rag": True}
}
)
dataset_id = response.json()['id']
# Upload documents
response = requests.post(
f"https://api.synapsex.ai/v1/tenants/farmacia_santa_casa/datasets/{dataset_id}/upload/docs",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"docs": [
{
"doc_id": "med_001",
"title": "Aspirin 500mg",
"text": "Pain reliever and anti-inflammatory. Dosage: 1-2 tablets every 4-6 hours...",
"metadata": {"category": "analgesics", "price": 12.99}
}
]
}
)
RAG in Actionβ
When the tenant makes a request:
# Tenant request
response = client.chat.completions.create(
model="synapsex-chat",
messages=[{"role": "user", "content": "What pain medications do you have?"}]
)
# Response includes RAG context automatically
print(response.choices[0].message.content)
# "We have several pain medications including Aspirin 500mg ($12.99)..."
Per-Tenant LoRAβ
Training Flowβ
- Collect feedback from tenant users
- Trigger training when threshold reached
- Deploy LoRA adapter for tenant
- Automatic loading on inference
# Check training readiness
response = requests.get(
"https://api.synapsex.ai/v1/tenants/farmacia_santa_casa/feedback/stats",
headers={"Authorization": "Bearer sk-admin-xxx"}
)
if response.json()['ready_for_training']:
# Trigger training
response = requests.post(
"https://api.synapsex.ai/v1/tenants/farmacia_santa_casa/train/lora",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={"epochs": 3, "lora_r": 16}
)
print(f"Training job: {response.json()['job_id']}")
LoRA Loadingβ
When a request comes in for a tenant:
1. Request arrives with X-Tenant-ID: farmacia_santa_casa
2. System loads base model + farmacia_santa_casa LoRA adapter
3. Response generated with tenant-specific adaptations
4. LoRA unloaded (or cached for next request)
Usage Trackingβ
Get Tenant Usageβ
response = requests.get(
"https://api.synapsex.ai/v1/tenants/farmacia_santa_casa/usage",
headers={"Authorization": "Bearer sk-admin-xxx"},
params={"period": "current_month"}
)
usage = response.json()
print(f"Requests: {usage['requests']}")
print(f"Tokens: {usage['tokens']}")
print(f"Rerank calls: {usage['rerank_calls']}")
print(f"Training jobs: {usage['training_jobs']}")
Usage by Dayβ
response = requests.get(
"https://api.synapsex.ai/v1/tenants/farmacia_santa_casa/usage/daily",
headers={"Authorization": "Bearer sk-admin-xxx"},
params={"from": "2024-01-01", "to": "2024-01-31"}
)
for day in response.json()['days']:
print(f"{day['date']}: {day['requests']} requests, {day['tokens']} tokens")
All Tenants Usageβ
response = requests.get(
"https://api.synapsex.ai/v1/admin/usage/tenants",
headers={"Authorization": "Bearer sk-admin-xxx"},
params={"period": "current_month", "sort": "tokens_desc"}
)
for tenant in response.json()['tenants']:
print(f"{tenant['name']}: {tenant['tokens']:,} tokens")
Billing Integrationβ
Webhook for Usageβ
Configure webhooks for billing integration:
response = requests.post(
"https://api.synapsex.ai/v1/webhooks",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"url": "https://your-billing-system.com/webhook",
"events": ["usage.daily", "usage.limit_reached"],
"secret": "webhook-secret"
}
)
Usage Webhook Payloadβ
{
"event": "usage.daily",
"timestamp": "2024-01-15T00:00:00Z",
"data": {
"tenant_id": "tenant_abc123",
"tenant_slug": "farmacia_santa_casa",
"period": "2024-01-14",
"metrics": {
"requests": 1500,
"tokens": 450000,
"rerank_calls": 1200,
"quantum_rerank_calls": 800
}
}
}
Self-Service Trialβ
Enable customers to self-onboard:
Trial Configurationβ
response = requests.post(
"https://api.synapsex.ai/v1/admin/trial/config",
headers={"Authorization": "Bearer sk-admin-xxx"},
json={
"enabled": True,
"duration_days": 14,
"limits": {
"requests_per_day": 100,
"tokens_per_day": 10000
},
"features": {
"rerank_tier": "classic",
"enable_rag": True,
"enable_training": False
}
}
)
Trial Signup Endpointβ
POST /public/trial/signup
{
"email": "customer@company.com",
"company_name": "Acme Corp",
"use_case": "Customer support automation"
}
Response:
{
"tenant_id": "trial_xyz789",
"api_key": "sk-trial-xyz789-xxx",
"expires_at": "2024-01-29T00:00:00Z",
"limits": {
"requests_per_day": 100,
"tokens_per_day": 10000
}
}
Best Practicesβ
Securityβ
β Do:
- Use tenant-specific API keys
- Validate X-Tenant-ID on all requests
- Implement IP whitelisting for enterprise
- Audit tenant data access
β Don't:
- Share API keys between tenants
- Allow cross-tenant data access
- Store tenant secrets in logs
Performanceβ
β Do:
- Cache tenant settings
- Pre-load frequently used LoRAs
- Use connection pooling per tenant
- Set appropriate rate limits
β Don't:
- Load LoRA on every request
- Allow unlimited token consumption
- Skip tenant validation
Next Stepsβ
- π API Reference - Tenant endpoints
- π Training - Per-tenant model training
- π¦ RAG Setup - Document management