createWebhook
Creates a webhook that can be used to suspend and resume a workflow run upon receiving an HTTP request.
Webhooks provide a way for external systems to send HTTP requests directly to your workflow. Unlike hooks which accept arbitrary payloads, webhooks work with standard HTTP Request objects and can return HTTP Response objects.
createWebhook() creates a public endpoint at /.well-known/workflow/v1/webhook/:token, and the token in that URL is the only authorization performed for incoming requests resuming that webhook. Anyone who has the URL can resume the workflow with a request of their choosing, so verify requests before acting on them or use createHook() behind your own authorized route. See Hook and webhook security.
API signature
Parameters
Signature 1
| Name | Type | Description |
|---|---|---|
options | WebhookOptions & { respondWith: "manual"; } |
Signature 2
| Name | Type | Description |
|---|---|---|
options | WebhookOptions |
Returns
Signature 1
Webhook<RequestWithResponse>Signature 2
Webhook<Request>The returned Webhook object has:
url: The HTTP endpoint URL that external systems can call. On Vercel, it uses the deployment URL. Elsewhere, it'shttp://localhoston thePORTenvironment variable, or on the detected server port whenPORTis unsettoken: The unique token identifying this webhookgetConflict(): A promise that resolves with the conflicting run if another active hook already owns this token, ornullonce the webhook endpoint has been registered. The endpoint is registered alongside the steps the workflow starts at the same time, not ahead of them, so awaitgetConflict()before a step that handsurlto a caller who may request it right away. See Registering a hook before a step uses it.- Implements
AsyncIterable<T>for handling multiple requests, whereTisRequest(default) orRequestWithResponse(manual mode)
When using createWebhook({ respondWith: 'manual' }), the resolved request type is RequestWithResponse, which extends the standard Request interface with a respondWith(response: Response): Promise<void> method for sending custom responses back to the caller.
Use the simplest option that satisfies the prompt:
createWebhook(): generated callback URL, and the default202 Acceptedresponse is finecreateWebhook({ respondWith: 'manual' }): generated callback URL, but you must send a custom body, status, or headerscreateHook()+resumeHook(): the app resumes from server-side code with a deterministic business token instead of a generated callback URL
Common wrong turns
- A callback URL alone does not require
respondWith: 'manual'. - Do not use
RequestWithResponseunless you chose manual mode. - Do not invent a custom callback route when
webhook.urlis the intended callback surface.
Examples
Basic usage
Create a webhook that receives HTTP requests and logs the request details:
Responding to webhook requests (manual mode)
Use this section only when the caller requires a non-default HTTP response. If 202 Accepted is acceptable, use createWebhook() without respondWith: "manual".
Pass { respondWith: "manual" } to get a RequestWithResponse object with a respondWith() method. Call respondWith() from within a step function:
Waiting for multiple requests
You can also wait for multiple requests by using the for await...of syntax.
Related functions
createHook(): Use when the app resumes from server-side code with a deterministic business token.resumeHook(): Pairs withcreateHook()for deterministic server-side resume.defineHook(): Type-safe hook helper.resumeWebhook(): Low-level runtime API. Most integrations should callwebhook.urldirectly instead of adding a custom callback route.