RequestOptions

View as MarkdownOpen in Claude

Every REST resource method accepts a trailing requestOptions argument that controls the transport for that one call: how long to wait, whether to retry, how to back off, and an AbortSignal to cancel. Pass the same object as the requestOptions option of the RestClient constructor to set a client-wide default. A per-request value overrides the client default field by field; an unset field inherits.

Pass a plain object literal, typed as RequestOptionsInit. The RequestOptions class is exported too and is accepted anywhere the plain object is.

import type { RequestOptionsInit } from "@signalwire/sdk";

Properties

timeout
numberDefaults to 30

Maximum seconds per attempt. When exceeded, the request throws a RestTransportError (see RestError).

retries
numberDefaults to 0

Number of retry attempts after the first failure, so total attempts are retries + 1. Retries are off by default.

retryOnStatus
ReadonlySet<number>

HTTP statuses that trigger a retry. Defaults to 429, 500, 502, 503, and 504. GET, PUT, and DELETE retry on any status in the set. POST and PATCH retry only on 429 and 503, which mean the request was not processed, so a partially applied write is never replayed.

retryBackoff
numberDefaults to 0.5

Base seconds for exponential backoff between retries, doubling each attempt. A Retry-After response header is honored when present.

abortSignal
AbortSignal

Cancels the request. The signal is passed straight to fetch, so an in-flight request is interrupted, and it is checked again before every retry.

Examples

Client-wide default

import { RestClient } from "@signalwire/sdk";
const client = new RestClient({
requestOptions: { timeout: 10, retries: 2 },
});
const numbers = await client.phoneNumbers.list();

Per-request override with cancellation

import { RestClient } from "@signalwire/sdk";
const client = new RestClient();
const controller = new AbortController();
const agents = client.fabric.aiAgents.list(undefined, {
timeout: 5,
abortSignal: controller.signal,
});
setTimeout(() => controller.abort(), 2000);
await agents;

Retries on every page of an iteration

paginate() forwards the same requestOptions to every page fetch.

import { RestClient } from "@signalwire/sdk";
const client = new RestClient();
for await (const address of client.fabric.addresses.paginate(undefined, { retries: 3 })) {
console.log(address.name);
}