Skip to main content

AI Gateway Service — Event Schemas

Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · 04 event-driven · standards/NAMING.md

All events follow the platform CloudEvents 1.0 envelope. Event type format: ai_gateway.{aggregate}.{event}.v{N}. NATS subject = event type. All payloads are PHI-safe by default (no raw prompts, no raw outputs, no free-text PHI). DPIA-approved tenants may enable an opt-in secure-retention payload on a separate subject (ai_gateway_secure.*) subject to legal review.

1. Produced events

Event typeAggregateRetentionTriggerPayload fields
ai_gateway.assist.requested.v1AIDecision7yAuth + quota consumedcorrelationId, decisionId, tenantId, actorId, featureKey, resourceType, residency, inputChars, hasInstructions
ai_gateway.assist.completed.v1AIDecision7yProvider returned, provenance stampedcorrelationId, decisionId, tenantId, actorId, featureKey, provenanceId, provider, modelVersion, promptTemplate.key/version, latencyMs, moderation.input, moderation.output, hitlRequired
ai_gateway.assist.failed.v1AIDecision7yAny failure pathcorrelationId, decisionId?, tenantId, actorId, featureKey, reasonCode, provider?, retryable
ai_gateway.decision.created.v1AIDecision7yDecision persisted as draftdecisionId, tenantId, featureKey, state, consumerService, provenanceId
ai_gateway.decision.hitl_queued.v1AIDecision7yDraft requires HITLdecisionId, tenantId, featureKey, assignmentPolicy, queuedAt
ai_gateway.decision.accepted.v1AIDecision7yReviewer accepted or owner finaliseddecisionId, tenantId, featureKey, provenanceId, acceptedBy, acceptedByRole, targetResource
ai_gateway.decision.rejected.v1AIDecision7yReviewer rejected / timeoutdecisionId, tenantId, featureKey, rejectedBy, rejectionReason
ai_gateway.moderation.flagged.v1ModerationFinding3yClassifier above thresholddecisionId, tenantId, featureKey, stage (input|output), categories[], verdict, thresholds
ai_gateway.provider.degraded.v1ProviderRoutingRule1yCircuit breaker openedtenantId?, provider, featureKey?, consecutiveErrors, lastErrorCode, detectedAt
ai_gateway.provider.recovered.v1ProviderRoutingRule1yCircuit closed againprovider, downtimeMs, recoveredAt
ai_gateway.quota.exceeded.v1TenantQuota1yQuota breachtenantId, featureKey, windowSec, limit, attemptedAt
ai_gateway.routing_rule.updated.v1ProviderRoutingRule7yAdmin changed ruletenantId?, featureKey, changes, updatedBy
ai_gateway.prompt_template.published.v1PromptTemplate7yNew version publishedtemplateKey, version, guardrailsHash, publishedBy

2. Consumed events

SubjectSourceReaction
identity.user.disabled.v1identity-serviceRevoke cached tokens, pending HITL review reassignment
tenant.suspended.v1tenant-serviceDisable new assists for tenant; existing reviews retained
config.feature_flag.updated.v1config-serviceInvalidate per-feature cache
config.provider_matrix.updated.v1config-serviceRebuild routing in memory

3. Envelope (CloudEvents 1.0)

{
"specversion": "1.0",
"type": "ai_gateway.assist.completed.v1",
"source": "ghasi/ai-gateway-service",
"id": "uuid",
"time": "ISO8601",
"subject": "dec_01H...",
"datacontenttype": "application/json",
"tenantid": "ten_...",
"actorid": "usr_...",
"correlationid": "uuid",
"data": { "...as table above..." }
}

4. JetStream configuration

StreamSubjectsRetentionStorageReplicas
ai-gateway-eventsai_gateway.*limits — 7yfile3
ai-gateway-opsai_gateway.provider.*, ai_gateway.quota.*limits — 1yfile3
ai-gateway-dlqai_gateway.dlq.*manualfile3

5. Schema versioning

  • All schemas live under packages/@ghasi/event-envelope/schemas/ai_gateway/.
  • Breaking changes emit a new version suffix (.v2); both versions run for ≥1 release.
  • Contract tests validate payload shape on publish and consume.

6. PHI redaction policy

Default subjects must not contain: raw instructions, raw draftText, patient names, addresses, free-text notes, or medication strings. Metrics allowed: character counts, token counts, category scores, resource references (IDs only).