> This page is for SDK, 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.

# 配置幂等性请求头

> 为支持重试请求的 SDK 配置幂等性请求头

> **企业功能**
>
> 此功能仅适用于[企业计划](https://buildwithfern.com/pricing)。如需开始使用，请联系 [support@buildwithfern.com](mailto:support@buildwithfern.com)。

对于您已配置为幂等的端点，Fern 的 SDK 允许用户为安全的请求重试指定幂等性请求头。通常这些请求头包括 `Idempotency-Key`，但您也可以指定其他请求头。

## 生成的 SDK 行为

生成的 SDK 仅为标记为幂等的端点公开幂等性请求头作为参数，确保用户准确知道哪些调用是幂等的。

#### 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"),
)
```

## 设置幂等性请求头

配置您的 API 使用的幂等性请求头，然后将各个端点标记为幂等：

**`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
```

有关完整配置详情，请参见 [OpenAPI 中的幂等性](/learn/zh/api-definitions/openapi/extensions/idempotency)。