You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Beyond setTimeout: Building Robust Retry Logic for LLM API Calls in Node.js
#2
If you've ever built a production app that calls LLM APIs, you know the pain: rate limits, transient 500s, and the dreaded 60-second timeout. A simple try/catch with a setTimeout retry isn't going to cut it.
The Problem with Naive Retries
// Don't do this in productionasyncfunctioncallLLM(prompt){try{returnawaitclient.complete(prompt);}catch(e){setTimeout(()=>callLLM(prompt),1000);// fires into the void}}
This has zero backoff, no jitter, no max retries, and silently swallows the eventual failure.
What Good Retry Logic Looks Like
Here's a pattern we recommend for Node.js SDK consumers:
Only retry idempotent or safely-repeatable calls — LLM completions are usually fine
Respect Retry-After headers — rate limit responses include this
Add jitter — synchronized retries from multiple clients make overload worse
Set a total timeout budget — don't let a single call eat 5 minutes
The AIWave Node SDK handles most of this automatically with built-in exponential backoff, but understanding the underlying logic helps when you need to customize for edge cases.
Open Question
Some teams are moving toward circuit breaker patterns — tripping after N consecutive failures to fail fast rather than queuing retries. Has anyone implemented circuit breakers for LLM API calls in Node? Curious whether it's overkill or genuinely useful for high-throughput scenarios.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
If you've ever built a production app that calls LLM APIs, you know the pain: rate limits, transient 500s, and the dreaded 60-second timeout. A simple
try/catchwith asetTimeoutretry isn't going to cut it.The Problem with Naive Retries
This has zero backoff, no jitter, no max retries, and silently swallows the eventual failure.
What Good Retry Logic Looks Like
Here's a pattern we recommend for Node.js SDK consumers:
Key Principles
Retry-Afterheaders — rate limit responses include thisThe AIWave Node SDK handles most of this automatically with built-in exponential backoff, but understanding the underlying logic helps when you need to customize for edge cases.
Open Question
Some teams are moving toward circuit breaker patterns — tripping after N consecutive failures to fail fast rather than queuing retries. Has anyone implemented circuit breakers for LLM API calls in Node? Curious whether it's overkill or genuinely useful for high-throughput scenarios.
Resources
All reactions