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

# Idempotencia

> Evita duplicar operaciones al reintentar requests.

Las operaciones mutantes aceptan `Idempotency-Key`. Úsala especialmente al crear sesiones de checkout.

## Con SDK

```ts theme={"dark"}
await onflay.checkoutSessions.create(
  {
    listingId: 'lst_...',
    customerEmail: 'comprador@ejemplo.com',
    successUrl: 'https://tu-app.com/gracias',
    cancelUrl: 'https://tu-app.com/cancelado',
  },
  { idempotencyKey: 'checkout:user_123:lst_456' }
);
```

## Con HTTP

```bash theme={"dark"}
curl -X POST https://sandbox-api.onflay.com/v1/checkout-sessions \
  --header 'Authorization: <tu-secret-key>' \
  --header 'Content-Type: application/json' \
  --header 'Idempotency-Key: checkout:user_123:lst_456' \
  --data '{
    "listingId": "lst_...",
    "customerEmail": "comprador@ejemplo.com",
    "successUrl": "https://tu-app.com/gracias",
    "cancelUrl": "https://tu-app.com/cancelado"
  }'
```

## Cómo elegir una key

Usa una key estable para la operación lógica, no una key nueva por cada retry.

Buenos ejemplos:

```text theme={"dark"}
checkout:user_123:listing_456
checkout:order_789
refund:transaction_123
```

Si reutilizas la misma key con un body distinto, la API puede devolver `409 idempotency_error`.
