Top use cases

  • Scoring: Score requests based on custom logic.
  • Data ETL: Moving data from one system to another.
  • Automations / Alerts: Trigger actions automatically, such as sending a Slack notification or triggering a webhook to an external tool.

Setting up webhooks

Head over to the webhooks page to set up a webhook.

Webhooks page

Add the webhook URL and select the events you want to trigger on.

You will want to copy the HMAC key and add it to your webhook environment to validate the signature of the webhook request.

Configure your webhook route

We recommend for startups to use Cloudflare workers or Vercel edge functions for webhooks, they are simple to setup and scale very well.

We have a prebuilt Cloudflare worker that you can use as a starting point.

The webhook endpoint is a POST route that accepts the following JSON body:

POST /webhook

The body of the request will contain the following fields:

  • request_id: The request ID of the request that triggered the webhook.
  • request_body: The body of the request that triggered the webhook.
  • response_body: The body of the response that triggered the webhook.

Example - NextJS

import crypto from "crypto";

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const { request_id, request_body, response_body } = req.body;

  // STEP 1: Validate the signature of the webhook request
  const hmac = crypto.createHmac("sha256", process.env.HELICONE_WEBHOOK_SECRET);
  hmac.update(JSON.stringify({ request_id, request_body, response_body }));
  const signature = hmac.digest("hex");
  if (signature !== req.headers["helicone-signature"]) {
    return res.status(401).json({ error: "Unauthorized" });
  }

  // STEP 2: Do something with the webhook data
  console.log(request_id, request_body, response_body);
  // ...
  // EX: You can submit a score using our [Scoring API](/features/scoring)

  return res.status(200).json({ message: "Webhook received" });
}