# Configure idempotency headers

> SDKs that safely support retrying requests

<Warning title="Pro and Enterprise feature">
  This feature is available only for the [Pro and Enterprise plans](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).
</Warning>

For endpoints you've configured as idempotent, Fern's SDKs allow you to
specify idempotency headers. Typically the headers include `Idempotency-Key`,
but you can also specify additional headers.

## How it works for SDK users

Your SDK users can specify an idempotency header like this:

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

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

  <CodeBlock title="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()
    );
    ```
  </CodeBlock>

  <CodeBlock title="Go">
    ```go {7}
    response, err := client.Transactions.Send(
      ctx,
      &SendTransactionsRequest{
        Amount: 100,
        Currency: Currency.USD,
      },
      option.WithIdempotencyKey("64099353-b48b-4dcd-98b7-74df1cc57933"),
    )
    ```
  </CodeBlock>
</CodeBlocks>

<Note>
  The generated SDKs will not allow users to specify idempotency headers
  for non-idempotent endpoints. This is to ensure that the user knows exactly
  which invocations are idempotent and which are not.
</Note>

### Setting up idempotency headers

To set up idempotency headers in your API, you need to do the following in your `overrides` file:

1. Configure the idempotency headers
2. Mark individual endpoints as idempotent

<Tabs>
  <Tab title="OpenAPI">
    <CodeBlocks>
      <CodeBlock title="openapi-overrides.yml">
        ```yaml
        # Configure the idempotency headers
        x-fern-idempotency-headers:
          - header: IDEMPOTENCY-KEY
            name: idempotency_key

        # Mark an individual endpoint as idempotent
        paths:
          /foo:
            post:
              x-fern-idempotent: true
        ```
      </CodeBlock>
    </CodeBlocks>
  </Tab>

  <Tab title="Fern Definition">
    <CodeBlocks>
      <CodeBlock title="api.yml">
        ```yaml
        # Configure the idempotency headers
        name: idempotency-headers
        auth: bearer
        idempotency-headers:
          Idempotency-Key: string
          Idempotency-Expiration: integer
        ```
      </CodeBlock>

      <CodeBlock title="service.yml">
        ```yaml
        # Mark an individual endpoint as idempotent
        endpoints:
          foo:
            idempotent: true
        ```
      </CodeBlock>
    </CodeBlocks>
  </Tab>
</Tabs>

```
```