Skip to content

Send Idempotency-Key on POST/PUT/PATCH so retries are safe #47

@justin-layerv

Description

@justin-layerv

Summary

After the next qURL prod release, the API will support the `Idempotency-Key` header end-to-end on state-mutating endpoints — so a retried request with the same key returns the original response instead of creating a duplicate.

This SDK should generate and forward that header automatically so users do not have to think about it.

Why

`#19` ("POST retries on network errors can duplicate items (batch_create especially)") is the user-facing symptom. Today, a transient 5xx or socket reset on `client.create()` / `batch_create()` / mint flows can produce duplicate resources after the SDK retries — because each retry is a fresh request from the server's perspective. With idempotency-key forwarding in place, the server collapses retries onto the original response.

Proposed surface

  • Auto-generate a UUIDv7 `Idempotency-Key` per outbound POST/PUT/PATCH (read-only methods do not need it).
  • Reuse the same key across retries of the same logical call — do NOT regenerate inside the retry loop, otherwise the server sees N independent writes.
  • User override via a per-call option (e.g. `idempotency_key=...` on the public methods) for callers that want to tie idempotency to their own request ID (e.g. an upstream job ID) instead of an SDK-generated UUID.
  • Apply to both the sync (`client.py`) and async (`async_client.py`) clients.
  • Documentation: brief README section explaining what the SDK now does on retries, and how to override; docstrings on the affected methods.

Definition of done

  • UUIDv7 generated per POST/PUT/PATCH and sent as `Idempotency-Key`.
  • Retry path reuses the same key.
  • Per-call override exposed (sync + async).
  • README/docstrings updated.
  • Test: simulate a transient 5xx + retry, assert the second request carries the same `Idempotency-Key` value as the first (and that the SDK does not surface a duplicate on the caller side when the server returns the cached response).
  • Closes POST retries on network errors can duplicate items (batch_create especially) #19.

Sequencing

Gate landing this on the qURL prod release that ships server-side `Idempotency-Key` support on `POST /v1/api-keys`. The generic middleware on other POST endpoints is already live, so the SDK can begin sending the header sooner — but holding until the API-key path is also covered keeps the rollout coherent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions