> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fintoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Idempotent requests

> Safely retry POST requests

The Fintoc API supports idempotent requests. You can retry an idempotent request without performing the same operation twice. Use idempotency for resource creation requests that you might retry after a network error. Examples include [charges](/api/direct-debit-legacy/charges/charge-object), [payment intents](/api/payments-api/payment-intents/payment-intents-object), and [transfers](/api/transfers-api/transfers/transfers-create).

If a connection error occurs after you submit an idempotent request, you can retry the request without creating a second object.

To make an idempotent request, include the `Idempotency-Key: <idempotency-key-value>` header.

An idempotency key is a unique value that your client generates. Fintoc uses this key to recognize retries of the same request. Use UUID version 4 values or random strings with enough entropy to avoid collisions. Idempotency keys can contain up to 255 characters.

Fintoc saves the status code and response body from the first request for each idempotency key, whether the request succeeds or fails. Subsequent requests with the same key return the saved result, including `4xx` and `5xx` errors.

<Info>
  **Authentication needed**

  Fintoc does not save an idempotent result when authentication fails because the request does not reach the API endpoint.
</Info>

For each retry, the idempotency layer compares the request parameters with the original request parameters. Fintoc returns an error if the parameters differ.

Fintoc can remove idempotency keys automatically once they are at least 24 hours old. If you reuse a key after Fintoc removes the original result, the API processes the request as new.

All `POST` requests accept idempotency keys. Sending idempotency keys in `GET` and `DELETE` requests has no effect because `GET` and `DELETE` requests are idempotent by definition.

The following examples create a charge with an idempotency key. You can retry the request without creating a duplicate charge.

```curl theme={null}
curl --request POST "https://api.fintoc.com/v1/charges" \
--header 'Authorization: sk_test_0000000000000000' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: 31a0dd22-38e4-4392-81e1-aa3a2018b48d' \
--data-raw '{
  "subscription_id": "sub_000000",
  "amount": 1000,
  "currency": "clp",
  "metadata": {
    "customer": "123456"
  }
}'
```

```node theme={null}
// First install our Node SDK (https://github.com/fintoc-com/fintoc-node)
// $ npm install fintoc

const { Fintoc } = require('fintoc');

const fintoc = Fintoc('your_api_key')
await fintoc.charges.create({
  idempotency_key: '31a0dd22-38e4-4392-81e1-aa3a2018b48d',
  subscription_id: 'sub_000000',
  amount: 1000,
  currency: 'clp',
  metadata: {
    customer: '123456'
  },
});
```

```python theme={null}
# First install our Python SDK (https://github.com/fintoc-com/fintoc-python)
# $ pip install fintoc

from fintoc import Fintoc

client = Fintoc("your_api_key")
client.charges.create(
    idempotency_key="31a0dd22-38e4-4392-81e1-aa3a2018b48d",
    subscription_id="sub_000000",
    amount=1000,
    currency="clp",
    metadata={"customer": "123456"},
)
```
