Webhooks
Golem webhooks are built on top of Golem Promises. They let an agent generate a temporary public URL that, when POSTed to by an external system, delivers the request body to the agent. The agent is durably suspended while waiting, consuming no resources.
Webhooks are useful for:
- Integrating with webhook-driven APIs such as payment gateways, CI/CD systems, GitHub, and Stripe
- Receiving async callbacks from external services
- Building event-driven workflows where agents react to external events
Webhooks use Golem Promises under the hood. See the Promises page to learn more about the underlying mechanism.
Prerequisites
To use webhooks, your agent must:
- Have an HTTP mount defined in its agent annotations
- Be deployed via the
httpApisection ingolem.yaml
Creating a webhook
TypeScript
To create a webhook, call createWebhook. The returned object provides the public URL and can be awaited to receive the incoming payload:
import { createWebhook } from "@golemcloud/golem-ts-sdk"
type MyEvent = {
action: string
resourceId: string
}
async function waitForCallback(): Promise<MyEvent> {
const webhook = createWebhook()
const url: string = webhook.getUrl()
// Send `url` to the external system to POST to
const payload = await webhook
const result: MyEvent = payload.json()
return result
}Webhook URL structure
When a webhook is created, Golem generates a URL with the following format:
https://<domain>/<prefix>/<suffix>/<id><domain>— the domain of the HTTP API deployment<prefix>— defaults to/webhooks, customizable via thewebhookUrlfield in thehttpApideployment configuration ingolem.yaml<suffix>— defaults to the agent type name in kebab-case (e.g.,my-webhook-agent), customizable viawebhookSuffixin agent annotations<id>— a unique identifier for this particular webhook instance
Customizing the webhook URL
You can customize the webhook URL suffix using the webhookSuffix annotation on your agent:
TypeScript
@agent({ mount: "/workflow/{id}", webhookSuffix: "/workflow-hooks" })Calling the webhook
The webhook URL expects a POST request with an arbitrary body. When the external system sends the POST request, the awaiting agent resumes and receives the payload.
The payload object provides helpers to access the data in different formats:
- Raw bytes — the unprocessed request body
- String — the request body decoded as a UTF-8 string
- JSON — the request body parsed as JSON into a typed value
Configuring webhook URL in golem.yaml
To configure the base URL for webhooks and deploy agents with webhook support, use the httpApi section in golem.yaml:
httpApi:
deployments:
local:
- domain: my-app.localhost:9006
webhookUrl: http://my-app.localhost:9006
agents:
WebhookAgent: {}The webhookUrl field sets the base URL that Golem uses when generating webhook URLs. This should match the publicly accessible address of your deployment so that external systems can reach the webhook endpoints.