Webhooks
Create a webhook
Create a webhook that gets signed notifications when sessions change status.
POST
/
api
/
v2
/
webhooks
from hai_agents import Client
client = Client()
webhook = client.webhooks.create_webhook(
url="https://example.com/hooks/h",
enabled_events=["session.status_updated"],
description="Production listener",
)
print(webhook.secret) # shown only once; store it securely
import { HaiAgentsClient } from "hai-agents";
const client = new HaiAgentsClient();
const webhook = await client.webhooks.createWebhook({
url: "https://example.com/hooks/h",
enabledEvents: ["session.status_updated"],
description: "Production listener",
});
console.log(webhook.secret); // shown only once; store it securely
curl -X POST https://agp.eu.hcompany.ai/api/v2/webhooks \
-H "Authorization: Bearer $HAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/hooks/h",
"enabled_events": ["session.status_updated"],
"description": "Production listener"
}'
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"url": "https://example.com/hooks/h",
"enabled_events": ["session.status_updated"],
"description": "Production listener",
"disabled": false,
"last_delivery_status": null,
"last_delivery_error": null,
"last_delivery_at": null,
"last_success_at": null,
"consecutive_failures": 0,
"created_at": "2026-06-11T15:04:05Z",
"updated_at": "2026-06-11T15:04:05Z",
"secret": "whsec_k3TQyhq2mPv8WdJ4cN7xLbR9sF1aZ6uE0gYoHiC5jXw"
}
Behavior
Each event inenabled_events arrives as a signed POST, with the payload and signature check in Webhooks.
The secret is returned once and cannot be retrieved later. To replace it, use Rotate secret.
Request body
string
required
Target URL for deliveries, up to 2048 characters. Must be
https:// and publicly reachable: the platform sends a HEAD request at creation time and rejects the webhook if the endpoint cannot be reached. Any HTTP status counts as reachable. Your endpoint does not need to accept HEAD.string[]
default:["*"]
Event types delivered to this webhook.
"*" subscribes to the session.status_updated firehose. Granular session.* types are delivered only when named explicitly (Event types).string
Label for the webhook, up to 255 characters.
Response
201 with the created webhook object plus its secret.
from hai_agents import Client
client = Client()
webhook = client.webhooks.create_webhook(
url="https://example.com/hooks/h",
enabled_events=["session.status_updated"],
description="Production listener",
)
print(webhook.secret) # shown only once; store it securely
import { HaiAgentsClient } from "hai-agents";
const client = new HaiAgentsClient();
const webhook = await client.webhooks.createWebhook({
url: "https://example.com/hooks/h",
enabledEvents: ["session.status_updated"],
description: "Production listener",
});
console.log(webhook.secret); // shown only once; store it securely
curl -X POST https://agp.eu.hcompany.ai/api/v2/webhooks \
-H "Authorization: Bearer $HAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/hooks/h",
"enabled_events": ["session.status_updated"],
"description": "Production listener"
}'
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"url": "https://example.com/hooks/h",
"enabled_events": ["session.status_updated"],
"description": "Production listener",
"disabled": false,
"last_delivery_status": null,
"last_delivery_error": null,
"last_delivery_at": null,
"last_success_at": null,
"consecutive_failures": 0,
"created_at": "2026-06-11T15:04:05Z",
"updated_at": "2026-06-11T15:04:05Z",
"secret": "whsec_k3TQyhq2mPv8WdJ4cN7xLbR9sF1aZ6uE0gYoHiC5jXw"
}
Errors
| Status | Cause |
|---|---|
400 | Organization webhook limit reached (10), URL does not resolve to a public address, or the endpoint could not be reached. |
422 | Body failed validation: non-https URL, empty or unknown enabled_events. |
Was this page helpful?
⌘I
from hai_agents import Client
client = Client()
webhook = client.webhooks.create_webhook(
url="https://example.com/hooks/h",
enabled_events=["session.status_updated"],
description="Production listener",
)
print(webhook.secret) # shown only once; store it securely
import { HaiAgentsClient } from "hai-agents";
const client = new HaiAgentsClient();
const webhook = await client.webhooks.createWebhook({
url: "https://example.com/hooks/h",
enabledEvents: ["session.status_updated"],
description: "Production listener",
});
console.log(webhook.secret); // shown only once; store it securely
curl -X POST https://agp.eu.hcompany.ai/api/v2/webhooks \
-H "Authorization: Bearer $HAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/hooks/h",
"enabled_events": ["session.status_updated"],
"description": "Production listener"
}'
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"url": "https://example.com/hooks/h",
"enabled_events": ["session.status_updated"],
"description": "Production listener",
"disabled": false,
"last_delivery_status": null,
"last_delivery_error": null,
"last_delivery_at": null,
"last_success_at": null,
"consecutive_failures": 0,
"created_at": "2026-06-11T15:04:05Z",
"updated_at": "2026-06-11T15:04:05Z",
"secret": "whsec_k3TQyhq2mPv8WdJ4cN7xLbR9sF1aZ6uE0gYoHiC5jXw"
}