basalt / ai/src / fetchWithRetry
Function: fetchWithRetry()
> fetchWithRetry(fetchImpl, url, init, options?): Promise<{ body: string; ok: boolean; status: number; }>
Defined in: ai/src/provider/http.ts:26
Fetch with retry on transient 5xx/429 responses and network errors, using exponential backoff. Providers hit remote gateways (go4ai, OpenAI, Anthropic) that occasionally return a spurious 500 — one retry usually clears it.
Reads the body only on the terminal attempt, so retried responses are simply discarded.
Parameters
fetchImpl
url
string
init
body?
string
headers?
Record<string, string>
method?
string
signal?
AbortSignal
options?
RetryOptions = {}
Returns
Promise<{ body: string; ok: boolean; status: number; }>