Skip to content

Retries and idempotency

The Poli Page Ruby SDK retries transient failures automatically. POST requests carry an auto-generated UUID v4 Idempotency-Key header, the same on every retry of one call.

  • ConnectionError (network_error), TimeoutError (timeout), 5xx answers and 429 answers are retried.
  • Never retried: QUOTA_EXCEEDED and OVERAGE_CAP_EXCEEDED (429), STORAGE_ACCESS_DENIED (502), any other 4xx, InvalidOptionsError, a 2xx whose body is not JSON (invalid_response), a file render_to_file cannot write (io_error), and the presigned-URL download (DOWNLOAD_FAILED, timeout included). The quota codes last until the monthly reset and the bucket error until its access is restored, so waiting cannot help.
  • Up to max_retries retries (default 2 — three total attempts); when they are exhausted, the last error is raised.
  • Before retry n, the SDK waits retry_delay × 2^(n−1) × j seconds (retry_delay defaults to 0.5), j uniform in [0.5, 1.5). The wait is never shorter than that: a sleep that returns early sleeps again for the rest.
  • A Retry-After header (integer seconds or an HTTP-date) sets the wait instead, without jitter, clamped to 0–30 s. Retry-After-Ms is ignored.
  • timeout: is one deadline per attempt, covering the connection (DNS, TCP, a proxy’s CONNECT, TLS), the request and the whole answer, body included.
  • Net::HTTP never sends a request a second time by itself: every resend is one of the SDK’s counted retries, reported to on_request and on_retry.

Set max_retries: 0 on the constructor to disable retries entirely.

client = PoliPage::Client.new(
api_key: ENV.fetch("POLI_PAGE_API_KEY"),
max_retries: 0
)

Every POST request (render.*, documents.thumbnails) includes an Idempotency-Key header: a lowercase UUID v4 the SDK generates once per call and sends unchanged on every retry of that call. GET and DELETE requests and the presigned-URL download send none.

The API does not deduplicate on this header. Every POST /v1/render that reaches the renderer stores a new document, so a retry can create a second one when the first attempt was stored but its answer was lost: a 5xx raised after the document was stored, a timeout that fired while the API was still rendering (for example timeout: 10 on a 15 s render), or a network_error after the request reached the API. A 503 PUBLISH_IN_PROGRESS is raised before any render work, so retrying it never duplicates. If an extra stored document matters to you, lower max_retries or raise timeout; note that max_retries: 0 also stops the always-safe retry of PUBLISH_IN_PROGRESS.

You can supply your own key via the idempotency_key: keyword on the render call, for example to correlate a call in your logs; it is sent as is on every attempt of that call:

pdf = client.render.pdf(
project: "billing",
template: "invoice",
data: { invoiceNumber: "INV-001" },
idempotency_key: "invoice-INV-001-v1"
)

The key does not make the API return an earlier document: each call still stores a new one.

require "poli_page"
client = PoliPage::Client.new(
api_key: ENV.fetch("POLI_PAGE_API_KEY"),
max_retries: 4,
retry_delay: 0.25
)
pdf = client.render.pdf(
project: "billing",
template: "invoice",
data: { invoiceNumber: "INV-001", total: 1280 }
)