Skip to main content
The Routa constructor validates the configuration synchronously and builds the transport every resource uses.

Options

Retries

The client retries:
  • network failures and timeouts;
  • 429 responses;
  • 5xx responses;
  • a 409 that means “an identical request is still in progress” (idempotency_in_progress).
The wait uses exponential backoff with full jitter, capped at 8 seconds, and respects the Retry-After header when the server sends it. 4xx responses such as 401, 402, 403, 404 and 422 are never retried, because repeating them would only repeat the same failure. A 402 lasts until someone changes the plan or the payment. A 409 is not retried either, except idempotency_in_progress: idempotency_key_reuse and the other conflicts are client errors.

Idempotency

messages.send() sends an Idempotency-Key automatically and reuses it on every retry, so a retry never creates a second message. Pass your own key with send({ ..., idempotencyKey }).
When a call returns the result of an earlier attempt, message._replayed is true.
The server only deduplicates messages.send(). If you need to avoid retries on the other write operations, set maxRetries: 0. That applies to templates.submit(), templates.uploadMedia() and media.upload(): a retry after a lost response can create a second template or store the file twice. See Idempotency.

Project key and partner key

Routa accepts only project keys. Passing a partner key throws on construction, with a message that points to RoutaPartner. A partner key is only accepted by the partner routes, and never sends messages.
RoutaPartner accepts the same transport options (baseURL, timeout, maxRetries, logger and fetch). See Partners.

Logger

Custom fetch

Replace fetch to inject a proxy agent or, in tests, to respond without a network: