Skip to main content
This article explains how external systems can sign requests sent to an Agent Studio webhook trigger. It covers the webhook credentials, request format, signing procedure, validation rules, API responses, and code examples required to integrate an external system with the webhook trigger.

Credentials

The webhook URL and signing secret are displayed once in the Webhook dialog when the trigger is created or its secret is regenerated.

Request

Send an HTTP POST request to the webhook URL.
Include the following headers and request body:

Signing procedure

Follow these steps to generate a signature for each webhook request.
  1. Serialize the request body: Convert the JSON body into a string and retain the exact bytes.
  2. Generate the timestamp: Get the current Unix timestamp in seconds (ts).
  3. Construct the signed message: Combine the timestamp, a period (.), and the raw request body.
  4. Generate the HMAC: Compute HMAC-SHA256 using the signed message and the complete signing secret, including the whsec_ prefix, as the UTF-8 key.
  5. Format the signature: Convert the HMAC digest into lowercase hexadecimal.
  6. Send the request: Include the timestamp and signature in the request headers. Ensure the request body contains the exact bytes used to generate the signature.

Worked example

The following example illustrates how the signed message and signature are constructed.

Rules

Follow these requirements when signing and sending webhook requests.
  • Request body: Send the exact bytes used to generate the signature. Re-serializing the JSON body, including changing the key order, spacing, or formatting, returns 401 invalid_signature.
  • Signing secret: Use the complete signing secret, including the whsec_ prefix, as the HMAC key. Removing the prefix or Base64-decoding the secret returns 401 invalid_signature.
  • Timestamp validity: The timestamp must be within 300 seconds (5 minutes) of the server’s current time. Timestamps outside this window, including those caused by clock differences, return 401 stale_timestamp.
  • Timestamp format: Send the timestamp as a plain integer in seconds. Milliseconds, leading zeros, or decimal values return 401 stale_timestamp.
  • Content type: Set Content-Type to application/json. Other content types leave the request body unread and cause signature validation to fail.
  • Retries: Generate a fresh timestamp and signature for every retry. Requests replayed after 300 seconds are rejected.
  • Secret security: Do not expose the signing secret in client-side code or application logs. Anyone with the secret can initiate agent runs.
  • Duplicate requests: Accepted requests are not automatically deduplicated. Each accepted request starts a new agent run.
  • Secret regeneration: Update callers immediately after regenerating the signing secret. The previous secret becomes invalid at once.

Responses

The webhook returns the following HTTP status codes based on request validation and processing.

Examples

The following examples show how to generate a signature and send a signed webhook request using cURL, Node.js, and Python.