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

# Idempotency

Idempotency ensures that repeating a request always produces the intended outcome, no matter how many times it's sent.
This is especially important when network errors or interruptions make it unclear whether an operation has already completed.

For operations where duplicates could cause unintended effects, PaySway requires an idempotency key.
Including the same key in a retried request lets PaySway recognize it as a duplicate and return the existing result instead of performing the operation again.
This ensures you can safely retry requests without the risk of creating duplicates or executing the same action twice.

## Implementation

<Steps>
  <Step title="Generate an idempotency key">
    The idempotency key must be a valid UUID. Generate a unique UUID for each distinct request you intend to make.

    <CodeGroup>
      ```javascript JavaScript theme={null}
      import { v4 as uuidv4 } from 'uuid';

      const idempotencyKey = uuidv4();
      ```

      ```python Python theme={null}
      import uuid

      idempotency_key = str(uuid.uuid4())
      ```

      ```java Java theme={null}
      import java.util.UUID;

      UUID idempotencyKey = UUID.randomUUID();
      ```

      ```csharp C# theme={null}
      using System;

      Guid idempotencyKey = Guid.NewGuid()
      ```

      ```go Go theme={null}
      import "github.com/google/uuid"

      idempotencyKey := uuid.New()
      ```
    </CodeGroup>
  </Step>

  <Step title="Include the header in your request">
    Add the `Idempotency-Key` header to your HTTP request with the generated UUID.

    ```http theme={null}
    Idempotency-Key: 9678e160-38b3-4182-851e-9ca1d925f6ce
    ```
  </Step>

  <Step title="Handle retries">
    When you need to retry a previous request due to network issues or timeouts, always use the same idempotency key as the original request.

    <Tip>
      Store the idempotency key alongside your request metadata until you receive a successful response. This way, retries for the same entity state will always result in the same key.
    </Tip>

    <Note>
      If a retried request uses the same idempotency key but different parameters, PaySway will reject it. This prevents accidental misuse and ensures the idempotency key always refers to the same request.
    </Note>
  </Step>
</Steps>
