---
title: "Idempotency Key — definition | Nuri Glossary"
description: "A unique label on a payment request so retries cannot charge twice."
lang: "en"
type: "glossary-term"
canonical: "https://nuri.com/glossary/idempotency-key"
---

# Idempotency Key

A unique label on a payment request so retries cannot charge twice.

## Basically

An idempotency key is a unique label you add to a payment request. It stops the same payment being processed twice when you retry.

## Key Takeaways

- An idempotency key is a unique identifier generated by the client and sent with a payment API request. The server uses it to recognise retries and return the cached result instead of processing a duplicate transaction.
- Major payment processors including Stripe, Square, and PayPal all implement idempotency keys, but each uses a different header name and retention period. An IETF draft proposes standardising on the Idempotency-Key HTTP header.
- Bitcoin's UTXO model provides natural idempotency at the protocol level because a given output can only be spent once. Payment APIs built on top of blockchain networks still use idempotency keys to prevent duplicate crediting at the application layer.

## What Is an Idempotency Key?

An idempotency key is a unique string that you attach to an API request. It guarantees that the same operation is never processed more than once. The term comes from the mathematical idea of idempotence: applying an operation several times produces the same result as applying it once.
Payment gateways and financial APIs use idempotency keys to solve a fundamental distributed systems problem. A dropped connection can leave you unsure whether a payment request succeeded because the response never arrived. A retry without a key can charge the customer twice, while a retry with a key makes the server return the original result without reprocessing.
HTTP methods such as GET and DELETE are inherently idempotent because repeating them produces the same server state. POST requests create payments and charges, so they are not idempotent. Payment processor APIs therefore use idempotency keys mainly with POST endpoints.

## How It Works

The idempotency key mechanism follows a straightforward flow between the client application and the payment server. The client attaches the key to its request, and the server uses it to recognise later retries.

## Code Example

A typical implementation sends the idempotency key as an HTTP header with a payment creation request. You include the same key whenever you retry that request.
The key must belong to the intended operation, not to the HTTP request itself. You should always use the same key across retries of one logical payment. You should use a different key for a different payment.

## Server-Side Behavior

The server compares the incoming request parameters with the stored original when it receives an idempotency key it has seen before. Three outcomes are possible:
Parameter validation creates an important subtlety. Most providers do not store a result against the key if the original request fails validation before processing begins, so you can fix the request and retry with the same key.

## Implementation Across Payment Providers

Every major payment processor supports idempotency keys. Each provider has adopted a slightly different approach:
An IETF draft, draft-ietf-httpapi-idempotency-key-header, proposes standardising the Idempotency-Key HTTP header across all APIs. It specifies error responses for missing keys (HTTP 400), parameter mismatches (HTTP 422), and concurrent requests (HTTP 409). The document remains an Internet-Draft as of 2025 and has not been published as an RFC.

## Bitcoin and Natural Idempotency

Bitcoin's UTXO model provides a form of natural idempotency at the protocol layer. Each transaction input references a specific unspent output by its TXID and output index. The network rejects any attempt to spend that output again once it is spent, making double-spending impossible under normal conditions.
A transaction's TXID is the double-SHA256 hash of the serialised transaction data, so it is deterministic and the same transaction always produces the same identifier. Broadcasting the same signed transaction twice does not create two payments because miners and nodes recognise the duplicate TXID and discard it.
Applications built on top of Bitcoin still need idempotency keys at the API layer. An exchange processing a withdrawal uses these keys to ensure that a network timeout during the withdrawal request does not trigger two on-chain transactions. The blockchain prevents double-spending of a specific UTXO, but it cannot stop an application from constructing and broadcasting two separate transactions that spend different UTXOs for the same withdrawal.

## Network Timeout Recovery

A network timeout is the most common scenario. The server may process a payment request successfully, but the client may receive an error instead of the lost HTTP response and then retry. A retry without an idempotency key charges the customer twice, while a retry with one returns the cached successful response and creates no duplicate charge.

## Server Crash Mid-Processing

The idempotency key guides what happens when you retry after a server crash during payment processing. The server processes the request fresh if no result was stored because the crash happened before completion. It returns the stored result if the operation completed before the crash, so the customer is charged at most once in either case.

## Client-Side Double Submissions

Users can cause double charges by double-clicking a "Pay" button. Mobile apps with aggressive retry logic and frontend code that fires duplicate requests can cause the same problem. Idempotency keys ensure that only the first request is processed, regardless of how many duplicates arrive.

## Payment Orchestration Systems

Payment orchestration architectures may route a single payment through multiple processors or retry it across different payment rails. Idempotency keys ensure that each intended payment is processed exactly once as the orchestration layer retries failed routes.

## Cryptocurrency Payment Gateways

Crypto payment gateways expose REST APIs for merchants and use idempotency keys in the same way as traditional processors. The key prevents the gateway from generating multiple addresses or broadcasting multiple transactions for the same intended payment when a merchant requests a payment address or initiates a withdrawal. Stablecoin payments make this safeguard especially important because their finality characteristics differ from traditional card networks.

## Why It Matters for Digital Payments

Payment infrastructure is moving towards instant settlement and real-time processing, which makes the consequences of duplicate transactions more severe. Traditional card payments have built-in reversal mechanisms through chargebacks, but stablecoin and cryptocurrency payments settle with finality and cannot be reversed once confirmed. Payment APIs must therefore prevent duplicates rather than treating this protection as optional.
Developers building on platforms like Spark need idempotent payment design. Any API that initiates value transfer should support idempotency keys to protect against unpredictable failures in distributed systems. The research on payment processor stablecoin integration offers a deeper look at how modern payment systems handle these challenges.

## Key Expiration

Idempotency keys are not stored forever. Stripe retains keys for 24 hours (API v1) or 30 days (API v2), while PayPal retains them for up to 45 days depending on the endpoint. The server treats a retry as a new request and processes it again after the key expires, so systems that may retry after long delays must account for this window.

## Key Reuse with Different Parameters

Accidental reuse of an idempotency key with different payment parameters makes the server return an error instead of processing the second payment. This safety feature means applications must carefully manage key generation to avoid collisions. UUID v4 provides sufficient entropy, with 2^122 possible values, to make accidental collisions astronomically unlikely.

## Storage and Performance Overhead

Servers must store every idempotency key and its associated response for the retention period. High-volume payment processors handling millions of requests per day accumulate substantial key-response stores. Efficient indexing, TTL-based expiry, and storage architecture become important considerations at scale.

## Concurrent Request Handling

Two requests with the same idempotency key can arrive simultaneously and create a race condition that the server must handle. Most implementations process the first request and return HTTP 409 Conflict for the second. Applications should wait and retry, ideally using exponential backoff with jitter to avoid the thundering herd problem.

## Scope Boundaries

Idempotency keys are typically scoped to a specific API endpoint and account. You cannot reuse a key from a charge request for a refund request, even if both relate to the same transaction. PayPal explicitly requires unique keys per API call type, so developers must understand these scope boundaries to avoid unexpected behaviour.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. You should always do your own research before using any protocol or technology.
Part of the [Nuri glossary](https://nuri.com/glossary), which defines 1876 Bitcoin, Lightning, wallet, stablecoin and payment terms.
