Webhooks & Event Forwarding
Relevant source files
The following files were used as context for generating this wiki page:
Speakeasy provides a centralized event forwarding system to monitor AI usage, enforce security policies, and maintain audit compliance. The system emits structured webhooks when actors perform actions within an organization or when the platform detects potential risks.
The event architecture enables real-time observability of token costs, tool effectiveness, and sensitive data leaks. Developers use the provided SDKs to ingest these events into external logging or monitoring stacks. Sources: README.md:25-34, hooks/sdk/README.md:45-55
Event Architecture and Outbox Pattern
Speakeasy utilizes a generated event catalog to ensure consistent schema across all notification types. The platform triggers events during resource mutations, security scans, and directory synchronization. Sources: server/internal/outbox/events/catalog_gen.yaml:5-10
Transactional Atomicity
The server ensures atomicity by writing audit log entries inside the same database transaction as the primary mutation. If the audit log write fails, the entire request fails to prevent unlogged actions. Sources: REVIEW.md:52-56
Event Processing Flow
The following diagram illustrates how a mutation generates a webhook event:
The flow ensures that every mutation results in a corresponding audit entry before event delivery occurs. Sources: REVIEW.md:52-56, server/internal/outbox/events/catalog_gen.yaml:12-25
Event Catalog
The Speakeasy event catalog defines the JSON payloads for all supported webhooks. Each event includes common metadata such as organization_id, actor_id, and occurred_at. Sources: server/internal/outbox/events/catalog_gen.yaml:15-40
| Event Name | Description | Key Payload Fields |
|---|---|---|
audit_log.created | Emitted for any resource mutation | actor_id, action, before_snapshot, after_snapshot |
risk_finding.created_v1 | Emitted when a risk is detected | confidence, risk_policy_id, rule_id, tags |
directory_review.opened_v1 | Emitted for directory group changes | directory_group_id, pending_count, source_kind |
assistant_tool_call_event_v1 | Emitted when an assistant uses a tool | acting_surface, subject_id, subject_type |
Sources: server/internal/outbox/events/catalog_gen.yaml:372-385, server/internal/outbox/events/catalog_gen.yaml:966-980, server/internal/outbox/events/catalog_gen.yaml:1040-1055
Webhook Ingestion via SDK
Developers integrate Speakeasy events into their applications using the standard Go SDK. The SDK provides structured methods for ingesting, feedback, and content uploads. Sources: hooks/sdk/README.md:120-130
Ingestion Example
The SDK requires a Gram-Key and a Gram-Project header for authentication. The Ingest operation accepts a HookIngestEvent containing the event type and schema version. Sources: hooks/sdk/README.md:45-75
s := sdk.New(
sdk.WithSecurity(components.Security{
ApikeyHeaderGramKey: "<YOUR_API_KEY_HERE>",
ProjectSlugHeaderGramProject: "<YOUR_PROJECT_SLUG_HERE>",
}),
)
res, err := s.Hooks.Ingest(ctx, operations.IngestHookEventRequest{
Body: components.IngestRequestBody{
Event: components.HookIngestEvent{
Type: components.TypeSkillActivated,
},
SchemaVersion: "v1",
Source: components.HookIngestSource{
Adapter: "custom-relay",
},
},
})
Sources: hooks/sdk/README.md:50-70
Risk and Observability Events
Speakeasy distinguishes between event sources to provide multidimensional analysis. gram.hook.source identifies the calling agent or client, while gram.tool_call.source identifies the downstream MCP server that handled the execution. Sources: server/internal/assistants/testdata/managed_assistant_instructions_05c5372.txt:23-28
Risk Result Detection
When the risk policy engine scans chat messages, it emits risk_finding.created events. For secret-bearing sources like gitleaks, Speakeasy replaces the raw secret with a match_redacted fingerprint. This fingerprint allows organizations to deduplicate leaks without exposing sensitive credentials in the event stream. Sources: server/internal/assistants/testdata/managed_assistant_instructions_05c5372.txt:30-40
Local Development and Forwarding
For local development, Speakeasy provides the assistant-relay Pitchfork daemon. This daemon forwards TCP traffic from the Docker bridge gateway to the local server address. Sources: CONTRIBUTING.md:48-52
- The relay identifies the port from
GRAM_ASSISTANT_RUNTIME_SERVER_URL. - It defaults to the
GRAM_SERVER_URLport if no override exists. - It creates a listener on the bridge gateway to receive callbacks from Docker containers.
- It passes TLS traffic through unchanged to maintain certificate integrity.
Sources: CONTRIBUTING.md:48-55
The relay ensures assistant callbacks reach the local API even when the API listens on loopback. Sources: CONTRIBUTING.md:48-58
Summary
Webhooks and Event Forwarding form the backbone of Speakeasy's observability and security posture. By combining transactional audit logging with a structured event catalog and specialized local relays, the platform provides consistent visibility into AI activities across development and production environments. Sources: README.md:25-35, REVIEW.md:52-60