PlatformXeDocs
Get API Key

Custom Events

Tenant-defined events — register a typed schema, emit payloads, and route them through the bus.

The client.events.custom namespace lets tenants register their own typed event shapes with PlatformXe, emit payloads against them, and have them delivered to subscribers (webhooks and federation peers; workflow triggers on custom events are being added). Schemas are JSON Schema 2020-12 (OpenAPI 3.1 component schemas accepted as a strict superset). Available in TypeScript, Python, Go, and Terraform.

SDKInstallNamespace
TypeScriptnpm install @caldera/platformxe-sdkclient.events.custom
Pythonpip install "platformxe @ git+https://github.com/calderaxe/platformxe-python@v1.7.0" (not on PyPI yet)client.events.custom
Gogo get github.com/calderaxe/platformxe-goclient.Events.Custom
Terraformsource = "calderaxe/platformxe"platformxe_custom_event

Plan tiers

TierRegister your ownEmit genericEmit registeredMonthly emitsVersioning
Free—✅—1,000—
Basicup to 5✅✅10,000latest only
Proup to 25✅✅100,000full semver
Enterpriseunlimited✅✅unlimitedfull semver + federation

Every organisation is auto-seeded with the platform-provided platformxe.generic catch-all event so even Free-tier tenants can experiment with the engine without registering anything first. Use the kind field on the generic payload to route to the correct subscriber.

Quick start — emit the generic event (Free-tier friendly)

await client.events.custom.emit({
  name: 'platformxe.generic',
  payload: {
    kind: 'user.signed_up',
    summary: 'New user joined',
    data: { userId: 'usr_123', plan: 'free' },
  },
});
client.events.custom.emit(
    name="platformxe.generic",
    payload={
        "kind": "user.signed_up",
        "summary": "New user joined",
        "data": {"userId": "usr_123", "plan": "free"},
    },
)
_, err := client.Events.Custom.Emit(platformxe.EmitCustomEventInput{
    Name: "platformxe.generic",
    Payload: map[string]interface{}{
        "kind":    "user.signed_up",
        "summary": "New user joined",
        "data":    map[string]interface{}{"userId": "usr_123", "plan": "free"},
    },
})

Register a typed event (Basic+)

Schemas are immutable per (namespace, name, version). Evolve a shape by registering a new version — bump rules: patch must be byte-equal except for description; minor must be backwards-compatible; major is free-form.

await client.events.custom.register({
  namespace: 'lettings',
  name: 'property.favorited',
  version: '1.0.0',
  status: 'published',
  description: 'Fired when a customer favorites a property',
  payloadSchema: {
    type: 'object',
    properties: {
      propertyId: { type: 'string', maxLength: 64 },
      subjectId:  { type: 'string', maxLength: 64 },
      favoritedAt: { type: 'string', format: 'date-time' },
    },
    required: ['propertyId', 'subjectId'],
    additionalProperties: false,
  },
});
resource "platformxe_custom_event" "property_favorited" {
  namespace = "lettings"
  name      = "property.favorited"
  version   = "1.0.0"
  status    = "published"

  payload_schema = jsonencode({
    type = "object"
    properties = {
      propertyId  = { type = "string", maxLength = 64 }
      subjectId   = { type = "string", maxLength = 64 }
      favoritedAt = { type = "string", format = "date-time" }
    }
    required             = ["propertyId", "subjectId"]
    additionalProperties = false
  })
}

Emit a registered payload

const result = await client.events.custom.emit({
  name: 'lettings.property.favorited',
  payload: {
    propertyId: 'p_123',
    subjectId: 'sub_456',
    favoritedAt: '2026-05-04T10:00:00Z',
  },
  // Optional: pin to a specific version. Omit to route to latest published.
  version: '1.0.0',
});

result.canonicalName; // 'TENANT_CUSTOM:org_x:lettings.property.favorited@1.0.0'
result.status;        // 'queued'

Delivery is asynchronous. The emit answers 202 queued once the payload is validated and stored with the emit; a durable worker then reads the stored payload and reaches your webhook subscriptions and federation peers after the response, with retries. A failure to deliver is retried, never silently dropped; the emit is marked sent only when every step succeeded. Each subscriber has one delivery record per emit, so a retried or concurrent delivery run does not open a second one; but a subscriber that answers an error, or does not answer before a crash, is sent again by its retry ladder, so delivery is at least once: deduplicate on data.emitId. Lifecycle events (CUSTOM_EVENT_*) you subscribe to are delivered the same way, never inside the request that caused them. Subscribers match the canonical name by exact string. An emit accepted but never started (a platform incident) is picked up again within 30 minutes; an emit accepted before 2026-11-17 whose payload was never stored is marked failed once (emit_not_relayed, a CUSTOM_EVENT_DELIVERY_FAILED event) instead.

Idempotency. Idempotency-Key (header) or idempotencyKey (body) is the emit's key, unique per (organisation, registered event version) for as long as the emit is kept (90 days; 7 years on Enterprise). A retry with the same key answers the original emitId — and if that emit never reached delivery (a 502 bus_relay_failed, a crash), it is handed to delivery again with the originally stored payload. The same key with a different payload answers 422 idempotency_key_reused. An emit accepted before 2026-11-17 that never reached delivery answers 409 emit_not_relayed (send it under a new key). The x-idempotency-key header is the platform's generic HTTP replay cache, separate from this key.

Limits. Payload ≤ 64 KiB; 1,000 emits (and emit dry-runs) per second per event name; the plan's monthly emit quota (counted atomically). Emits are metered (events / custom_emit on your usage page).

Delivery outcome. CUSTOM_EVENT_EMIT_DELIVERED fires when every subscriber has answered 2xx (on the first attempt or after retries); CUSTOM_EVENT_EMIT_DELIVERY_FAILED fires when a subscriber exhausted its retries (or the emit could not be relayed at all) — a final verdict, never followed by DELIVERED for the same emit. A subscription that keeps failing is marked FAILING and counted in health().subscriptions.isolated; it is still sent new events (queued for the once-a-minute retry sweep) and retried, and its next successful delivery makes it ACTIVE again (see Webhook Delivery).

Subscribe a webhook

const sub = await client.events.custom.subscribe({
  name: 'lettings.property.favorited',
  version: '1.0.0', // omit or '*' for every version
  webhookUrl: 'https://your-app.com/webhooks/favorites',
});
sub.canonicalName; // 'TENANT_CUSTOM:org_x:lettings.property.favorited@1.0.0'
sub.secret;        // HMAC secret for verifying deliveries — shown once

POST /api/v1/events/custom/subscribe applies the same webhook URL rules as POST /api/v1/event-subscriptions. The URL must use HTTPS and point at a public host: localhost, *.local / *.internal names, loopback, private (RFC 1918), link-local (including 169.254.169.254) and unique-local IPv6 addresses are rejected, and a hostname must resolve only to public addresses. Anything else returns HTTP 400 with invalid_webhook_url and no subscription is created.

Validate a template before persisting (dry-run)

const verdict = await client.events.custom.dryRun({
  namespace: 'lettings',
  name: 'property.favorited',
  version: '1.0.0',
  payloadSchema: { /* … */ },
});
verdict.valid;          // true
verdict.semverBump;     // 'initial' | 'patch' | 'minor' | 'major'
verdict.schemaHash;     // sha-256 hex
verdict.schemaFlavour;  // 'json-schema-2020-12' | 'openapi-3.1'

Used by terraform plan previews and the SDK type-generation workflow to catch schema problems before they reach the registry. 200 dry-runs per hour per key.

Dry-run an emit (CI)

// TypeScript SDK: pending its next release — Python dry_run_emit, Go DryRunEmit, or POST /api/v1/events/custom/dry-run with mode "emit".
const check = await client.events.custom.dryRunEmit({
  name: 'lettings.property.favorited',
  payload: { propertyId: 'p_123', subjectId: 'sub_456' },
});
check.valid;         // true — or the emit's own error: 400 payload_invalid with errors[], 404, 409, 402, 413
check.canonicalName; // the version the emit would route to

POST /api/v1/events/custom/dry-run with mode: "emit" runs exactly the emit's checks and writes, counts, meters and relays nothing (Python dry_run_emit, Go DryRunEmit).

The dry-run request body (either mode) is read up to 266,240 bytes (260 KiB: room for a 64 KiB schema and a 64 KiB example, each twice over for the indentation a pretty-printed body carries, and the other fields); a larger body is 413 payload_too_large before the rate limit counts it. An emit-mode payload over its own 64 KiB cap is 413 payload_too_large too, as the emit answers.

Publish a draft, edit the description

// TypeScript SDK: pending its next release — Python update / publish, Go Update / Publish, or PATCH /api/v1/events/custom/{id}.
await client.events.custom.update('cer_…', { status: 'published' });          // publish
await client.events.custom.update('cer_…', { description: 'Fired when …' }); // or change the description

PATCH /api/v1/events/custom/{id} takes status: "published", description (a string, or null to clear it), or both (Python update / publish, Go Update / Publish, Terraform: changing status or description in place). On Basic (latest version only), publishing a version archives the event's other live versions; Pro and Enterprise keep every version.

Registering again, limits, schema rules

  • Registering an identical version again is a no-op: 200 with the stored row (201 only when created). A different schema at the same version is 409 version_already_exists.
  • Daily registration cap per plan (5 Basic, 20 Pro, 100 Enterprise; UTC day) → 429 daily_registration_cap_exceeded; 60 registers per hour per key.
  • Schemas: depth ≤ 5 and ≤ 50 declared properties counted under every subschema keyword, ≤ 64 KiB, enums ≤ 500 values, no $async, $schema 2020-12 (older drafts → schema_draft_unsupported).
  • Patterns: pattern and patternProperties keys must be accepted by RE2 (no lookaround, no backreferences) and be valid JavaScript (u flag) regular expressions, ≤ 1,024 characters (unsupported_pattern names the pattern). While the RE2 engine is unavailable, every pattern is refused, and a stored event with a pattern answers 404 event_not_registered until it is back. Bound long strings with maxLength.
  • Bounded validation cost: uniqueItems needs maxItems ≤ 100 on the same schema unless its items are scalar-typed (schema_unique_items_unbounded); $ref must point inside the schema (#/$defs/…), may not be recursive, and the schema may expand to at most 2,000 subschemas once every $ref is followed (schema_ref_not_local, schema_ref_recursive, schema_ref_expansion_too_large); anyOf / oneOf / allOf list at most 20 subschemas each (schema_too_many_branches), an enum at most 500 values, patternProperties at most 10 patterns (schema_too_many_patterns); $id, $anchor and $dynamicAnchor are accepted on the root only (schema_id_not_allowed); and the estimated evaluation cost (subschemas × enum / pattern work × the maxItems / maxProperties of every enclosing array and object, 100 when unbounded) must stay under a fixed budget (schema_too_costly: bound your arrays and objects). Validation reports the first failing keyword only.
  • Validation time budget: every payload (and payloadExample) is validated off the request thread with a 250 ms budget; past it the answer is 422 VALIDATION_TIMEOUT and nothing is stored or counted.
  • Events registered before these rules keep working: they are validated under the same 250 ms budget and listed in health().needsReview with the reason, so you can register a new version that passes the rules.
  • GET /api/v1/events/custom is paginated: limit (1..200, default 100) and offset; the answer carries pagination.hasMore.
  • An archive or publish takes effect on every instance at once.

Health & usage

const h = await client.events.custom.health();
h.plan;                      // 'BASIC'
h.registrations.used;        // 4
h.registrations.limit;       // 5 (or null when plan is unlimited)
h.emits.thisMonth;           // 9_812
h.emits.monthlyLimit;        // 10_000 (or null)
h.registrations.createdToday; // registrations made today (UTC)
h.recentFailures;            // last 10 emits that could not be delivered
h.subscriptions;             // { byStatus, isolated, recentDeliveryFailures }
h.needsReview;               // [{ id, canonicalName, reason }] live events registered before the current schema rules
h.patternEngine;             // 're2' — or 'native-guarded' while RE2 is unavailable (patterns refused)

Sub-resources

Two opt-in sub-namespaces extend the base client.events.custom surface:

  • client.events.custom.marketplace — (Pro+) publish a registered event for other tenants to fork into their own org. Browsing is open to all plans; publishing and forking are Pro+. See Marketplace.
  • client.events.custom.federation — (Enterprise only) push live emit traffic to peer Enterprise orgs through bus-level fan-out. An owner creates a group, invites peers, and declares per-version pushes; the platform re-emits on each accepted peer's canonical name automatically. Since 1.5.0 — Pattern 3: peers can also be arbitrary HTTPS endpoints addressed by URL + HMAC secret, useful when the receiving system isn't on PlatformXe. See Federation.

These are entirely separate flows from client.permissions.federation (the v1.x.x admin permissions cross-app sync) — different concept, different access path.

Reference — namespaces & naming

  • Namespace — ^[a-z][a-z0-9_-]{1,30}$. Reserved namespaces (identity, fraud, permissions, messaging, webhooks, workflows, auth, platform, platformxe, events, subscriptions, domains, templates, generic) are blocked globally. Tenants can only register under namespaces on their org's allowlist — seeded with the org slug at onboarding (and by a daily repair job); PlatformXe operations grant additional namespaces (an audited admin action — ask support).
  • Name — ^[a-z][a-z0-9_.-]{1,60}$. Dots in names are allowed (e.g. property.favorited).
  • Version — strict MAJOR.MINOR.PATCH (no prereleases or build metadata). Single-step bumps only.
  • Schema caps — depth ≤ 5, total properties ≤ 50 (across all nested levels). Payload size ≤ 64 KiB.
  • Canonical name — TENANT_CUSTOM:<organizationId>:<namespace>.<name>@<version>. Org id in the bus name guarantees strict isolation between tenants.

Reference — error codes

CodeStatusCause
invalid_namespace400Namespace fails the regex
reserved_namespace400Tried to use a globally-reserved namespace
namespace_not_allowed400Namespace not on this org's allowlist
VALIDATION_ERROR400A required field is missing or a query / PATCH value is invalid
BAD_REQUEST400The body is not JSON / not an object
invalid_name / invalid_version_format400Shape error
invalid_description400Description over 2,000 characters
schema_draft_unsupported400$schema older than 2020-12
schema_too_large / schema_enum_too_large400Schema over 64 KiB / an enum over 500 values
schema_async_unsupported400$async is not accepted
unsupported_pattern400A pattern RE2 cannot run (lookaround, backreference) or over 1,024 characters
invalid_payload_example / payload_example_too_large400Example not an object, has a __proto__ key, or over 64 KiB
validation_failed400Template dry-run failed (errors[])
invalid_idempotency_key400Key empty or over 255 characters
invalid_version / invalid_webhook_url400Subscribe: bad version or webhook URL
UNAUTHORIZED401Missing or invalid API key
FORBIDDEN403Scope missing or key without an organisation
CUSTOM_EVENTS_REGISTRATION_NOT_AVAILABLE402Registering needs Basic+
CUSTOM_EVENTS_EMIT_RESTRICTED402Free emits platformxe.generic only
daily_registration_cap_exceeded429Daily registration cap
RATE_LIMITED429Route rate limit
event_not_found / NOT_FOUND / organization_not_found404Registration or organisation not found
cannot_publish_archived_event / cannot_update_archived_event409Archived registrations cannot change
cannot_modify_generic_event403The generic event's description is fixed
idempotency_key_reused422Same key, different payload
emit_not_relayed409A pre-2026-11-17 emit that never reached delivery; send it under a new key
schema_unique_items_unbounded / schema_ref_not_local / schema_ref_recursive / schema_ref_expansion_too_large / schema_too_many_branches / schema_too_many_patterns / schema_id_not_allowed / schema_too_costly400Schema validation cost is unbounded
VALIDATION_TIMEOUT422Validating the payload or payloadExample took longer than 250 ms
event_schema_invalid409The registered schema no longer compiles; register a new version
federated_event_not_emittable403A federated type (fed-*) is emitted only by its source organisation
INTERNAL_ERROR500Try again later
cannot_register_generic_event400Tenants cannot self-register platformxe.generic
version_already_exists409That version exists with a different schema (identical: 200 no-op)
version_downgrade / version_invalid_jump400Semver bump issue
patch_must_be_byte_equal400Patch bump changed the schema beyond description
minor_must_be_backwards_compatible400Minor bump is breaking
schema_too_deep / schema_too_wide400DoS guard tripped
invalid_json_schema400Ajv compile error
payload_example_does_not_match_schema400Example doesn't satisfy own schema
registration_quota_exceeded402Plan cap hit
event_not_registered404Emit target not found / not published
event_not_published409Emit target is draft or archived
payload_invalid400Emit payload fails the registered schema, or holds a NUL character or an unpaired surrogate (keyword: unstorableText)
payload_too_large413Payload > 64 KiB
chain_depth_exceeded422Workflow chain hit the platform's 50-deep cap
monthly_emit_quota_exceeded402Monthly emit ceiling reached
bus_relay_failed502Stored but not handed to delivery — retry with the same Idempotency-Key
cannot_archive_generic_event403Generic catch-all is system-managed

Lifecycle — what fires when

Every state transition emits a platform event so subscribers (drift detection, federation push, audit, billing meter, ops alerts) stay in sync. The full catalog is in docs/platformxe-tenant-custom-events-lifecycle-events.md. At a glance:

  • Registration: CUSTOM_EVENT_REQUESTED → CUSTOM_EVENT_VALIDATED → CUSTOM_EVENT_PERSISTED → CUSTOM_EVENT_MATERIALISED → CUSTOM_EVENT_REGISTERED.
  • Emit: CUSTOM_EVENT_EMIT_REQUESTED → CUSTOM_EVENT_EMIT_RELAYED → CUSTOM_EVENT_EMIT_DELIVERED (or …_DELIVERY_FAILED).
  • Failure: CUSTOM_EVENT_VALIDATION_FAILED / CUSTOM_EVENT_EMIT_REJECTED / CUSTOM_EVENT_QUOTA_EXCEEDED.
  • Infra: CUSTOM_EVENT_GENERIC_SEEDED, CUSTOM_EVENT_INVALIDATED, CUSTOM_EVENT_CHAIN_TRUNCATED.