| name | openai-webhooks |
| description | Receive and verify OpenAI webhooks. Use when setting up OpenAI webhook handlers for fine-tuning jobs, batch completions, or async events like fine_tuning.job.completed, batch.completed, or realtime.call.incoming.
|
| license | MIT |
| metadata | {"author":"hookdeck","version":"0.1.0","repository":"https://github.com/hookdeck/webhook-skills"} |
OpenAI Webhooks
When to Use This Skill
- Setting up OpenAI webhook handlers for async operations
- Debugging signature verification failures
- Handling fine-tuning job completion events
- Processing batch API completion notifications
- Handling realtime API incoming calls
Essential Code (USE THIS)
Express Webhook Handler
const express = require('express');
const crypto = require('crypto');
const app = express();
function verifyOpenAISignature(payload, webhookId, webhookTimestamp, webhookSignature, secret) {
(!webhookSignature || !webhookSignature.()) {
;
}
currentTime = .(.() / );
timestampDiff = currentTime - (webhookTimestamp);
(timestampDiff > || timestampDiff < -) {
.();
;
}
[version, signature] = webhookSignature.();
(version !== ) {
;
}
payloadStr = payload ? payload.() : payload;
signedContent = ;
secretKey = secret.() ? secret.() : secret;
secretBytes = .(secretKey, );
expectedSignature = crypto
.(, secretBytes)
.(signedContent, )
.();
crypto.(
.(signature),
.(expectedSignature)
);
}
app.(,
express.({ : }),
(req, res) => {
webhookId = req.[];
webhookTimestamp = req.[];
webhookSignature = req.[];
(!(
req.,
webhookId,
webhookTimestamp,
webhookSignature,
process..
)) {
.();
res.().();
}
event = .(req..());
(event.) {
:
.(, event..);
;
:
.(, event..);
;
:
.(, event..);
;
:
.(, event..);
;
:
.(, event..);
;
:
.(, event..);
;
:
.(, event..);
;
:
.(, event.);
}
res.({ : });
}
);