Can an AI API timeout cause duplicate actions? Yes. A write may finish before its response is lost. Check its outcome and retry only when duplicates can be prevented or detected and repaired.
An agent requests a change, waits, and receives a timeout. Its next move is to repeat the request. That can be reasonable for some read-only operations, but it can be dangerous for a write. The server may have completed the first action even though the agent never received the response. A second attempt can create a duplicate record, send another notification or repeat work that was already finished.
This guide explains how to separate retryable API failures from uncertain action outcomes. It uses a fictional task-management system in which an agent creates a ticket and posts an update. The examples are design guidance, not a report of a specific production incident. The right implementation depends on the actual provider contract and the action you are trying to perform.
Google's Gemini troubleshooting guidance recommends delayed retries for appropriate transient errors and notes that SDKs can already retry some requests. That supports checking the retry behavior of your client. It does not establish that every downstream tool action is safe to repeat, or that a successful model response means the whole workflow completed exactly once.
A timeout does not say whether the remote action happened. Look up the operation by its identifier where the provider supports it; only retry when you can prevent duplicates or detect and repair them. If no status check exists, surface the uncertainty.
Find out which operation actually failed
A workflow can contain several layers: your application, an agent framework, a model provider, a tool adapter and the target service. A timeout at one layer does not automatically describe the state of all the others. Before changing retry settings, identify which operation produced the error and which component was waiting for a response.
In the ticket example, the model call might fail before proposing any action. Alternatively, the model may produce a valid tool call, the ticket service may create the record, and the adapter may time out while returning the result. Those cases need different recovery steps. Retrying the entire agent conversation in the second case can replay a side effect that already happened.
Keep a small timeline with operation identifiers, timestamps and states. Record whether the request was prepared, submitted, acknowledged or confirmed complete. Do not fill unknown states with assumptions. A timeout often means that the client lacks an answer; it is not by itself proof that the target service did nothing.
Classify errors before choosing a retry
Start with the provider's current documentation for the endpoint and SDK version in use. Authentication errors, malformed inputs, exhausted account quota and transient overload are not interchangeable. A delay will not correct a missing required field. Repeating a request with an invalid credential can consume time while making the original configuration problem harder to see.
A useful application policy separates failures into correctable input errors, potentially transient errors and uncertain outcomes. The categories should lead to different behavior. Correctable input errors need a change or a clear message. Potentially transient errors may permit a bounded retry. Uncertain outcomes need reconciliation with the target system before another side effect is attempted.
Keep the classification explicit in code or configuration where possible. Asking the model to decide freely whether to retry every tool result makes the behavior harder to review. The agent can explain the failure to the user, but the operational boundary should not depend solely on how confidently it phrases its next action.
A timeout is an unknown outcome
Count retries across the whole stack
A retry budget can be much larger than it appears. Your application may retry a framework call, the framework may retry a model request, and the SDK may retry an HTTP operation internally. A limit of three at each layer does not necessarily mean only three network attempts. Inspect the actual stack rather than assuming the outermost counter tells the whole story.
Document which layer owns the retry decision. If the SDK already handles a documented transient condition, an additional application retry may be unnecessary or may need a different scope. Count attempts, elapsed time and any downstream actions separately. The goal is to understand what work can repeat when one visible operation fails.
Use a controlled failure in a nonproduction environment to verify the behavior. Record how many requests are made and when the workflow stops. A configuration file can say one thing while middleware or a wrapper adds another retry. The actual request sequence is the evidence you need before claiming that the system has a bounded recovery policy.
Use delay to reduce pressure, not to hide failure
For a retryable transient error, delayed retries can reduce the pressure created by immediate repeated requests. Follow the provider's documented guidance, including any supplied retry interval. Where appropriate, a gradually increasing delay with randomness can avoid many clients retrying at exactly the same moment. The exact values should fit the service and user experience.
A delay strategy still needs an end. Define a maximum number of attempts and an overall deadline. A workflow that sleeps repeatedly for an hour may technically be backing off while failing the user's actual time requirement. The budget should account for request duration as well as the time between attempts.
When the budget expires, return a useful outcome. State which step failed, what work is known to be complete and what remains uncertain. Do not let the agent convert an exhausted retry loop into a success summary. A clear partial result gives the user a way to recover without assuming the entire task must be started again.
Treat side effects as a separate design problem
A read-only query and a command that creates a ticket have different consequences when repeated. Classify your tools accordingly. The classification should describe actual behavior, not just the HTTP method or the tool name. A seemingly harmless read endpoint can trigger work in some systems, and a write endpoint may provide a documented deduplication mechanism.
For each side-effecting tool, ask how the application will recognize the same logical operation on a later attempt. The user intent to create one ticket should not become a fresh intent merely because a network response was lost. Keep a stable operation identifier outside the model's generated text and preserve it across retries of that same action.
Also decide when an operation is genuinely new. A user changing the requested ticket content may represent a different action, not another attempt at the original one. The boundary must be clear enough to avoid both duplicate execution and accidental suppression of legitimate work. That is an application contract, not something a general retry loop can infer reliably.
Understand the provider's idempotency contract
Some services support idempotency keys or another way to deduplicate repeated operations. Read the exact contract. Check which endpoints support it, how long keys are retained, whether request parameters must match and what response a duplicate attempt returns. Do not assume that adding an arbitrary header makes an operation idempotent.
In the fictional ticket system, a stable key could identify the user's one requested ticket creation. If the response is lost, a repeated request with the same key might return the original result under the service's documented behavior. That allows the application to reconcile the operation without asking the model to guess whether a ticket already exists.
Idempotency has boundaries. It may cover ticket creation but not a later notification or a separate database update. Map the entire workflow and identify where exactly-once behavior is not provided. Where the target service lacks a suitable mechanism, use a deliberate reconciliation or review step instead of presenting a local retry counter as a complete guarantee.
Reconcile uncertain outcomes before continuing
When a side-effecting request times out, the next useful step may be a read that checks the operation's state. Use an authoritative identifier when available. Searching for a ticket with a similar title can be ambiguous if several legitimate tickets share that title. A reliable reconciliation path should distinguish the intended operation from unrelated records.
If the target service confirms completion, record the result and continue from the next step. If it confirms that the operation did not occur, apply the retry policy for that action. If the state remains unknown, stop or escalate according to the consequence of duplication. Unknown is a real operational state and should remain visible.
Avoid making the agent narrate uncertainty away. A response such as the request probably failed is not evidence. The user should receive a precise description of what the application knows: the request was submitted, no response arrived, and completion could not be verified. That wording supports an informed recovery decision instead of silently choosing a risky replay.
Preserve progress when only one step fails
A multi-step task should not have to restart from the beginning whenever one API call fails. Record completed steps and their outputs in a durable workflow state appropriate to the application. For the ticket example, successful ticket creation and a failed update notification should be represented as two different outcomes.
The recovery path can then retry or reconcile the notification without creating another ticket. This requires the application to store the ticket identifier and the fact that creation was confirmed. A conversational summary alone may be insufficient if the agent session is interrupted or restarted. Use a state record that the resumed workflow can inspect.
Be careful with dependencies between steps. A later operation may rely on an earlier result that has changed or expired. Resuming should include the checks necessary to confirm that the saved state is still valid. Preserving progress means avoiding unnecessary repetition, not blindly trusting every old result forever.
Handle partial streams explicitly
Streaming adds another kind of partial state. The user may have seen text before the provider connection fails. The application needs to distinguish a partial answer from a completed response. Appending a new model's continuation without a clear boundary can produce a result whose reasoning or instructions are inconsistent with the text already displayed.
For a text-only answer, the product might mark the response incomplete and offer a fresh attempt. For an agent workflow, inspect whether any tool calls were accepted before the stream ended. Do not infer action completion from the fact that some explanatory text appeared. The text stream and the side-effect record are separate sources of evidence.
Design this behavior before the failure occurs. The interface should make interruption understandable without overwhelming the reader with internal stack details. A short message naming the unfinished step and the available recovery action is usually more useful than either a generic error or a confident answer assembled from incompatible partial outputs.
Test recovery without contacting real users
Build failure scenarios in an isolated environment. Simulate a failure before a request is sent, a failure after the target performs the action, a delayed response and a repeated callback. These cases exercise different assumptions. A test that only returns an immediate error cannot establish what happens after an uncertain side effect.
Use fixtures or a test double for external notifications so the evaluation does not email real people or create live tickets. Count the intended actions and inspect the workflow state after each failure. The assertion should concern the user outcome, such as one ticket with a known identifier, rather than merely checking that the retry function was called.
Include recovery after a process restart. An in-memory deduplication set may appear to work until the application restarts or another worker handles the next attempt. If the correctness claim depends on durable state, the test needs to exercise that boundary. Document which parts are simulated and which provider behavior remains outside the test.
Keep operational logs useful and limited
You need enough information to understand a failed attempt, but not an unbounded copy of every prompt and tool payload. Prefer operation identifiers, error categories, timing, attempt counts and state transitions. Redact credentials and avoid recording private customer content unless there is a specific authorized need and an appropriate retention policy.
A safe error record can still show that a request timed out after submission and that reconciliation later found the completed ticket. That sequence is often more useful than a raw dump of the model conversation. Link related events with a stable trace or operation identifier so you can inspect the chain without copying sensitive data into every log line.
Check the failure path itself. Logging can throw, response parsing can fail, and a cleanup step can accidentally remove the only record needed for reconciliation. Keep the operational policy understandable when dependencies are unavailable. The recovery system should fail in a way that preserves uncertainty rather than inventing a completed or cancelled state.
Give the user an honest recovery choice
At the end of a failed workflow, explain the state in terms the user cares about. The ticket was created but the notification was not confirmed is more actionable than a generic timeout. Where the state is unknown, say which operation is uncertain and why another attempt may require a check first.
Offer only actions the application can perform safely under its contract. A retry button should not secretly restart every completed step. A resume action should identify the checkpoint it uses. If a manual review is required, provide the operation reference and the evidence needed to resolve it rather than asking the user to reconstruct the entire history.
Good retry handling is not the ability to keep trying forever. It is the ability to recover within a clear budget while preserving what is known about side effects. The model can help explain the problem, but the workflow needs explicit state, bounded attempts and a verification path. Those controls make failures visible and can reduce the risk that a lost response leads to unnoticed duplicate work.