# Retries, delivery, and usage

Treat each logical event as one immutable payload and identifier, even when the network requires retries.

## Idempotency

Send `Idempotency-Key` (1 to 128 visible ASCII characters). Reuse it with the same application and payload for retries. The replay window is 24 hours. The first request returns `202` and `replayed: false`; an identical replay returns `200`, the original notification ID, and `replayed: true`. Conflicting content returns `409` and `reason: idempotency_conflict`.

`external_id` is optional and remains reserved within an application while its history exists. Do not reuse an external ID for a different message. Device array order and duplicates do not change replay identity. A title/body/configuration change is a new payload, not a retry.

## A bounded retry policy

- Preserve the exact JSON body and idempotency key before the first request.
- Retry transport timeouts, `408`, and transient `500/502/503/504` at most twice with backoff and jitter. A timed-out request may already have been accepted.
- For `429`, honor `Retry-After` (seconds or HTTP date). If the wait exceeds your task budget, stop and report when to retry; a quota reset may be much later than an ordinary throttle.
- Do not automatically retry `401`, `403`, `404`, `409`, or `422`. Correct credentials, scope, recipient approval, conflict, or fields first.
- Stop after the bounded attempts or event deadline. Report an ambiguous outcome as unknown, never as a definite failure followed by a new-key resend.

The downloadable Node.js example implements two retries, 10-second per-request timeouts, and a 30-second maximum retry wait. The other examples make one request; rerun them with the same key and body only when appropriate.

## Delivery evidence

| Evidence | What it proves |
| --- | --- |
| `202` and notification ID | Durable acceptance into Pijon. |
| History / recipient Inbox | Stored message and recorded delivery outcomes. |
| `provider_accepted` | Push provider accepted the attempt. |
| Provider receipt | Upstream handoff information, not guaranteed display. |
| Device display observed | Actual display on that device for that test. |
| `read_at` | Recipient read state, distinct from push acceptance and sync. |

States include `queued`, `leased`, `processing`, `retrying`, `provider_accepted`, `failed`, `suppressed`, `expired`, `inbox_only`, and `partial`. `simulated` is local test evidence only. Script keys cannot poll History; use the account app. Production-device verification is separate from API deployment.

## Allowances

Usage is per independent receiving endpoint. The sender owns used and reserved allowance; recipients are free. Both daily and monthly availability apply. Accepted internal retries and replayed requests do not add another unit for the same notification/endpoint. Provider acceptance settles a reservation; pre-acceptance failure releases it.

Calendar boundaries default to UTC. There is no automatic paid overage. A limit rejection does not queue the request until reset. Ingress throttles, pending queue bounds, and per-key throttles also apply independently of plan allowances. Inspect Usage in the app and follow `Retry-After`.
