Last week I published a checklist on my site for wrapping LLM API calls in production: a timeout sized to the job, retries only for errors worth retrying, a fallback decided per feature, validation before anything trusts the output, a spend cap, and one shared wrapper so the fix for a bad provider hour lives in one file.
Then I did what I now do with every guide I write: I graded my own repos against it. Two products, five model calls:
- Upwork Scout (upwork-scout.com) scores each new Upwork job against a freelancer's profile with Claude Haiku inside a cron job, and has a second call that turns a pasted Upwork profile into structured fields.
-
VoiceDash, my white-label portal for voice agents, runs post-call analysis: a summary, an evaluation and optional topic tags, all with
gpt-4o-mini.
1. What is the timeout, and is it sized to the job?
Neither app sets one. Every client is created like this:
const client = new Anthropic({ apiKey });
No timeout, no maxRetries. So I went and read the defaults in node_modules. In the Anthropic SDK version Upwork Scout uses (0.110.0):
this.timeout = options.timeout ?? _a.DEFAULT_TIMEOUT /* 10 minutes */;
this.maxRetries = options.maxRetries ?? 2;
The OpenAI SDK in VoiceDash has the same two defaults: ten minutes, two retries.
Sensible for a library that has no idea what you are building. Now look at what wraps those calls:
// app/api/profile/import/route.ts
export const maxDuration = 60;
// app/api/cron/scan/route.ts
export const maxDuration = 300;
The profile import gives the model call a ten minute budget, three attempts, inside a function the platform kills at sixty seconds. On a normal day Haiku answers quickly and none of this matters. On a slow day, the platform ends the function before the SDK ever gives up, and my carefully worded catch block ("Import failed. Try again, or fill the fields manually.") never runs. The user gets a generic platform error instead of the message I wrote for exactly this case.
The cron is the more interesting one, because of the order things happen in. A scan run does roughly this:
- Fetch new jobs and write each one to the
jobscollection (that write is how the next run knows a job is not new). - For each user, filter those new jobs, then score the survivors one at a time with
await scoreJobFit(...). - Send alerts, write stats, release the lock in a
finally.
Step 1 commits before step 2 starts. If the model API has a slow stretch and the sequential scoring loop runs into the 300 second wall halfway through the user list, the function dies, and the users it had not reached yet never get matched against those jobs. The next run sees them as already stored, so they are not new anymore, so nobody ever looks at them again. No error, no alert, just a few missing job alerts for whoever was late in the loop.
In You Can Retry a Write. You Cannot Retry an Email. I treated the 300 second wall as a reason a run can happen twice. I missed that it can also make a run happen less than once.
Grade: fail. The fix is boring: pass timeout per client (a few seconds for the per-job score, longer for the import but well under 60), and give the scoring loop a deadline so it stops starting new calls once the run is close to the wall.
2. Which errors are retried, and is anything else also retrying?
A pleasant surprise: I never wrote a retry, yet I have a decent retry policy, because the SDK's default is decent. Reading shouldRetry in the Anthropic client: it retries 408, 409, 429 and 5xx, respects an x-should-retry header from the server, and its backoff reads retry-after-ms and retry-after before falling back to its own exponential delay. That is close to exactly what my guide recommends.
Then the stacking question: does anything above the call also retry? For Upwork Scout, the pinger in the repo is a GitHub Actions workflow that runs curl once and fails the job on a non-200. No retry there, so attempts do not multiply. VoiceDash's analysis is fired from the Retell webhook with a fetch(...).catch(() => {}), which also does not retry.
Grade: pass, by accident. The honest caveat is that I am relying on defaults I had never read until this audit, and those two retries each get the full ten minute timeout from question 1.
3. What does the user see when retries run out?
Upwork Scout has an answer, and it is deliberate. scoreJobFit returns null on any failure, and the cron treats null as "no verdict": the job is judged by the user's hard filters alone and still goes out, just without a score. I explained the reasoning in Cheap Filters First, LLM Last, and the risks of failing open in My Job Filters Fail Open. One detail I had missed: a failed call still counts against the user's daily scoring cap, because the counter increments before the result is checked.
VoiceDash has no answer. The three analysis calls run one after another inside the route, with no try around any of them, and every result is collected into one updates object that is written to the database at the end. If the summary succeeds and the evaluation call throws, the route returns a 500 and the paid-for summary is thrown away. The webhook that triggered it swallows the error, so the call just shows up in the portal with no summary.
There is no second model anywhere. The model is configurable in Upwork Scout (AI_MODEL env var, defaulting to claude-haiku-4-5) and hardcoded as "gpt-4o-mini" three times in VoiceDash.
Grade: pass for Upwork Scout, fail for VoiceDash. The VoiceDash fix is to save each result as soon as it exists, so one failed call costs one field instead of all three.
4. Is the output validated before anything uses it?
Upwork Scout does this well, mostly because I used structured outputs from the start:
output_config: { format: { type: "json_schema", schema: VERDICT_SCHEMA } },
After that it checks for a refusal stop reason, parses, clamps the score to 0 to 100, rejects anything that is not a finite number, and trims the reason to 200 characters. A response truncated by max_tokens fails JSON.parse and lands in the catch, which ends in the same null path. The one gap: an empty reason string passes.
VoiceDash uses the older json_object mode, which guarantees JSON but not shape. The evaluation score is stored without a range check. The auto-tagging prompt is the funny one: it asks the model to "Return JSON array of matching topics", while json_object mode can only return an object. The code then guesses which key the model chose:
updates.tags = result.topics || result.tags || [];
If the model picks any other key name, the call succeeds, the parse succeeds, and the tags are silently empty.
Grade: pass and fail again. The fix for VoiceDash is a real schema per call, which makes the guess unnecessary.
5. Is spend capped and watched?
Upwork Scout caps model calls per user per day (maxAiScoresPerDay: 150), caches every verdict so a job is never scored twice for the same user, and has a separate global daily budget for scraping. There is no global cap on model calls, though: the ceiling is 150 times the number of users. Nothing logs tokens per call. The only number recorded is aiScored, a count in the last run's stats document, which gets overwritten every run. If the bill moved, I could not tell you which day it started.
VoiceDash uses the workspace's own OpenAI key if one is set, and falls back to mine. That moves spend onto the customer in the common case, but there is no per-workspace limit on how often analysis runs, and no record of tokens either.
Grade: half. Whether provider-side budget limits are set, nothing in either repo tells me.
6. Does every call go through one wrapper?
No. Upwork Scout has one function for scoring, but the profile import creates its own client and makes its own call, so the timeout fix from question 1 has to happen in two places. VoiceDash has three near-identical calls inline in one route.
Grade: fail, and it is the reason the other failures exist. If there had been one callModel(feature, prompt, schema) function, the timeout question would have been answered once, consciously, instead of zero times by default.
What I am taking from this
The most useful lesson was not on the checklist: a timeout only means something relative to the timeout around it. Ten minutes is not wrong. It was chosen by someone who could not know my function lives for sixty seconds, or that my cron commits work before the slow part. The fix list, none of it shipped yet:
- Explicit
timeouton every client, sized below the function'smaxDuration. - A deadline in the cron's scoring loop, and moving the "job is stored" write after matching (or recording which users a job has been matched for).
- Save VoiceDash analysis results one at a time, with a real JSON schema per call.
- Log tokens per call, tagged by feature.
- One wrapper per app.
The full checklist, with the reasoning behind each item, is in the original post: Calling LLM APIs in production: timeouts, retries and fallbacks.
Have you ever checked what your HTTP client's default timeout actually is? I am curious how many of us are running ten minute timeouts inside functions that live for one.
Top comments (0)