Set up webhooks to receive real-time notifications from TengineAI.
Webhooks allow your application to receive notifications when events occur in your TengineAI projects. This enables real-time integration and automated workflows.
project.created: New project createdproject.updated: Project settings updatedproject.deleted: Project deletedapi_key.created: New API key generatedapi_key.revoked: API key revokedapi_key.updated: API key permissions updatedintegration.connected: OAuth integration connectedintegration.disconnected: OAuth integration disconnectedintegration.updated: Integration settings updatedusage.threshold_reached: Usage threshold exceededusage.limit_exceeded: Usage limit exceededNavigate to Webhooks
Configure Webhook
Test Webhook
curl -X POST https://app.tengine.ai/api/v1/projects/{project_id}/webhooks \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-app.com/webhook",
"events": ["project.created", "api_key.created"],
"secret": "your-webhook-secret"
}'
{
"id": "evt_1234567890",
"type": "project.created",
"data": {
"id": "proj_123",
"name": "My Project",
"description": "A sample project",
"created_at": "2024-01-01T00:00:00Z"
},
"created_at": "2024-01-01T00:00:00Z",
"api_version": "2021-09-01"
}
{
"type": "project.created",
"data": {
"id": "proj_123",
"name": "My Project",
"description": "Project description",
"created_at": "2024-01-01T00:00:00Z"
}
}
{
"type": "api_key.created",
"data": {
"id": "key_123",
"name": "My API Key",
"permissions": ["read", "write"],
"created_at": "2024-01-01T00:00:00Z"
}
}
TengineAI signs all webhook payloads using HMAC-SHA256:
const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(payload, 'utf8')
.digest('hex');
return signature === `sha256=${expectedSignature}`;
}
// Usage
app.post('/webhook', (req, res) => {
const signature = req.headers['x-tengine-signature'];
const payload = JSON.stringify(req.body);
if (!verifyWebhookSignature(payload, signature, process.env.WEBHOOK_SECRET)) {
return res.status(400).send('Invalid signature');
}
// Process webhook
res.status(200).send('OK');
});
For additional security, whitelist TengineAI IP addresses:
# TengineAI Webhook IPs
54.123.45.67
54.123.45.68
app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {
const signature = req.headers['x-tengine-signature'];
// Verify signature
if (!verifyWebhookSignature(req.body, signature, process.env.WEBHOOK_SECRET)) {
return res.status(400).send('Invalid signature');
}
const event = JSON.parse(req.body);
// Handle different event types
switch (event.type) {
case 'project.created':
handleProjectCreated(event.data);
break;
case 'api_key.created':
handleApiKeyCreated(event.data);
break;
default:
console.log(`Unhandled event type: ${event.type}`);
}
res.status(200).send('OK');
});
TengineAI will retry failed webhook deliveries:
Handle duplicate events using the event ID:
const processedEvents = new Set();
app.post('/webhook', (req, res) => {
const event = JSON.parse(req.body);
// Check if already processed
if (processedEvents.has(event.id)) {
return res.status(200).send('Already processed');
}
// Process event
processEvent(event);
// Mark as processed
processedEvents.add(event.id);
res.status(200).send('OK');
});
Use ngrok to expose your local server:
# Install ngrok
npm install -g ngrok
# Expose local server
ngrok http 3000
# Use the HTTPS URL for webhook endpoint
# https://abc123.ngrok.io/webhook
# Send test webhook
curl -X POST https://app.tengine.ai/api/v1/webhooks/{webhook_id}/test \
-H "Authorization: Bearer YOUR_API_KEY"
View webhook delivery logs in your dashboard:
"Invalid Signature"
"Timeout"
"Duplicate Events"
app.post('/webhook', (req, res) => {
try {
// Quick validation
const event = JSON.parse(req.body);
// Return 200 immediately
res.status(200).send('OK');
// Process asynchronously
setImmediate(() => {
processWebhookEvent(event);
});
} catch (error) {
console.error('Webhook error:', error);
res.status(400).send('Bad Request');
}
});
async function processWebhookEvent(event) {
try {
// Process event
await handleEvent(event);
} catch (error) {
console.error('Failed to process webhook:', error);
// Log to monitoring service
// Send alert to team
}
}
curl -X POST https://app.tengine.ai/api/v1/projects/{project_id}/webhooks \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-app.com/webhook",
"events": ["project.created"],
"headers": {
"X-Custom-Header": "custom-value"
}
}'
{
"url": "https://your-app.com/webhook",
"events": ["project.created", "api_key.created"],
"filters": {
"project.name": "My Project"
}
}
Need help with webhooks? Contact our support team or join our Discord community.