API Web Hook

You need configure a webhook url for each agent you create. Long running text responses from agents and configured functions are sent to webhooks.

To securely consume a webhook response, you can optionally validate the webhook using the x-signature token sent with the response. The token must be validated with the same api key used to make the request to the agent.

// Header
'x-signature': xxxxxxxxxxxxxxx
// Webhook Text Response
{
    "message": {
        "id": "duH7f5mOItDIlpYRbMPDE",
        "agentId": "hyeyry3mOItehdsfp373hhs",
        "role": "assistant",
        "content": "The diagnosis of Pediculus Capitis (head lice) is a valid medical condition. The details provided do not indicate any fraudulent activity."
    }
}

Here is a smaple code to securely verify your hooks

const crypto = require('crypto');

function verifyWebhookSignature(req, secret) {
  const signature = req.headers['x-signature'];
  const payload = JSON.stringify(req.body);
  
  // Compute the hash using HMAC with SHA256 and the shared secret
  const hash = crypto.createHmac('sha256', secret).update(payload).digest('hex');

  // Compare the computed hash with the signature
  return hash === signature;
}

// Usage in Express.js
app.post('/webhook', (req, res) => {
  const secret = 'your_api_key';
  
  if (!verifyWebhookSignature(req, secret)) {
    return res.status(403).send('Forbidden');
  }
  
  // Handle the webhook
  res.status(200).send('Webhook received');
});

You can optionally use this approach to seurely consume a hook, or ensure that your webhook url is on a secured https certificate.

Last updated