TypeScript SDKReference

Webhook Types

TypeScript types for outbound and inbound webhook handling.

See Webhooks for usage.

WebhookEvent

enum WebhookEvent {
  COMPLETED = 'completed',
  FAILED    = 'failed',
  CANCELED  = 'canceled',
  STARTED   = 'started',
}

Webhook Class

class Webhook {
  readonly url: string;
  readonly events: readonly WebhookEvent[];
  
  constructor(url: string, events: WebhookEvent[]);
  toJSON(): WebhookPayload;
}
MemberTypeDescription
urlstringCallback URL.
eventsreadonly WebhookEvent[]Events to subscribe to.
.toJSON()WebhookPayloadSerialize for API calls.

WebhookListener Class

class WebhookListener {
  on(route: WebhookRoute, handler: (prediction: PredictionResponse) => void | Promise<void>): this;
  off(route: WebhookRoute, handler: Function): this;
  handle(rawBody: string, headers: Record<string, string>): Promise<PredictionResponse>;
  handleRequest(request: Request): Promise<Response>;
  dispatch(prediction: PredictionResponse): Promise<void>;
}

See Inbound Webhooks.

MethodDescription
.on(route, handler)Register a handler. Alias: listen().
.off(route, handler)Remove a handler.
.handle(rawBody, headers)Verify + parse + dispatch.
.handleRequest(request)Web RequestResponse.
.dispatch(prediction)Skip verification, run handlers directly.

WebhookRoute

type WebhookRoute =
  | WebhookEvent
  | `prediction.${PredictionStatus}`
  | 'prediction.*'
  | '*'

WebhookVerifyOptions

interface WebhookVerifyOptions {
  mode?: 'general' | 'enterprise';
  secret?: string;
  apiKey?: string;
}
FieldTypeDescription
mode'general' | 'enterprise''general' uses sk-… key; 'enterprise' uses dashboard secret.
secretstringEnterprise webhook secret.
apiKeystringPlatform API key (for 'general' mode).

WebhookListenerOptions

interface WebhookListenerOptions {
  mode?: 'general' | 'enterprise';
  verifySignature?: boolean;
  secret?: string;
  apiKey?: string;
}
FieldTypeDefaultDescription
mode'general' | 'enterprise''general'Verification mode.
verifySignaturebooleantrueEnable HMAC-SHA256 verification.
secretstringEnterprise secret.
apiKeystringPlatform API key.
  • SDK Webhooks — Complete webhooks implementation guide
  • Webhooks API — API webhook concepts and event types
  • SDK Errors — Error handling including WEBHOOK_SIGNATURE_INVALID

How is this guide?

On this page