---
title: Idempotent AI Webhook Deduplication | APIkit
description: Stop duplicate AI endpoint executions during webhook replays using configurable idempotency keys and cached results.
canonical: "https://apikit.ai/j/deduplicate-idempotent-webhook-events"
modified: 2026-11-14
author: apikit.ai editorial team
source: "https://apikit.ai"
category: Webhook & Async Event Pipelines
category_url: "https://apikit.ai/j#group-webhook-event-pipelines"
---

# Deduplicate duplicate webhook runs with idempotency keys

> Prevent double token billing and duplicate database updates when third-party senders retry slow or flaky webhook deliveries.

## Prepared starting prompt

Stripe and our internal queue sometimes deliver the same event twice. I want APIkit to deduplicate requests by event_id and return the cached output.

### Quick scenarios
- **Header or body ID key:** Extract idempotency keys from Idempotency-Key headers or nested event_id JSON paths.
- **Return original JSON:** Replay the exact stored AI response on duplicate hits instead of running the LLM again.
- **Configurable dedup TTL:** Hold idempotency locks for 24 hours or 7 days depending on upstream retry windows.

- [Request early access](https://apikit.ai/#waitlist-f73a0d)

## Steps to enforce idempotent AI webhooks

1. **Pick an immutable sender key** — Bind idempotency to the provider delivery ID or payload event_id rather than volatile timestamps.
2. **Handle concurrent in-flight duplicates** — Lock identical simultaneous deliveries so the second request waits for the first run rather than duplicating work.
3. **Set matching retention TTLs** — Ensure idempotency window length exceeds the maximum retry duration of your webhook sender.
4. **Log deduplicated cache hits** — Track duplicate-blocked counters in analytics to spot noisy upstream retry configurations.

## Frequently Asked Questions

### What response does a duplicate webhook receive?

APIkit returns HTTP 200 with the previously stored JSON response and a deduplicated flag, keeping callers happy with zero extra model spend.

### What if two identical webhooks arrive at the exact same millisecond?

In-flight locking holds the concurrent duplicate briefly and shares the single model run's outcome rather than racing.

### Can I extract the key from the JSON body instead of an HTTP header?

Yes. Point the idempotency rule at any JSONPath expression such as $.event.id or a standard Idempotency-Key header.

## Related tasks in this category

- [Enrich incoming webhooks with AI before forwarding](https://apikit.ai/j/process-stripe-github-webhooks-ai.md)
- [Run slow AI jobs asynchronously with webhook callbacks](https://apikit.ai/j/run-long-ai-jobs-async-callbacks.md)
- [Sign and verify AI webhook callbacks with HMAC headers](https://apikit.ai/j/sign-outbound-webhook-hmac-headers.md)
- [Recover failed webhook deliveries with retries and DLQ](https://apikit.ai/j/configure-dead-letter-webhook-retries.md)
- [Fan out batch arrays into parallel AI endpoint runs](https://apikit.ai/j/fan-out-batch-events-parallel.md)
- [Turn raw app events into crisp Slack or Discord alerts](https://apikit.ai/j/trigger-slack-discord-alerts-events.md)

---

*Published by **Wondel.ai sp. z o.o.** · [apikit.ai](https://apikit.ai) · [About](https://apikit.ai/about) · [Editorial Guidelines](https://apikit.ai/editorial) · [Contact](https://apikit.ai/contact) · [Wondel.ai Products](https://wondel.ai/products)*