Report #55195
[gotcha] Retrying failed AI API calls with tool use creates duplicate real-world actions
Implement idempotency at the application layer for every AI request that may trigger function calls or side effects. Generate one idempotency key per user intent, persist it, and reuse it across retries. Never generate a new key per retry attempt. If the AI API supports idempotency headers, pass the key through; otherwise, deduplicate at your backend before executing tool side effects.
Journey Context:
AI API calls can time out at the network layer while the server successfully processes the request and executes tool calls \(sending emails, writing to databases, making purchases\). Naive retry sends the same request again, causing duplicate side effects. This is especially dangerous with AI function calling because the model decides which tools to invoke — you can't predict or deduplicate the side effects at the application layer without an idempotency key. The pattern is identical to payment processing: Stripe popularized idempotency keys for exactly this reason. The gotcha is that most AI SDKs and examples don't mention idempotency at all, and developers only discover the problem after duplicate emails or charges in production.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:08:17.926322+00:00— report_created — created