Skip to main content

About webhooks

Webhooks allow you to receive real-time notifications when asynchronous operations complete in Wordsmith. Instead of polling the API to check if a task is finished, you can configure a webhook URL to receive callbacks when processing completes.

How webhooks work

  1. Configure a webhook URL: When making an API request, include a callback_url parameter
  2. Receive notifications: Wordsmith will send a POST request to your URL when processing completes
  3. Verify signatures: Use the webhook secret to verify that requests are genuinely from Wordsmith
  4. Process the data: Handle the notification data in your application

Setting up webhooks

Step 1: Create an API key with webhook secret

When creating an API key, you can optionally provide a webhook secret. If you don’t provide one, Wordsmith will automatically generate a secure secret for you.

Step 2: Use webhooks in your requests

Include a callback_url when making async requests (sync_mode is false):

Webhook payload format

When processing completes, Wordsmith sends a POST request to your callback URL with the following payload:

Payload fields

id
string
The unique session ID for the completed question
status
string
The final status: "completed" or "error"
answer
string
The assistant’s response. Present when status is "completed", contains error message when status is "error"
attachments
array
Array of generated files (e.g., analysis reports, summaries). Only present when status is "completed"

Validating webhook signatures

To ensure webhook requests are genuinely from Wordsmith and haven’t been tampered with, you should validate the signature before processing the payload.

About signature validation

Wordsmith uses HMAC-SHA256 to sign webhook payloads with your webhook secret. The signature is included in the Wordsmith-Signature header and follows this format:
Where:
  • t is the timestamp when the signature was created
  • v1 is the HMAC-SHA256 signature

Signature verification process

  1. Extract the timestamp and signature from the Wordsmith-Signature header
  2. Create the signed payload by concatenating the timestamp and the request body: {timestamp}.{payload}
  3. Generate the expected signature using HMAC-SHA256 with your webhook secret
  4. Compare the expected signature with the received signature using a constant-time comparison
  5. Verify the timestamp is within 60 seconds of the current time

Example implementations

Python

JavaScript/Node.js

Ruby

Testing webhook signatures

You can test your signature verification implementation using these values:
  • Secret: whsec_test_secret_123
  • Payload: {"id":"test","status":"completed"}
  • Timestamp: 1234567890
  • Expected signature: c60c0cc7241d79e8bf2a88fdc6ce257c2fd547048bb244495309b27ad07884bf
  • Header value: t=1234567890,v1=c60c0cc7241d79e8bf2a88fdc6ce257c2fd547048bb244495309b27ad07884bf

Security best practices

Store secrets securely

  • Never hardcode webhook secrets in your application
  • Use environment variables or secure configuration management
  • Rotate webhook secrets periodically

Validate all webhooks

  • Always verify webhook signatures before processing
  • Use constant-time comparison functions to prevent timing attacks
  • Check timestamp tolerance to prevent replay attacks

Handle errors gracefully

  • Return appropriate HTTP status codes (401 for invalid signatures)
  • Log failed signature verifications for monitoring
  • Don’t expose sensitive information in error messages

Use HTTPS

  • Always use HTTPS for webhook endpoints
  • Validate that callback URLs use secure protocols
  • Consider using certificate pinning for additional security

Troubleshooting

Common issues

Signature verification fails
  • Ensure you’re using the correct webhook secret
  • Check that the payload hasn’t been modified by middleware
  • Verify you’re parsing the signature header correctly
Webhook not received
  • Check that your endpoint is publicly accessible
  • Verify the callback URL is correct and uses HTTPS
  • Ensure your server can handle POST requests
Timestamp validation fails
  • Check that your server’s clock is synchronized
  • Verify you’re using the correct tolerance (60 seconds)
  • Ensure you’re parsing the timestamp correctly

Testing locally

For local development, you can use tools like ngrok to expose your local server:

Rate limiting

Webhook delivery is subject to rate limits to prevent abuse. If you receive too many webhooks in a short period, some may be dropped. Implement idempotency in your webhook handlers to handle potential duplicate deliveries.

Next steps