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

# Idempotency & Replayability

> How Monigo guarantees correctness even when things go wrong.

Monigo is built on event sourcing principles. Every action is recorded as an immutable event, which means the system can always reconstruct its state — and you can always replay events to fix mistakes.

## Idempotency keys

Every mutating API request should include an `Idempotency-Key` header (or `idempotency_key` in the request body for event ingestion). Monigo stores the response for each unique key and returns the same response for duplicate requests.

```bash theme={null}
curl -X POST https://api.monigo.co/v1/events \
  -H "Idempotency-Key: req_abc123" \
  -d '{ ... }'
```

If you send the same request twice with the same key:

* The event is recorded once
* Both requests return the same `200 OK` response
* Your customer is not double-charged or double-paid

Idempotency keys expire after 24 hours. After expiry, the same key will create a new record.

## Replaying events

If you discover a bug in your payout calculation after the fact, you don't need to manually recalculate everything. Monigo lets you:

1. Fix the payout rule
2. Replay affected events through the new rule
3. Generate corrected payout slips

This is available in **Dashboard → Events → Replay** or via the API:

```bash theme={null}
POST /v1/events/replay
{
  "from": "2026-01-01T00:00:00Z",
  "to": "2026-01-31T23:59:59Z",
  "event_name": "ride_completed"
}
```

<Warning>
  Replaying events generates new payout slips. Monigo will detect if a customer would be double-billed and flag those slips for review before submitting.
</Warning>

## Regenerating invoices

If an invoice was generated with incorrect data, you can void and regenerate it:

```bash theme={null}
POST /v1/invoices/{id}/void
POST /v1/invoices/{id}/regenerate
```

The regenerated invoice reflects the current state of all events for that billing period.

## The audit log

Every event, invoice, and payout in Monigo has a full audit trail. You can see exactly what happened, when, and why — useful for resolving customer disputes and passing financial audits.
