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

# How-to: Use idempotency keys

> Attach an idempotency key to a loan operation so the same user intent lands onchain at most once

An idempotency key lets the SDK recognize when two submissions represent the
same user intent and collapse them into one onchain outcome. Use it whenever the
same intent might reach the service more than once. Common cases:

* A caught error you decide to retry across processes.
* A user who double-clicks the submit button.
* A queue worker that replays after a deploy.
* A serverless function that times out and reruns.
* A webhook consumer that fires the same job twice.

`kit.borrow.borrow`, `kit.borrow.repay`, `kit.borrow.addCollateral`,
`kit.borrow.withdrawCollateralRepayIfNeeded`, and `kit.borrow.closeLoan` all
accept an `idempotencyKey` on the call.

## Prerequisites

Before you begin, ensure that you've:

* [Installed the App Kit SDK](/app-kit/tutorials/installation)
* [Configured an adapter](/app-kit/tutorials/adapter-setups)

These are required so any example below runs with a valid `kit` and `adapter`.

## Generate one key per user intent

Generate a UUID when the user first submits the intent, persist it alongside the
request, and reuse the same key on every later submission of that intent:

```typescript TypeScript theme={null}
import { randomUUID } from "node:crypto";

const idempotencyKey = randomUUID();

const result = await kit.borrow.repay({
  from: { adapter, chain: "Arc_Testnet" },
  loanId: "11111111-1111-4111-8111-111111111111",
  repayAmount: "100.0",
  idempotencyKey,
});
```

The service binds the key to the request parameters and to the Circle-signed
execution it produces. A same-key replay behaves differently depending on the
execution's state:

* While the execution is unsettled and hasn't expired (default TTL: 1 minute),
  the replay returns the same signed execution, which gets resubmitted onchain.
* If the execution has already settled onchain, the service returns
  `IDEMPOTENCY_KEY_ALREADY_EXECUTED`. Read this as "the first attempt succeeded,
  don't submit again."
* If the signed execution's deadline has passed, the service returns
  `SIGNED_BUNDLE_EXPIRED` and the request needs a new key.

For delays longer than the signed execution's TTL (queue workers replaying after
a deploy, serverless functions rerunning much later), reuse the same key if the
first attempt has already settled onchain, and mint a new key if it hasn't.

To resume a failed operation from the same process, use
[`kit.borrow.retry`](/app-kit/references/borrow-error-handling#retry-a-failed-operation)
instead.
