> This page is for SDKs, version Current (default).
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# Configure idempotency headers

> Configure idempotency headers for SDKs that support retrying requests

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.

#### TypeScript

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

#### Python

```python {4}
response = client.transactions.send(
  amount=100, 
  currency="USD", {
  idempotency_key="64099353-b48b-4dcd-98b7-74df1cc57933"
})
```

#### Java

```java {7}
var response = client.transactions().send(
  SendTransactionsRequest.builder()
    .amount(100)
    .currency(Currency.USD)
    .build(),
  IdempotentRequestOptions.builder()
    .idempotencyKey("64099353-b48b-4dcd-98b7-74df1cc57933")
    .build()
);
```

#### Go

```go {7}
response, err := client.Transactions.Send(
  ctx,
  &SendTransactionsRequest{
    Amount: 100,
    Currency: Currency.USD,
  },
  option.WithIdempotencyKey("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. `sdk-config.yml` doesn't have a setting for this yet. To turn it on with `generators.yml`, see [Auto-generate idempotency keys](/learn/sdks/legacy/deep-dives/idempotency#auto-generate-idempotency-keys) in the Legacy docs.

## Setting up idempotency headers

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

**`openapi.yml`**

```yaml title="openapi.yml" {2-4,10}
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](/learn/api-definitions/openapi/extensions/idempotency).