Introduction

A retry is safe when repeating the request cannot change the outcome. Payment APIs make this explicit with idempotency keys: the client sends a unique key, and the server returns the first result for any repeat. The Stripe API documents this pattern, and an IETF HTTPAPI draft standardises an Idempotency-Key header. Generative AI endpoints differ in two ways. A single call can take seconds to minutes. And the provider may start, and charge for, work before the client sees a response. The failure cases that are hardest to reason about are the ambiguous ones: a read timeout or a dropped connection after the request body was delivered. In those cases the client cannot know whether the work began.

Client SDKs decide what happens next. Most ship with automatic retries switched on, which hides transient errors from application code. This audit asks a narrow, measurable question. Under default settings, how many times does each SDK send the same generation request when the server fails, and does any attempt carry a key that would let the server deduplicate it?

The retry policies are documented piecemeal, in SDK READMEs and source code. The openai and anthropic Python clients document a default of two retries. The google-genai client exposes HTTP retry options. The fal-client source defines a maximum of ten attempts, with retryable status codes 408, 409 and 429. The Replicate client retries only non-POST methods through its retry transport. Each Stainless-generated base client contains an idempotency-key mechanism (_idempotency_header), but in the versions tested it is initialised to None. The nearest scholarly neighbour our OpenAlex check found is an article on architecting reliable payment pipelines (references); it concerns payments, not generative AI clients.

For agent tool writes rather than model calls, the LIMBO sandbox study (arXiv 2609.29095) reports that offering an idempotency key on every write lowered duplicate rates from 28% to 4%; it injects faults at tool services and does not audit model-provider SDKs. Server-side idempotency-key semantics are an active research topic; for example, a 2026 Zenodo draft describes a replay classifier that falsely flags an exact retry as conflicting, which is a server-side issue rather than an SDK default. A web search on 2026-10-25 found no measured, cross-SDK audit of what generative AI SDKs actually send on the wire when retrying. Pubroot 2026-162 describes a server-side idempotency layer for browser-driven media generation. It motivates the question but does not measure client SDKs.

Method

We installed the nine SDKs, pinned at the versions above, in one Python 3.13 virtual environment. A stub HTTP server on 127.0.0.1 logged every attempt: method, path, any header whose name contains “idempot”, the x-stainless-retry-count header, and a hash of the request body. Each SDK was pointed at the stub through its documented base-URL option and given a fake key. It then made one generation call: chat completion, messages, generate_content, prediction create, or queue submit, as appropriate.

The stub applied one of three scenarios to every attempt:

  • e500: return HTTP 500 with a JSON error.
  • timeout: read the request, then wait 2.5 seconds against a 1-second client timeout.
  • drop: read the full request, then close the socket without responding.

We changed only the per-attempt timeout. Retry counts, backoff and status-code policies were left at their defaults. Each SDK and scenario pair ran three times, for 81 logical calls. One harness bug, in which the google-genai client object was garbage-collected before the call, invalidated that SDK’s first nine runs. They were re-run after the fix, and the invalid rows are kept separately.

In a mitigation run, the four Stainless-generated SDKs passed a caller-chosen Idempotency-Key in extra headers across the same three scenarios.

Results

Attempts per logical call were identical across the three repetitions in every cell, and the request body hash never changed between attempts.

  • openai 3.37.0, anthropic 2.3.0, groq 1.7.0 and together 3.0.0: three attempts in each of e500, timeout and drop.
  • cohere 7.3.0: three attempts on e500 and drop, one on timeout.
  • fal-client 1.0.3: one attempt on e500, ten attempts on timeout and on drop. These took 54 to 62 seconds of wall-clock time per logical call.
  • mistralai 3.5.0, google-genai 2.33.0 and replicate 1.0.7: one attempt in every scenario.

In total the stub received 138 duplicate POSTs across 81 logical calls. Every attempt lacked an idempotency header: 0 of 219. The replicate client did not honour the timeout argument in our harness, so its timeout scenario received the delayed 500 instead. It still sent one attempt.

In the mitigation run, the caller’s key arrived unchanged on all three attempts in all 12 runs (four SDKs times three scenarios).

Discussion

The retry-heavy cells are the timeout and drop rows, because that is where the server may already be working. Four of the nine SDKs either do not retry at all (Mistral, google-genai, Replicate) or do not retry on timeouts (Cohere), and for them the ambiguous timeout case surfaces to the application. The four Stainless SDKs and fal-client resend the identical body two or nine extra times, with no key a server could use to recognise the repeat.

Hypothesis (not tested): on a provider that bills per request and does not deduplicate, each timed-out or dropped generation could be billed up to three times under the Stainless defaults and up to ten times under fal-client’s queue submit. The real figure depends on whether the provider had started work and on any server-side deduplication. Neither was measured.

The mitigation is cheap at the client: pass a stable key per logical job and reuse it across retries. Our run shows that the extra-headers path keeps the key stable through the SDK’s own retries. Whether a given provider honours the header is a separate, provider-side question. Absent that guarantee, applications that cannot tolerate duplicates can set the retry count to zero and retry at the job level with their own deduplication, as described for media pipelines in 2026-162.

Limitations

  • The audit is client-side and synthetic. It covers one version of each Python SDK, three failure modes and default settings with a shortened timeout. Streaming calls, async clients, other languages and 429 or Retry-After handling were not tested.
  • A lowered timeout could change behaviour if an SDK scales its retries with the timeout. We saw no evidence of that, but did not test longer timeouts.
  • Provider billing and deduplication were not measured.

Reproducibility

Code: https://github.com/buildngrowsv/pubroot-[REDACTED_SECRET]-retry

The pilot code is published at that URL: the stub, the per-SDK caller, the run scripts, raw attempt logs, client outcomes, the analysis script and the pinned requirements. No certificate or key is included; the stub generates a throwaway localhost certificate at run time. The logged attempts of the main matrix span about 10 minutes of wall-clock time, and the runs need no network after installation.

References