APIFleet Sign in

Voice agent tool calling idempotency: make repeated tool calls safe

Voice agent tool calling idempotency means a repeated tool call changes your data only once. Repeats come from timeouts, model retries, callers repeating themselves and webhook redelivery, and a model retry gets a new call_id. Key each write on a stable business operation, store the first result, return it on repeats, and reconcile after a timeout before retrying.

APIFleet team · · 16 min read

Why does a voice agent call the same tool twice?

Duplicate tool calls in a voice agent have ordinary causes, and each repeat looks like new work to your backend. The table lists the usual causes and what changes on the wire when each one happens.

On gpt-live-1 phone calls the slowest tenth of tool calls took 6.91 s or longer, within about a second of the 8 s default timeout. The sample is 1,008 tool calls of 20 ms or more in 450 calls, 11 September to 29 October 2026, and one assistant made 62% of the gpt-live-1 phone tool calls.

In the same period the voice stayed quiet for at least a median 5.07 s before the result audio on gpt-live-1 phone tool turns (851 tool turns in 425 calls). A pause that long gives the caller time to repeat the request while the first call is still running.

Interruptions behave differently by stack. On OpenAI Realtime, tool calls still queued when a caller interruption cancels their response are dropped before any request is sent, and APIFleet does not cancel a call it has already started. On Gemini Live, a caller interruption can cancel a tool call that APIFleet has already sent, so your endpoint may still complete the write while the model never receives a result for that call id.

Common causes of a repeated tool call and what changes on the wire
CauseWhat happensIdentifier on the repeatWhat protects you
Tool timeoutAPIFleet stops waiting (8 s by default) and gives the model an error result while your endpoint may still finish the writeA new call_id if the model asks againA lookup by business key before any new write
Model asks againAfter an error or an unclear result, the model issues the same tool call once moreA new call_idA key on the business operation
Caller repeats or correctsA silent wait invites the caller to restate the request, or to change one detail of itA new call_idSame key means a repeat, a changed detail means an update
Caller talks over the agentOn OpenAI Realtime, queued calls of a cancelled response are dropped before sending; on Gemini Live a call may be cancelled after the request went out, and its result is discardedA new call_id on any later attemptNever read an unspoken result as a failed write
Proxy or gateway resendA component in front of your handler sends the same request againThe same call_id and bodyThe key, or the call_id for this case only
Webhook retryYour reply took longer than the default 5 s budget, the request failed in transit, or you answered 429 or 5xxThe same delivery id, body and signatureA unique constraint on the delivery id

What APIFleet sends and what it retries

An HTTP tool call is one signed request per model tool call, a POST by default. The JSON body carries call_id, name, arguments, context and created_at, and the X-APIFleet-Call header repeats the call_id. A tool set to GET sends no body, so its arguments arrive in the query string.

That call_id is the model provider's tool call id: the id OpenAI Realtime or Gemini Live gave that call, or on a cascading assistant the id the chat model gave it. APIFleet makes one attempt, and a timeout, network failure or non-2xx reply goes back to the model as an error result instead of a retry.

Within one model response, APIFleet sends tool calls one at a time, in order. Overlap still happens when an attempt APIFleet gave up on is running while the next request arrives, so your handler has to tolerate two requests for one operation at once.

What APIFleet sends, what it retries and what to key on
EventIdentifier you receiveDoes APIFleet retry?Key on
HTTP tool callX-APIFleet-Call header and call_id in the body: the model provider's tool call id for that one callNo. One attempt per model tool call; a failure goes back to the model as an error resultThe business operation
Call webhooks (call.started, call.ended)X-APIFleet-Delivery header and delivery in the bodyYes, on a timeout, 429 or 5xx: by default up to 4 retries with exponential backoff, kept in the sender's memory, so a crash can drop themThe delivery id; reconcile gaps with GET /calls
Assistant lifecycle and simulation webhooks (assistant.created, assistant.updated, assistant.deleted, simulation.completed)The same header and body fieldYes: a durable outbox keeps retrying for 24 hours by default, with no attempt limitThe delivery id
Your POST /calls/outbound requestThe ids in a 201 reply, nothing if the request times outNo automatic retry and no universal Idempotency-KeyA lookup in GET /calls before you repeat

Why call_id is not an idempotency key

RFC 9110 calls a method idempotent when several identical requests have the same intended effect on the server as one. A tool can be configured as GET, POST, PUT, PATCH or DELETE, but the method name does not make your handler safe, because your code has to provide that effect.

The call_id answers a different question: which tool call is this, so the model can match the result. OpenAI describes the Realtime call_id as a system-generated ID for that function call, and a model that asks again after a timeout issues a new one. A key built from it dedupes a request that was resent, not a request that was repeated.

Two other obvious keys fail too. The request body includes created_at, which changes on every attempt, so a hash of the whole body never matches a repeat. A hash of the raw arguments breaks as soon as the model rephrases a value, such as a time sent as 19:00 once and 7 pm the next time.

Stripe's API shows the pattern when the client is a program. For its v1 API, Stripe saves the status code and body of the first request made with a key, returns them for later requests with the same key, including 500 errors, and errors if the parameters differ. In a voice agent the client is a language model, so derive the key on your side from data you control.

Which idempotency key fits which tool?

Build the key from the business operation: the venue, the customer id that your lookup step resolved, and the booked time in UTC. Do not use a phone number as typed or spoken, because (312) 555-0100 and +1 312 555 0100 are the same caller but different strings. In a local test, a key built from the digits of the phone text created a second booking when the same caller's number arrived in a different format.

When no natural key exists, split the write in two. A prepare tool validates the request, stores it and returns an operation id with a read-back sentence, and a commit tool takes only that id. A repeated commit finds the same stored operation and returns its result, and the caller's confirmation applies to exactly the details that were stored.

Which key fits which kind of tool
Tool typeKey that survives a model retryWhat goes wrong without it
Lookup or availability checkNone needed: a read is safe to repeatA repeat costs time on the call, not data
Create a booking or orderVenue, resolved customer id and start time in UTC, or a prepare operation idA second booking for the same caller and slot
Change a bookingThe booking id plus the new valuesA change applied twice, or a new booking created instead
Cancel a bookingThe booking id: cancelling twice leaves it cancelledAn error on the repeat that makes the model say the cancellation failed
Send an SMS or emailRecipient, purpose and conversation id, plus the provider's own idempotency key if it offers oneThe caller receives the same message twice

Should a voice agent retry a tool call that timed out?

Not until you know whether the first attempt happened. A timeout means APIFleet stopped waiting, not that your endpoint stopped working, so the write may be committed, still running or never started. The model cannot tell which, because all three reach it as the same error result.

RFC 9110 says a client should not automatically retry a non-idempotent request unless it knows the semantics are idempotent or can detect that the original was never applied. A language model has neither, so your endpoint has to supply one of them: a key that makes the repeat harmless, or a lookup that shows what happened.

Keep the first response inside the budget. If the write can take longer than a few seconds, return in_progress with the operation id at once, finish the work in the background and give the model a status tool to ask again. Raising the tool timeout up to 30 s buys time but lengthens the silence on the line, and lowering it ends the wait sooner but turns slower writes into unknown outcomes.

Describe each status value in the tool's description so the model knows that in_progress means wait rather than repeat. On cascading assistants, set progress_message on a slow tool so the caller hears an update instead of silence; it reduces dead air but does not make a repeated write safe.

What the model sees after a tool call, what may have happened and the safe next step
What the model seesWhat may have happenedSafe next step
An error that says the tool invocation failed (timeout or network)The write never ran, is still running, or finished after APIFleet stopped waitingLook the operation up by its key and repeat only if it does not exist
An error that names an HTTP 5xx status, plus your response bodyYour gateway or app failed, and the write may already be committedReconcile exactly as for a timeout
An error that names an HTTP 4xx status, plus your response bodyYour handler refused the request, normally before any writeFix the input or ask the caller, then repeat
Your in_progress statusThe first attempt is still runningTell the caller it is being confirmed, then call a status tool
A stored result with duplicate trueA repeat of work that already finishedSay the same confirmation and write nothing new

How to build a duplicate-safe tool handler

The handler needs one table with a unique constraint and one rule: claim the operation before you do the work. The IETF's Idempotency-Key draft, still an Internet-Draft in October 2026, suggests answering a retry that arrives while the first request runs with 409 Conflict. A tool reply goes to a language model, not a client library, and APIFleet passes a non-2xx status to the model as an error, so the steps below return 200 with an in_progress status.

  1. On any tool method except GET, verify X-APIFleet-Signature before parsing: compute sha256= plus the hex HMAC of the raw body with the tool's secret and compare it in constant time, checking the lengths first because timingSafeEqual throws when they differ.
  2. Build the operation key from business data your system resolved, such as venue id, customer id and start time in UTC, never from call_id, created_at or the raw argument text.
  3. Claim the key with one statement, INSERT INTO tool_ops (op_key, fingerprint, status) VALUES (?, ?, 'running') ON CONFLICT (op_key) DO NOTHING, a clause Postgres accepts (use your database's equivalent elsewhere), and read how many rows it inserted. The fingerprint holds the details that may legitimately change, such as party size.
  4. If one row was inserted, you own the operation: do the write, store the result on the same row with status done, and return it. If the write lives in your own database, do the claim and the write in one transaction.
  5. If no row was inserted, read the existing row. When it is done and its fingerprint matches, return the stored result unchanged; when it is still running, return in_progress with the operation id.
  6. If the fingerprint differs, for example a new party size, return a conflict that names the existing booking and points the model at your update tool, and never create a second booking silently.
  7. Return a repeat in the same success shape as the first call, with a duplicate flag if you like, and keep an error field or ok set to false out of it, because APIFleet records such a reply as a failed tool event.
  8. Give a running claim a lease: when its row is older than your longest write plus the tool timeout, check the downstream system for the operation before you retry or release it.
Worked trace of that handler: a timed-out booking and the requests that follow (local test with a 500 ms tool timeout, not production data)
Requestcall_idWhat the handler findsWhat the model sees
1. First requestcall_AClaims the key and starts a write that outlasts the timeoutAn error: the tool invocation failed
2. The model asks again while the write runscall_BThe key is claimed and still runningStatus in_progress
3. The caller repeats later, time and phone re-formattedcall_CThe key is done and the details matchStatus confirmed, the same booking reference, duplicate true
4. A proxy resends request 1call_AThe key is done and the details matchThe same stored result
5. The caller changes the party size from 4 to 5call_DThe key is done but the fingerprint differsStatus conflict that names the existing booking
6. The caller asks for the next hour insteadcall_EA different key, so a new claim and a new writeA second booking, because it is a different operation

How to make a webhook handler idempotent

Webhook delivery is at least once while APIFleet is still retrying, not exactly once, so the same event can reach your endpoint more than once. Each event gets one delivery id, a UUID sent in the X-APIFleet-Delivery header and in the body as delivery, and every retry to an endpoint reuses that id, the same body and the same signature. Treat the id as the dedupe key, and because every endpoint subscribed to the same event receives the same id, key a table shared by two endpoints on the delivery id plus the endpoint.

The retry rules depend on the event. By default, call.started and call.ended are retried from memory: up to 4 retries, so 5 attempts, with waits of 1, 2, 4 and 8 s plus up to 250 ms of jitter each, and a crash can drop pending retries. For simulation.completed and the assistant.created, assistant.updated and assistant.deleted events, a durable outbox keeps retrying with no attempt cap, by default doubling the wait up to 5 minutes and stopping when a 24 hour window ends, after which the delivery is marked failed.

By default a call event therefore gets about 15 s of backoff in all, so an outage of a minute or more, or a crash before a retry, can lose it for good, and GET /calls is how you reconcile what you did not receive. By default the durable events survive a much longer outage, because they keep retrying until their 24 hour window ends.

By default, replies are expected within 5 seconds, and a slower reply counts as a failed attempt that is retried. If your handler does the business work inline and takes longer, the retry arrives while the first attempt is still running, and a check-then-insert guard lets both through. In a local test with APIFleet's own webhook sender and a shortened reply budget, that guard ran the work twice, while storing the delivery id first under a unique constraint ran it once, even when the first 200 was lost.

Verify the signature over the raw body, insert the delivery into a table keyed by delivery id, answer 200 straight away and do the work from that table. Answer 200 for a duplicate too, because any other 4xx is permanent and a 429 or 5xx asks for another retry. Use 401 only for a bad signature.

How APIFleet treats your webhook reply
Your replyWhat APIFleet doesUse it for
2xx within the default 5 s budgetMarks the delivery done and stopsA new delivery and a duplicate you already stored
No reply within that budget, or a network errorCounts a failed attempt and retries, even if your handler finishedAvoid it: store first, then do the work
429 or 5xxRetries with exponential backoffA transient failure you want retried
Any other 4xx, such as 401Treats it as permanent and never retriesA request you will never accept, such as a bad signature

How to test duplicates before callers do

Test the endpoint you will run in production. A simulation tool mock returns canned JSON in place of your endpoint, so it cannot show how your handler treats a repeat, although it can show what the model says after an in_progress or error result. To trigger a real timeout, set the tool's timeout to its lowest allowed value, 500 ms, and add a delay after the write in a test endpoint.

After real test calls, read tool_events in GET /calls. Two entries with the same tool name and equivalent arguments but different call_id values usually mark a model repeat, and on Gemini Live a cancelled status may mark a result that APIFleet discarded after an interruption.

Duplicate cases to run against your real endpoint
CaseHow to trigger itIt passes when
ReplaySend the same signed request twice with curlOne row is written and both replies carry the same booking reference
Model repeatSend the same business request, re-signed, with a new call_id, a later created_at and the time or phone number spelled differentlyThe same booking reference comes back and no second row appears, because the key uses resolved ids
Timeout then repeatSet the tool timeout to 500 ms, delay your reply by a second after the write, then repeat the requestThe first call times out, the booking exists once and the repeat returns it
OverlapSend two identical requests at the same momentOne write happens and the other waits or returns in_progress
Changed detailRepeat the request with a different party size or timeYou get a conflict or an update path, never a silent second booking
Webhook replayPost the same delivery id twice, once with a slow replyThe business effect runs once

What to ask any voice platform about tool calls

Three answers decide how much duplicate protection you have to build: which identifier a tool request carries, what the platform retries, and what the model sees after a failure. For APIFleet HTTP tools the answers are the model provider's tool call id, no retry, and an error result that does not say whether the write happened.

Our comparison of six developer platforms covers per-minute cost, control and pilot fit rather than tool-retry behavior, so put the same three questions to each vendor before you rely on its tool calls for writes.

APIFleet behavior on this page was checked on 16 November 2026. The defaults quoted here, such as the 5 s webhook reply budget and the 8 s tool timeout, can change, so confirm them against the API documentation and your own test calls.

Voice agent workflow diagram: caller audio, speech and model, a round trip to tools and context, then the spoken reply

Continue with a practical next step

Frequently asked questions

What is an idempotency key for a tool call?

An idempotency key is a stable identifier for one intended operation, such as one booking for one customer at one time. Your handler stores the first result under that key and returns it for every repeat. In a voice agent, build it from data your system resolved, not from call_id, which is new on every model retry.

Why does a voice agent call the same tool twice?

The model can retry after a timeout or an error, the caller can repeat or correct a request while a slow tool runs, an interruption can leave a result unspoken, and a proxy can resend a request. Each model retry is a new tool call with a new call_id, so it looks like new work unless you key the write on the business operation.

Should a voice agent retry a tool call that timed out?

Not until you know what happened. A timeout means APIFleet stopped waiting, not that your endpoint stopped, so the write may exist. Look the operation up by its key and repeat only if it is missing; with an idempotent write, a repeat is safe and returns the stored result.

How do I make a webhook handler idempotent when the sender retries?

Verify the signature over the raw body, insert the X-APIFleet-Delivery id into a table with a unique constraint, answer 200 for both new and duplicate deliveries, and do the work from that table. APIFleet can deliver the same event more than once, reuses the same delivery id, body and signature on every retry, and expects a reply within 5 seconds by default.

Does APIFleet retry HTTP tools or webhooks?

It does not retry HTTP tool calls: each model tool call gets one attempt, and a failure goes back to the model as an error result. Call webhooks (call.started and call.ended) are retried from memory after a timeout, 429 or 5xx, by default up to 4 times, while assistant lifecycle and simulation webhooks are retried from a durable outbox for 24 hours by default. APIFleet does not promise exactly-once delivery for either.

Sources and evidence

Prepared with AI assistance and checked against the linked evidence. Examples are illustrative unless explicitly documented as measured results.

Bring your next conversation.

Explore the API, or sign in to your existing workspace. New workspace access is currently limited; contact us to discuss your project.