Claude API Webhook Event Notifications: Setup Guide
If you've been searching for how to configure webhook event notifications on the Claude API, the short answer is: Anthropic's API doesn't have a native webhook system. Unlike payment processors or some batch-job APIs, Claude's Messages API is a synchronous request/response call (or a streamed response) — there's no "callback URL" field you can register, and no dashboard setting that fires a POST to your server when a generation finishes.
That doesn't mean you can't get webhook-style notifications. It means you have to build a thin layer that watches your Claude calls and dispatches events yourself. This is a common pattern and it's not hard to implement correctly — this guide covers the architecture, the events worth tracking, and working code for a webhook dispatcher you can drop into an existing integration.
Why Claude doesn't have built-in webhooks
Claude's API is designed around two response modes:
- Non-streaming: you send a request, you wait, you get a full completion back in one HTTP response.
- Streaming (SSE): you get
message_start,content_block_delta,message_delta, andmessage_stopevents over an open connection, but they go directly to the caller — not to a webhook endpoint you register in advance.
There's no job queue with a callback option like you'd see in some async APIs. So "setting up a webhook" for Claude really means wrapping your own event layer around calls you're already making, and firing HTTP callbacks to wherever you want — Slack, an internal service, a billing system, a monitoring dashboard.
The architecture: event dispatcher pattern
The cleanest approach is a small middle layer between your app and the Claude API:
- Your app sends a request to Claude (directly, or through a proxy like SubToAPI).
- A dispatcher wraps that call and emits internal events: started, streaming, completed, errored, tool-use-requested.
- Each event is turned into a signed HTTP POST to one or more webhook URLs you configure.
- A queue with retries handles delivery, so a slow or down webhook receiver doesn't block your main request path.
This keeps your application code simple — it just calls Claude — while giving downstream systems (Slack alerts, logging pipelines, support tools) a reliable notification channel.
Minimal dispatcher example
import crypto from "crypto";
const WEBHOOK_URL = process.env.WEBHOOK_URL;
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET;
async function sendWebhook(event, payload) {
const body = JSON.stringify({ event, payload, timestamp: Date.now() });
const signature = crypto
.createHmac("sha256", WEBHOOK_SECRET)
.update(body)
.digest("hex");
await fetch(WEBHOOK_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Signature": signature,
},
body,
}).catch((err) => {
// enqueue for retry instead of swallowing silently
console.error("webhook delivery failed", err);
});
}
async function callClaudeWithEvents(messages) {
await sendWebhook("message.started", { messages });
const res = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "claude-sonnet-4-5",
max_tokens: 1024,
messages,
}),
});
const data = await res.json();
if (!res.ok) {
await sendWebhook("message.errored", { status: res.status, data });
throw new Error("Claude request failed");
}
await sendWebhook("message.completed", {
id: data.id,
usage: data.usage,
stop_reason: data.stop_reason,
});
return data;
}
Signing the payload with HMAC means receivers can verify the webhook actually came from your dispatcher, not from a spoofed request — treat WEBHOOK_SECRET the same way you'd treat an API key.
Events worth notifying on
Not every API call needs a webhook. Focus on events that someone actually needs to react to:
message.completed— a generation finished; useful for logging, analytics pipelines, or triggering a follow-up actionmessage.errored— a call failed; route this to Slack or PagerDuty, not just your logstool_use.requested— Claude asked to call a tool; if you're running tool use asynchronously (see docs/tools), this is the natural trigger point for a webhook that kicks off the actual tool executionusage.threshold_exceeded— a request's token usage crossed a budget line, useful if you're building spend monitoring on top of per-request usage datastream.stalled— a streaming connection has gone quiet longer than expected, which usually means something downstream is wrong
For streaming specifically, don't try to forward every SSE delta as its own webhook — that's a lot of HTTP overhead for no benefit. Buffer deltas server-side and fire one webhook per logical event (start, tool call, completion). The streaming docs cover the event types you'll be buffering.
Making delivery reliable
A webhook system is only useful if deliveries don't silently vanish. Two things matter most:
- Retries with backoff. If the receiving endpoint returns a non-2xx status or times out, retry 3–5 times with exponential backoff before giving up. A simple in-memory queue is fine for low volume; use Redis or a proper job queue (BullMQ, Sidekiq) once you're handling meaningful traffic.
- Idempotency. Include a unique event ID in every payload so receivers can dedupe if a retry arrives after the original delivery actually succeeded.
const body = JSON.stringify({
id: crypto.randomUUID(),
event: "message.completed",
payload,
timestamp: Date.now(),
});
Where this fits with usage metadata
If your main goal is notifications about spend or volume rather than individual completions, you don't need a full event bus — you can poll usage metadata on a schedule instead. SubToAPI returns per-request usage data (input/output tokens, model used) with every call through /docs/messages, which is enough to build a periodic check that fires a webhook only when a threshold is crossed, instead of on every single request.
Getting application API keys, streaming, and usage metadata set up correctly is covered in the quickstart — once requests are flowing through a single endpoint, wrapping a webhook dispatcher around them is a small addition. You can try the whole setup with a free trial, and plan details are on /pricing.
questions
Does the Claude API support native webhooks? No. Anthropic's Messages API is synchronous or streamed directly to the caller — there's no callback URL field or webhook registration in the API itself. You build notification logic as a layer on top of your own requests.
What's the simplest way to get Slack alerts on Claude errors? Wrap your API calls in a dispatcher that POSTs to a Slack incoming webhook URL whenever a request returns a non-2xx status. No queue is needed for low volume — a direct fetch call with basic retry logic is enough to start.
Can I get a webhook when token usage crosses a budget? Not natively, but you can build it: check the usage field returned with each response (or poll aggregated usage periodically) and fire a webhook whenever a configured threshold is exceeded.