Idempotency
How ulex deduplicates writes: the Idempotency-Key header, the 24-hour replay window, response replay semantics, conflicts on replay, how it differs from X-Ulex-Request-Id, natural-key idempotency in MCP tools, and the operations that are never idempotent.
Network calls fail in the two worst ways: after the server did the work, or during it. Idempotency keys make the first case safe.
POST /api/v1/users HTTP/1.1
Authorization: Bearer ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au
Idempotency-Key: 3c9d1f77-0b2e-4a58-9d61-5e7a2c40b913Send it on every POST that creates a resource. It is a header, never a body field, and never a query parameter.
#Semantics
ulex stores (tenant_id, method, path, key) → (status, body, headers) for 24 hours.
| Situation | First call | Retry with the same key |
|---|---|---|
| Succeeds | 201 + body | 201 + the same body, byte for byte |
| Fails validation | 400 + body | 400 + the same body, not re-validated |
Fails with 5xx | 500 + body | the original 5xx is not cached; the request is retried for real |
| Connection drops after the write | unknown | 201 + the original body |
| Different body, same key | — | 409 conflict |
That last row is the important one:
{
"error": {
"type": "conflict_error",
"code": "invalid_request",
"message": "This Idempotency-Key was already used with a different request body.",
"param": "Idempotency-Key",
"request_id": "req_01M3PSW9R0175NAW62NYR403R8",
"retryable": false,
"hint": "Use a new key, or resend the original body byte for byte."
}
}HTTP/2 409 ConflictA replayed response is the original response, including its original id and created_at. If you were expecting a freshly generated id on the retry, you will get the old one. That is the point: the retry is a read of the first outcome, not a second write.
#Key format
Any string, 1–64 characters. In practice use a UUID v4, or a deterministic key derived from the operation:
import { createHash } from "node:crypto";
// Random: one key per logical create, reused across retries of that create.
const key = crypto.randomUUID();
// Deterministic: the same logical create always produces the same key, so a
// crash-and-retry from scratch converges instead of duplicating.
function stableKey(scope: string, ...parts: string[]): string {
return createHash("sha256").update([scope, ...parts].join("