Skip to content

Idempotency And Retries

Use idempotency keys when retrying side-effecting operations. This prevents duplicate projects, duplicated usage imports, repeated invoice generation, or repeated payment-provider side effects.

Example

curl "$SPENDWARE_BASE_URL/api/v1/projects/" \
  -H "Authorization: Bearer $SPENDWARE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: project:acme-ai" \
  -d '{"title":"Acme AI","currency":"USD","external_id":"acme-ai"}'
project = client.projects.create(
    ProjectCreate(title="Acme AI", external_id="acme-ai"),
    idempotency_key="project:acme-ai",
)
const project = await client.projects.create(
  { title: "Acme AI", external_id: "acme-ai" },
  { idempotencyKey: "project:acme-ai" },
);

Retry Policy

  • Retry network failures, timeouts, 429, and transient 5xx responses.
  • Do not retry validation errors until the payload is fixed.
  • Reuse the same idempotency key only with the same payload.
  • Avoid embedding sensitive data in idempotency keys.