The page leanprompt report --html writes for assafelovic/gpt-researcher at commit 9d39a2f, audited 2026-11-26. Every figure on this page is an estimate from reading the code, not a measurement of the app in use. Corrections and takedown: email info@podwarden.com or open an issue. Back to the audit of assafelovic/gpt-researcher

leanprompt audit of assafelovic/gpt-researcher

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.

7 places where this app pays for tokens it doesn't need

The biggest, at gpt_researcher/utils/llm.py:151, about 660k tokens per 1,000 calls: when a model returns an empty answer, the shared completion helper sends the exact same request again, up to 10 times.

Together about 770k tokens per 1,000 calls For the 6 with a number, an estimate from the code, not a measurement.

Tokens per 1,000 calls, by finding, and each one's share of the total

Plus 5 other problems the audit found, listed after the findings. Not scored.

What this costs you

Every figure here is an estimate from the code, not a measurement. Findings can overlap (one failed call can show up in two), so the sum may count some tokens twice. Money is not part of the score. The table lists this app's findings first, largest first, then its open questions, then the questions for the server's administrator, then the findings the project already knows about, which are not in the totals.

FindingWhereTokens per 1,000 calls
LP-GE-05gpt_researcher/utils/llm.py:151360k prompt, 300k output
LP-PC-02backend/chat/chat.py:24693k not cached
LP-GE-03gpt_researcher/skills/deep_research.py:34913k output
LP-GE-10gpt_researcher/skills/deep_research.py:3823.3k output
LP-PD-06gpt_researcher/skills/deep_research.py:341900 prompt
LP-GE-05gpt_researcher/utils/llm.py:1270

To see this in money, add to leanprompt.yaml:

  • volume: {calls_per_month: N}: how many calls the app makes a month (with targets:, on each entry)
  • prices: per model: input, cached_input and output per 1M tokens (US dollars, or set currency), with source and checked date (or, self-hosted, engine: {prefill_tokens_per_second: N})

leanprompt never guesses a volume or a price. Your coding agent can look up the provider's current price page and add it with the date; how.

What's wrong and what to change

7 open, 0 fixed. Largest first, by the audit's estimate of tokens lost per 1,000 calls.

When a model returns an empty answer, the shared completion helper sends the exact same request again, up to 10 times.

Finding 1. gpt_researcher/utils/llm.py:151 high LP-GE-05 how often is assumed

On reasoning models an empty answer almost always means the output limit was used up by reasoning, so the same request fails the same way and every attempt is billed.

What to change
Read the finish reason the provider already returns (finish_reason 'length' on OpenAI-compatible APIs, stop_reason 'max_tokens' on Anthropic, MAX_TOKENS on Gemini). If the empty answer was cut off by the limit, retry at most once with a larger limit (for example double, capped), or raise a clear error naming the token-limit setting. Keep the current retry for empty answers that were not cut off.
Why it matters
Each repeated attempt bills up to the full output limit (4,000 or 8,000 tokens in deep research) and returns nothing usable.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: How often a call still comes back empty because the output limit was reached after #2260: count 'Empty response' warnings, with the provider's finish reason, in a deep-research run log.
Estimate
about 300k output and 360k prompt tokens per 1,000 calls (estimate)
What the estimate assumes

Call mix: 80% of runs are standard reports (3 calls), 15% deep research (about 33 calls), 5% detailed; so about 60% of calls are deep research. After PR #2260, 2% of result-analysis calls (8,000 limit) and 10% of plan calls and 2% of query calls (4,000 limit) still come back empty from truncation, and when they do the 9 retries also come back empty. Issue #2251 measured 202 empty responses in 13 runs before the fix. Each retry also resends the prompt, about 6k tokens on average, so the prompt side is about 0.06 of prompt tokens; the share recorded is the larger output side.

How to check the fix Mock a provider whose response metadata has finish_reason 'length' and empty content: before the fix get_chat_response is awaited 10 times, after it at most 2 times and the second call has a larger max_tokens.

The chat-about-the-report system prompt contains the current time down to the microsecond and the report passages retrieved for this turn, and it comes before the conversation history.

Finding 2. backend/chat/chat.py:246 high LP-PC-02

So the start of every request is new, and none of the earlier turns can be served from the provider's prompt cache.

What to change
Keep the system prompt fixed for the conversation (date only, no time, set once), keep the history after it unchanged, and put the passages retrieved for this turn into the newest user message instead of the system prompt. Retrieval per turn (the comment at line 223) stays as it is.
Why it matters
On OpenAI, prompt caching is automatic for a repeated prefix of 1,024 tokens or more; with a new prefix on every turn the history is billed at full input price every time.
Estimate
about 93k prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes

Chat is 10% of the app's calls; 4 turns per chat; about 650 tokens per turn of history; fixed system part about 300 tokens; only prefixes of 1,024 tokens or more count, in 128-token steps, so turns 1 and 2 gain nothing.

How to check the fix Two chat turns a minute apart on the same report: usage prompt_tokens_details.cached_tokens on the third turn rises from 0 to about the size of system prompt plus earlier turns.

The deep-research plan call runs the strategic model at high reasoning effort with the helper's default 4,000-token limit, which also has to cover the reasoning.

Finding 3. gpt_researcher/skills/deep_research.py:349 medium LP-GE-03 how often is assumed

This is the same shape PR #2260 fixed for the result-analysis call, but the plan call and the query-generation call were left at 4,000.

What to change
Pass max_tokens=cfg.strategic_token_limit to generate_research_plan and generate_search_queries, as #2260 did for process_research_results.
Why it matters
A cut-off plan returns empty after spending the whole 4,000-token budget, and then falls into the unchanged retry above.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: How often gpt-5.4 at reasoning_effort high returns empty content for the research-plan prompt with a 4,000-token limit (count 'LLM returned empty response' warnings in a deep run log).
Estimate
about 13k output tokens per 1,000 calls (estimate), first attempts only; the retries are counted in the empty-answer finding
What the estimate assumes

About 18 plan calls and 74 query calls per 1,000 app calls; 10% of plan calls and 2% of query calls are cut off at 4,000 tokens.

How to check the fix In a deep run with LOG_LEVEL=DEBUG, the count of empty-response warnings from these two calls drops to zero; existing test tests/test_deep_research_reasoning_budget.py extended to the two calls.

The deep-research calls ask for JSON in the prompt text but do not use the provider's structured output.

Finding 4. gpt_researcher/skills/deep_research.py:382 medium LP-GE-10

The parsers are forgiving and fall back to line parsing, so a malformed answer is rarely re-asked, but when nothing parses the learnings from that query are dropped.

What to change
Where the provider supports it, pass a JSON schema (with_structured_output or response_format json_schema) for the learnings, queries and plan calls, and keep the current parser as the fallback for providers without it.
Why it matters
An unparseable answer is output that was paid for and thrown away.
Estimate
about 3k output tokens per 1,000 calls (estimate)
What the estimate assumes

1% of the 166 result-analysis calls per 1,000 calls fail to parse at about 2,000 output tokens each.

How to check the fix Count parse fallbacks (no learnings returned) over a deep run before and after.

The research-plan prompt pastes the raw search results as a Python list repr, with every key and quote repeated for each result.

Finding 5. gpt_researcher/skills/deep_research.py:341 low LP-PD-06

What to change
Format the results as short title, URL and snippet lines, as other prompts in the project already do.
Why it matters
Repeated keys and quoting add tokens that carry no information.
Estimate
about 1k prompt tokens per 1,000 calls (estimate)
What the estimate assumes

One plan call per deep run (about 18 per 1,000 calls); about 3,000 tokens of results, 15% of it key and quote overhead.

How to check the fix prompt_tokens of the plan call drops by about 15% for the same query.

Every exception from the provider is retried up to 10 times with backoff, including errors that cannot succeed on retry: a wrong API key, a rejected parameter, a prompt over the context window, exhausted credit.

Finding 6. gpt_researcher/utils/llm.py:127 high LP-GE-05

Sub-query generation chains three such calls, so a bad key takes 30 attempts and about 3 minutes before the run reports the error.

What to change
Do not retry authentication, permission, bad-request and context-length errors (HTTP 400, 401, 403, 404, 413, and 429 for exhausted quota); raise them on the first attempt. Keep retries for connection errors, 408, 409, 429 rate limits and 5xx.
Why it matters
Rejected requests are usually not billed, so the cost is mostly time and a slow, noisy failure, not tokens.
Estimate
near zero tokens; up to about 55 s of backoff per call and about 3 minutes per run on a persistent error (estimate)
What the estimate assumes

Rejected 4xx requests are not billed by the provider. The SDK under LangChain also retries 408, 409, 429 and 5xx twice on its own.

How to check the fix A provider that raises an authentication error is awaited once, not 10 times.

Picking the research persona is a short label call (a name and a one-paragraph role), but it runs on the smart model, the one used to write the report.

Finding 7. gpt_researcher/actions/agent_creator.py:46 medium LP-GE-08

What to change
Run choose_agent on the fast model (FAST_LLM), after an answer check on a sample of queries.
Why it matters
The smart model (default gpt-6-sol) costs several times the fast model (default gpt-5.4-mini) per token for a task the small model can do.
Estimate
price only, no tokens saved
What the estimate assumes

One persona call per research run, and one per nested researcher in deep research.

How to check the fix On 20 sample queries, the fast model picks a persona that a reviewer accepts as often as the smart model does.

Other problems the audit found

Problems the audit checked in the code that cost no tokens of their own, such as a spend meter that ignores cache tokens or a cut-off answer accepted as complete. They are not scored. Check each one before you change anything.

Cached OpenAI input is priced at half the input rate for every model

Note 1. gpt_researcher/utils/costs.py:24 LP-GE-11 low not scored

OPENAI_CACHED_INPUT_DISCOUNT = 0.5 applies to every OpenAI model (used at lines 306-313). OpenAI's pricing page (read 2026-11-26) lists cached input at a tenth of the input price for the three default models, so their cached tokens are reported at five times their price. The tests use gpt-4o, where 0.5 is right. The comment at lines 18-23 says to revisit this when a model has a different ratio.

What to change
Add a cached-input price to each OPENAI_MODEL_PRICING row and use it, keeping 0.5 as the fallback for unknown models.

How to check the fix A parametrised test in tests/test_costs.py for the default models and gpt-4o.

A report cut off at the output limit is accepted as complete

Note 2. gpt_researcher/actions/report_generation.py:292 LP-GE-12 medium not scored

generate_report streams the report with max_tokens set to SMART_TOKEN_LIMIT, which on reasoning models also covers the reasoning. No code reads finish_reason or stop_reason, so a report that hits the limit stops mid-sentence and is saved and shown as complete. Only the empty case is detected (utils/llm.py:151).

What to change
Warn when the response metadata says the limit was reached, naming SMART_TOKEN_LIMIT.

How to check the fix With a small SMART_TOKEN_LIMIT, the run logs a warning and the report is marked as cut off.

A report stream that fails part way is shown twice

Note 3. gpt_researcher/actions/report_generation.py:307 not scored

When the streamed report fails after some chunks were sent, generate_report sends the whole report again through the same websocket (lines 307-322). The Next.js frontend appends report chunks (frontend/nextjs/hooks/useWebSocket.ts:120-121), so the user sees the partial report followed by the full one. Read in the code, not reproduced.

What to change
Send a message that clears the partial report before the second attempt, or replace the answer instead of appending on a retry.

How to check the fix A provider that fails after a few chunks: the page shows one report.

Persona calls in deep research produce a role nobody reads

Note 4. gpt_researcher/agent.py:388 not scored

Each nested researcher in deep research (about 9 per default run) calls choose_agent on the smart model (lines 388-400). The role is used by the writer and the curator, which nested researchers do not run with the default CURATE_SOURCES=False.

What to change
Pass a fixed agent and role to the nested researchers, so they skip the persona call.

How to check the fix A default deep-research run makes about 9 fewer smart-model calls, with the same report.

Chat and multi-agent calls are not metered

Note 5. backend/chat/chat.py:155 LP-GE-11 medium not scored

The chat path calls create_chat_completion_with_tools without cost_callback, so chat costs are never counted, and the multi-agent mode has cost_callback commented out (multi_agents/agents/utils/llms.py:30).

What to change
Pass cost_callback on both paths.

How to check the fix After one chat turn, get_costs() is above zero.

Fix it with your coding agent

Paste this into Claude Code, Codex, Cursor or any coding assistant. It will check each finding against your code and propose fixes one at a time, asking before it changes anything.

Please check and fix the LLM-call findings from a leanprompt audit of this repository.

1. If the leanprompt skills are not installed for you here, install them: npx leanprompt@0.1.0-dev.15 install
2. Read .leanprompt/findings.json and leanprompt-report.md. If they are missing, use the list below.
3. Check each finding against the code before you change anything. The audit can be wrong: if a finding does not hold, tell me why and leave that code alone.
4. Fix one finding at a time. Show me the change as a small diff and apply it only after I say yes.
5. Prove each fix with the measure-loop skill: a before and after on the same scenario. Ask me before running anything that sends real, billed requests.
6. When a fix is proved, set "fixed": true on its finding in .leanprompt/findings.json and run npx leanprompt@0.1.0-dev.15 score.

Findings, largest first:
1. LP-GE-05 at gpt_researcher/utils/llm.py:151: When a model returns an empty answer, the shared completion helper sends the exact same request again, up to 10 times. On reasoning models an empty answer almost always means the output limit was used up by reasoning, so the same request fails the same way and every attempt is billed.
2. LP-PC-02 at backend/chat/chat.py:246: The chat-about-the-report system prompt contains the current time down to the microsecond and the report passages retrieved for this turn, and it comes before the conversation history. So the start of every request is new, and none of the earlier turns can be served from the provider's prompt cache.
3. LP-GE-03 at gpt_researcher/skills/deep_research.py:349: The deep-research plan call runs the strategic model at high reasoning effort with the helper's default 4,000-token limit, which also has to cover the reasoning. This is the same shape PR #2260 fixed for the result-analysis call, but the plan call and the query-generation call were left at 4,000.
4. LP-GE-10 at gpt_researcher/skills/deep_research.py:382: The deep-research calls ask for JSON in the prompt text but do not use the provider's structured output. The parsers are forgiving and fall back to line parsing, so a malformed answer is rarely re-asked, but when nothing parses the learnings from that query are dropped.
5. LP-PD-06 at gpt_researcher/skills/deep_research.py:341: The research-plan prompt pastes the raw search results as a Python list repr, with every key and quote repeated for each result.
6. LP-GE-05 at gpt_researcher/utils/llm.py:127: Every exception from the provider is retried up to 10 times with backoff, including errors that cannot succeed on retry: a wrong API key, a rejected parameter, a prompt over the context window, exhausted credit. Sub-query generation chains three such calls, so a bad key takes 30 attempts and about 3 minutes before the run reports the error.
7. LP-GE-08 at gpt_researcher/actions/agent_creator.py:46: Picking the research persona is a short label call (a name and a one-paragraph role), but it runs on the smart model, the one used to write the report.

Other problems found (check each against the code first; not scored):
- Cached OpenAI input is priced at half the input rate for every model (gpt_researcher/utils/costs.py:24) [LP-GE-11]: OPENAI_CACHED_INPUT_DISCOUNT = 0.5 applies to every OpenAI model (used at lines 306-313). OpenAI's pricing page (read 2026-11-26) lists cached input at a tenth of the input price for the three default models, so their cached tokens are reported at five times their price. The tests use gpt-4o, where 0.5 is right. The comment at lines 18-23 says to revisit this when a model has a different ratio. Change: Add a cached-input price to each OPENAI_MODEL_PRICING row and use it, keeping 0.5 as the fallback for unknown models.
- A report cut off at the output limit is accepted as complete (gpt_researcher/actions/report_generation.py:292) [LP-GE-12]: generate_report streams the report with max_tokens set to SMART_TOKEN_LIMIT, which on reasoning models also covers the reasoning. No code reads finish_reason or stop_reason, so a report that hits the limit stops mid-sentence and is saved and shown as complete. Only the empty case is detected (utils/llm.py:151). Change: Warn when the response metadata says the limit was reached, naming SMART_TOKEN_LIMIT.
- A report stream that fails part way is shown twice (gpt_researcher/actions/report_generation.py:307): When the streamed report fails after some chunks were sent, generate_report sends the whole report again through the same websocket (lines 307-322). The Next.js frontend appends report chunks (frontend/nextjs/hooks/useWebSocket.ts:120-121), so the user sees the partial report followed by the full one. Read in the code, not reproduced. Change: Send a message that clears the partial report before the second attempt, or replace the answer instead of appending on a retry.
- Persona calls in deep research produce a role nobody reads (gpt_researcher/agent.py:388): Each nested researcher in deep research (about 9 per default run) calls choose_agent on the smart model (lines 388-400). The role is used by the writer and the curator, which nested researchers do not run with the default CURATE_SOURCES=False. Change: Pass a fixed agent and role to the nested researchers, so they skip the persona call.
- Chat and multi-agent calls are not metered (backend/chat/chat.py:155) [LP-GE-11]: The chat path calls create_chat_completion_with_tools without cost_callback, so chat costs are never counted, and the multi-agent mode has cost_callback commented out (multi_agents/agents/utils/llms.py:30). Change: Pass cost_callback on both paths.

Score

One number from 0 to 100 for how well this app avoids paying for the same tokens twice; higher is better. It is computed from the findings above (static) or from your usage log (measured).

78static
E, prefill reuse
0.79
S, prefix stability
1.00
G, generation waste
0.21
Default shares
0 of 7

Findings scored with severity defaults, not estimates. The fewer, the more the static score says about this app.

A static score is an estimate from the audit's findings, not a measurement.

Scored 2026-11-26 (the date on the machine that ran it).

Questions for the owner

These were not answered during the audit. Until they are, the page shows tokens only and ranks the advice without a priority.

  • Priority: which matters most for this app, cost, speed or quality (or weights)? Not set, so the advice uses equal weights. Answer with priority: in leanprompt.yaml.
  • Volume: how many calls does the app make a month? Answer with volume: {calls_per_month: N, source: "..."} in leanprompt.yaml.
  • Prices: what does each model cost (input, cached input, output per 1M tokens, with the source and the date it was read, and the currency if not US dollars)? Answer with prices: in leanprompt.yaml.