Skip to main content

Integrated Chat Agent — Data Flow & API Key Strategy

The STOA Console includes an integrated chat agent that helps operators manage their APIs through natural language. This guide explains how data flows through the system, how API keys are managed, and how GDPR obligations are met.

Data Processing Flow

User (Console)

│ 1. Chat message (HTTPS, TLS 1.3)

Control Plane API (FastAPI)

│ 2. Auth check (Keycloak OIDC token)
│ 3. Tenant isolation (RBAC + row-level filter)
│ 4. Build prompt (system context + user message)
│ 5. PII detection middleware (pre-send scan)

│ 6. API call (HTTPS, ANTHROPIC_API_KEY from Vault)

Anthropic API (claude-sonnet-4-6)

│ 7. Streaming response

Control Plane API

│ 8. Response logged (without secrets)
│ 9. Conversation stored in PostgreSQL (tenant-scoped)

│ 10. Streamed back (SSE)

User (Console)

Key Properties

  • Tenant isolation: each conversation is scoped to the authenticated user's tenant. No cross-tenant data leakage is possible — queries are filtered by tenant_id at the repository layer.
  • No training: Anthropic API usage is zero-retention by default. Chat data is not used to train models. See Anthropic's data policy.
  • PII pre-scan: the gateway PII middleware scans outbound prompts for sensitive patterns (emails, phone numbers, credit cards) before they reach the LLM provider.

API Key Strategy

Platform-Level Key

STOA uses a single platform-level Anthropic API key stored in HashiCorp Vault and synced to Kubernetes via External Secrets Operator (ESO).

HashiCorp Vault
└── stoa/k8s/anthropic
└── ANTHROPIC_API_KEY

│ ESO sync (1h refresh)

K8s Secret: anthropic-api-key

│ envFrom: secretRef

control-plane-api pod

Why a platform key (not per-tenant)?

ApproachProsCons
Platform keySimple rotation, single billing, centralized controlPlatform bears cost, shared rate limits
Per-tenant keyTenant pays directly, isolated rate limitsKey management complexity, onboarding friction

STOA uses the platform key because:

  1. The chat agent is a platform feature, not a tenant-provided service
  2. Token budgets enforce per-tenant cost control (see below)
  3. Key rotation is a single Vault update, not N tenant operations

Per-Tenant Token Budgets

Each tenant has configurable token limits that prevent any single tenant from exhausting the shared API key:

BudgetDefaultConfigurableEnforcement
Daily token limit100,000 tokensPer-tenant settingAPI returns 429 when exceeded
Monthly token limit2,000,000 tokensPer-tenant settingAPI returns 429 when exceeded
Max conversation length50 messagesGlobal settingOldest messages trimmed from context
Max input tokens per request4,096 tokensGlobal settingRequest rejected if exceeded

Token usage is tracked per tenant in PostgreSQL and exposed in the Console under Settings > Usage.

GDPR Compliance

Data Lifecycle

Message sent ──► Stored in PostgreSQL (tenant-scoped)

├── Active: available in conversation history

├── 90 days: automatic purge (background worker)

└── On tenant deletion: cascade delete (all conversations)

Right to Deletion

TriggerScopeMechanism
User requests deletionSingle conversationDELETE /v1/conversations/{id} — hard delete
User requests full erasureAll conversationsDELETE /v1/users/{id}/conversations — cascade
Tenant deletionAll tenant dataPostgreSQL ON DELETE CASCADE on tenant_id FK
90-day retentionExpired conversationsBackground worker (ConversationPurgeWorker)

Data Minimization

  • System prompts do not include tenant secrets, credentials, or PII
  • Conversation context is limited to the current session (no cross-session memory)
  • Anthropic receives only the conversation messages — no tenant metadata, no user identity
  • Logs record conversation IDs and token counts, never message content

Audit Trail

Every chat interaction is logged with:

  • Timestamp, tenant ID, user ID (pseudonymized)
  • Token count (input + output)
  • Model used, latency
  • No message content in logs (stored separately in PostgreSQL with retention policy)

Security Considerations

LayerControl
AuthenticationKeycloak OIDC token required for every request
AuthorizationRBAC: cpi-admin and tenant-admin can use chat; viewer read-only
TransportTLS 1.3 end-to-end (Console → CP API → Anthropic)
Secret storageAPI key in Vault, synced via ESO, never in env files or code
Rate limitingPer-tenant token budgets + global rate limiter middleware
PII protectionPre-send scan blocks sensitive patterns

Configuration

The chat agent is controlled by environment variables on the control-plane-api deployment:

VariableSourceDescription
ANTHROPIC_API_KEYVault (k8s/anthropic)API key for Anthropic
CHAT_AGENT_ENABLEDConfigMapEnable/disable chat feature (true/false)
CHAT_AGENT_MODELConfigMapModel to use (default: claude-sonnet-4-6)
CHAT_DEFAULT_DAILY_LIMITConfigMapDefault daily token limit per tenant
CHAT_RETENTION_DAYSConfigMapDays before automatic purge (default: 90)