429 as an operating condition rather than an edge case.
Your key’s limit, its remaining requests, and the window boundary come back on every response as X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset, plus Retry-After on a 429. The SDK retries on the schedule those headers state and keeps no schedule of its own.
How the SDK retries
- On a
429, the SDK reads the wait fromRetry-After. If that header is missing it falls back toX-RateLimit-Reset, which points at the end of the same window. - It waits exactly that long and retries, repeating for as long as the server keeps stating a wait.
- If the total time waited would pass 10 seconds, the SDK stops and throws
RateLimitErrorwithretriesExhausted: false. The wait is inrateLimitInfo.retryAfter, so your UI can tell the user when to come back instead of holding a spinner. - If a response carries no usable timing at all, the SDK stops immediately and throws
RateLimitErrorwithretriesExhausted: true.
Retry timing is not configurable. No client setting can widen a server-side
limit. If you need more headroom, ask Trustware to raise the limit on your
key.
RetryConfig type
retry configures observability only:
Properties
number
default:"5"
The number of remaining requests in the current rate limit window at which the
SDK calls
onRateLimitApproaching. For example, the default of 5 means the
callback fires when 5 or fewer requests remain before the window resets.Callbacks
(info: RateLimitInfo) => void
Called on every response that includes rate limit headers from the server,
regardless of whether the limit has been reached. Use this for passive
monitoring or to display a rate limit gauge in your UI.
(info: RateLimitInfo, retryCount: number) => void
Called every time a
429 response is received, before the SDK waits.
retryCount is the number of retries already made for this request, so it is
0 on the first 429. Use this to log rate limit events or show a warning to
the user.(info: RateLimitInfo, threshold: number) => void
Called when the remaining request count in the current window falls below
approachingThreshold. Use this as an early warning to reduce request
frequency before hitting the limit.RateLimitInfo shape
All three callbacks receive aRateLimitInfo object:
When the SDK gives up
The SDK throwsRateLimitError, which extends the native Error class rather than TrustwareError. Your onError callback is not called, because that callback takes a TrustwareError, and an instanceof TrustwareError check will not match it. Catch RateLimitError around your own calls.
retriesExhausted tells you which of the two cases you are in:
Mind the units when you render the wait:
retryAfter is a number of seconds from now, while reset is a Unix timestamp.
