At around 4,000 events per minute, a TCP timeout becomes statistically likely across a billing window of any meaningful duration. The agent fires the request, the network drops the response, and the agent does what any well-behaved client does: it retries. If your event ingestion endpoint is not idempotent, that retry becomes a second billing event. Multiply that by a pipeline that runs for eight hours a day across 50 customer accounts, and the duplicate rate is no longer a theoretical concern.

Idempotent event ingestion is not glamorous. It is also not optional for any billing layer that handles agent-generated traffic. This post covers why agents produce duplicates, what the right idempotency key design looks like, how deduplication windows work in practice, and where the pattern has real limits.

Why Agents Retry, and Why They Cannot Help It

The standard pattern for network calls in agent code is: attempt the request, and if the response is an error or a timeout, retry with exponential backoff up to some ceiling. This is correct behavior. Networks are unreliable, and a single transient failure should not abort a pipeline that has been running for three hours.

The problem for billing is that retries are indistinguishable from new events at the endpoint level unless the agent sends something that identifies the original attempt. A POST to /v1/events with no idempotency key looks identical whether it is the first attempt or the fourth. The endpoint has no way to know whether it has already accepted this event.

At low event rates this might not matter much. One duplicate per hundred events over a monthly billing cycle might be small enough that customers do not notice. At high event rates, or in pipelines that do aggressive retry on failure, duplicates compound. An agent that retries up to three times on timeout and operates at 2,000 events per hour during a period of network instability can easily produce a 15 to 20 percent duplicate rate across that window.

What an Idempotency Key Actually Does

An idempotency key is a client-generated unique identifier for a specific event attempt. When the endpoint receives an event, it checks whether an event with that key has already been accepted within the deduplication window. If yes, it returns the original success response and does not count the event again. If no, it processes the event normally and stores the key.

The key should be specific enough to identify exactly one logical event in the context of one pipeline run. A key like evt_wf_8821_step_14_call_001 ties the event to a workflow execution, a pipeline step, and a call sequence number. If the same call retries three times, all three carry the same key. The endpoint accepts the first and silently deduplicates the subsequent two.

A key like evt_1723899012 based purely on a timestamp does not work. Two legitimate concurrent events from different agents can share the same millisecond timestamp. The key must incorporate enough context to be globally unique across all customers for the duration of the deduplication window.

Deduplication Window Design

The deduplication window defines how long the endpoint remembers a key. A 24-hour window means that any retry arriving within 24 hours of the original accepted event will be deduplicated. A retry arriving 25 hours later, for whatever reason, will be counted.

Choosing the right window involves two competing pressures. Shorter windows reduce the memory footprint: you only need to store keys that arrived in the recent past, and expired keys can be purged. Longer windows protect against scenarios where a pipeline fails, is restarted, and replays some portion of its prior work from a checkpoint that predates the original event.

In practice, a 72-hour window covers the vast majority of realistic retry and replay scenarios while keeping the key store manageable. Paygentic uses a 72-hour default window, stored in a Redis-backed sorted set with TTL expiry. Keys are indexed by arrival timestamp. On each ingest request, the endpoint checks the key, records the event if novel, and returns 200 with an idempotent flag in the response body indicating whether the event was new or a deduplicated replay.

What Idempotency Does Not Protect Against

We want to be direct about the limits here. Idempotency protects against duplicate events that carry the same key. It does not protect against bugs in the client that generate a new key for each attempt rather than carrying the original key across retries. If an agent regenerates its idempotency key on retry, every retry is a new event from the endpoint's perspective. No amount of server-side deduplication can fix a client that does not propagate its own keys correctly.

It also does not protect against events that are semantically identical but carry different keys. If an agent processes the same input record twice because of a pipeline bug or an at-least-once queue delivery, and generates a different key each time, both events will be accepted. The idempotency layer checks keys, not event content.

The implication is that idempotency is a cooperation contract between the client and the server. The server provides the mechanism. The client must implement key generation and propagation correctly for the mechanism to work. For Paygentic integrations, the SDK handles key generation and carries it through retries automatically. For direct API integrations, the idempotency_key field is required in every event payload and the client is responsible for propagating it correctly across attempts.

The Business Cost of Skipping This

A 5 percent duplicate rate on a customer account processing 3 million events per month means 150,000 extra billed events. At a rate of $0.0001 per event, that is $15 per month per affected customer. At scale across a growing customer base, the cumulative effect on customer trust is worse than the dollar amount. Customers who discover they have been double-charged due to a billing infrastructure failure do not typically give the benefit of the doubt. They churn and they mention it.

Building idempotent ingestion from the start avoids this entirely. The implementation cost is modest: a unique key field in the event schema, a key store with TTL, and a check on every ingest request. That is a one-time engineering investment with a permanent correctness benefit. Retrofitting it after a duplicate billing incident is technically the same work, plus the customer relationship repair.

Stay current on agentic billing

Practical notes on metering, usage-based pricing, and AI infrastructure, published roughly once a month. No filler.