Skip to navigation

Configure idempotency headers

View as Markdown

For endpoints you’ve configured as idempotent, Fern’s SDKs allow users to specify idempotency headers for safe request retries. Typically the headers include Idempotency-Key, but you can also specify additional headers.

Generated SDK behavior

The generated SDKs expose idempotency headers as parameters only for endpoints marked as idempotent, ensuring users know exactly which invocations are idempotent.

const response = await client.transactions.send({
amount: 100,
currency: "usd",
}, {
idempotencyKey: "64099353-b48b-4dcd-98b7-74df1cc57933"
});

Auto-generate idempotency keys

Generated SDKs can attach an idempotency-key header automatically, generating a UUIDv4 value for each request unless the caller supplies one. Turn it on with client.idempotencyKeyGeneration at the top level of sdk-config.yml for every target, or under a single target’s client block:

sdk-config.yml
client:
idempotencyKeyGeneration:
enabled: true

By default the SDK sends an Idempotency-Key header on POST and PUT requests. Set headerName and methods to change them:

sdk-config.yml
client:
idempotencyKeyGeneration:
enabled: true
headerName: X-Idempotency-Key
methods:
- POST
- PUT
- PATCH

Setting up idempotency headers

Configure the idempotency headers your API uses, then mark individual endpoints as idempotent:

openapi.yml
x-fern-idempotency-headers:
- header: IDEMPOTENCY-KEY
name: idempotency_key
paths:
/plants:
post:
x-fern-idempotent: true

For full configuration details, see Idempotency in OpenAPI.