Retries meant to try new temperatures resend the same request each time
A web scraping and search API for AI agents; its prompt-injection guard already records the usage of calls that error out.
≈ 2,200 tokens per 1,000 calls, of extra calls when schema or crawler-options generation errors estimate
Audited with leanprompt 0.1.0-dev.15
Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.
- Repository
- firecrawl/firecrawl 213k GitHub stars
- Commit audited
73aea36- leanprompt version
- 0.1.0-dev.15
- Audit date
- Status
- The maintainers have been told about this audit; no response yet.
- Maintainers
- the issue
- How it ran
- Unattended audit: nobody was asked during the run, so priority, volume and prices were left open; the questions for the owner are listed at the end.
leanprompt read the code at commit 73aea36 and found 1 place where its LLM calls could use fewer tokens, plus 2 other problems, not scored. Static score: 99 of 100 (an estimate from the findings). The code may have changed since.
Findings
-
LP-GE-05Retry only retryable errors; never retry a truncation unchangedapps/api/src/scraper/scrapeURL/transformers/llmExtract.ts:1740· severity medium · saves prefill and generation · how often is assumedWhat happens. Schema generation and crawler-options generation try up to three times, meant to be at temperatures 0, 0.1 and 0.3. The temperature is never sent (the line is commented out in one function and absent in the other, and generateCompletions does not read options.temperature), so each retry is the same request. Every error, including permanent ones, is retried.
The change. Either pass the temperature through to the request, or stop the loop after a failure that cannot change (a 4xx or an invalid key), and keep retries only for the unsupported-schema case.
Why it helps. A retry that sends the same request at the default temperature costs a full call and mostly repeats the failure; a permanent error costs three calls instead of one.
Estimate up to 2 extra small calls per failing schema or crawler-options generation; size is small
Assumptions. these two functions are rare paths and the prompts are about 400 to 900 tokens, so the share of the whole app is tiny
How often. how often schema or crawler-options generation fails or yields an unsupported schema, from their logs
Other problems the audit found
Problems read in the code that cost no tokens of their own, such as a cost meter or an error path. Not scored.
-
The cost meter prices cached input tokens at the full input rate
apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts:519·LP-GE-11Meter every billed token, cached and unfinished ones too · severity mediumWhat happens. calculateCost takes only input and output token counts and prices every input token at the full input price. The price book in model-prices.ts carries cache_read_input_token_cost for OpenAI models, but it is never used, and the cached share OpenAI reports is not read at any call site.
The change. Read the cached token count from the usage the SDK returns, pass it to calculateCost and price it at the cached-input rate; record it separately in costTracking.addCall.
Why it matters. The cost meter and the cost limit it feeds overstate spend on calls that hit the cache, which are the repeated system prompts of the guard, summary and clean-content paths.
To check. For one call with a cached prefix, the recorded cost matches the provider's bill for it.
-
Usage of a cut-off or fenced-JSON extraction call is not recorded in the cost meter
apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts:1125·LP-GE-11Meter every billed token, cached and unfinished ones too · severity lowWhat happens. When generateObject fails with finishReason 'length', the code throws without calling costTracking.addCall, so the tokens of that billed call are missing from the meter. The fenced-JSON branch just below builds a usage object from error.usage and also never records it. The prompt injection guard handles the same case by recording error.usage in its catch block.
The change. Call costTracking.addCall with error.usage before throwing, as promptInjectionGuard.ts does.
To check. Force a length stop and check that costTracking has one call with the provider's token counts.
The maintainers’ response
No response from the maintainers yet.
How this was made
The llm-call-audit skill read the code and wrote findings.json; nothing was run against the project’s providers. The full audit page is what leanprompt report --html writes from the same findings.
Corrections and takedown: email info@podwarden.com or open an issue.