The page leanprompt report --html writes for Mintplex-Labs/anything-llm at commit b014470, 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 Mintplex-Labs/anything-llm

leanprompt audit of Mintplex-Labs/anything-llm

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.

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

The biggest, at server/utils/chats/stream.js:105, about 840k tokens per 1,000 calls: history is the last 20 saved exchanges (openAiHistory, default 20).

Together about 1.1M tokens per 1,000 calls An estimate from the code, not a measurement.

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

Plus 3 findings the project already knows about (planned, in progress, reported or declined), listed after the findings. They are not in the totals or the score.

Plus 2 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-PD-05server/utils/chats/stream.js:105840k not cached
LP-PC-01server/utils/agents/aibitat/providers/anthropic.js:270225k not cached
LP-PD-04server/utils/agents/aibitat/plugins/web-scraping.js:12443k prompt
LP-PC-05server/utils/agents/aibitat/index.js:116215k not cached
LP-PC-02 (already planned)server/utils/AiProviders/openAi/index.js:1251.2M not cached
LP-PC-03 (already planned)server/models/systemSettings.js:40809k not cached
LP-PC-01 (already planned)server/utils/AiProviders/anthropic/index.js:145357k not cached

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

4 open, 3 already known to the project, 0 fixed. Largest first, by the audit's estimate of tokens lost per 1,000 calls.

History is the last 20 saved exchanges (openAiHistory, default 20).

Finding 1. server/utils/chats/stream.js:105 medium LP-PD-05

Once a thread passes 20 exchanges, every new turn drops the oldest one, so the start of the history changes on every turn. This is not covered in #6401 and would defeat its stated goal that everything before the latest user turn stays byte-identical.

What to change
Drop old exchanges in steps (for example keep between 10 and 20 and cut back to 10 when 20 is reached) so the window moves only every tenth turn, or add this to the #6401 plan.
Why it matters
A window that slides by one row each turn changes the first history message every turn, which breaks reuse of the entire history.
Estimate
about 0.84M prompt tokens per 1,000 calls (estimate), overlapping the first two findings today
What the estimate assumes

15% of chat turns are in threads past 20 exchanges; a full window is about 8,000 tokens. Today the same tokens are already lost to the first two findings; this is the loss that remains after #6401 lands, so the shares are not additive.

How to check the fix In a thread with 25 exchanges, two consecutive turns after the #6401 change report cached tokens near the history size on all but one turn in ten.

In the agent tool loop on Anthropic, the cache mark (when enabled) sits only on the system prompt and there is none on the messages, so each step of a multi-step tool task recomputes the preloaded history and every earlier tool result.

Finding 2. server/utils/agents/aibitat/providers/anthropic.js:270 high LP-PC-01

With caching off (the default) nothing is cached at all. #6401 covers the chat path but does not name the agent loop.

What to change
When ANTHROPIC_CACHE_CONTROL is set, also mark the last content block of the last message in the agent request (or use top-level automatic caching), so each step reads the previous step's prefix.
Why it matters
An agent task makes several calls in a few seconds with a growing, append-only message list, which is the best case for caching.
Estimate
about 225k prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes

250 agent calls per 1,000; 15% on Anthropic (assumed); 75% are not the first step of a task; about 8,000 tokens of history and tool results per later step.

How to check the fix In a two-tool task, the second and third calls report cache_read_input_tokens near the size of the previous request.

The scrape tool returns the whole page text into the agent conversation whenever it is smaller than the model's entire context window, and summarises only above that.

Finding 3. server/utils/agents/aibitat/plugins/web-scraping.js:124 medium LP-PD-04

A 100k-token page on a 200k model goes in whole and is carried by every later call of the session.

What to change
Summarise (or cut) above a fixed share of the window, for example a quarter, instead of the whole window.
Why it matters
Every later step and turn of the agent session resends the page.
Estimate
about 43k prompt tokens per 1,000 calls (estimate)
What the estimate assumes

About 62 agent tasks per 1,000 calls; 10% scrape a page; 30% of pages exceed 8,000 tokens by about 12,000 tokens; about 2 later calls carry it.

How to check the fix Scrape a long page and compare prompt_tokens on the next agent step before and after. Answer check required: the model sees a summary instead of the page.

When an agent task reaches the tool-call limit, the final call is sent with no tools, which removes the tool definitions from the front of the prompt and makes that call recompute everything.

Finding 4. server/utils/agents/aibitat/index.js:1162 medium LP-PC-05

What to change
Keep the tool list and send tool_choice 'none' (or allowed_tools) on the final call, where the provider supports it.
Why it matters
Tool definitions are part of the cached prefix; removing them changes the prefix from the start.
Estimate
about 15k prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes

2% of agent tasks reach the limit; about 12,000 tokens of prefix on the final call.

How to check the fix On a task that hits the limit, the final call reports cached tokens near the previous request's size.

Already known to the project

The project's own issues, pull requests or docs already cover these, so they are not new and are not in the totals or the score. Read the link before working on one.

Retrieved document chunks and the user's memories are appended to the system message, which comes before the chat history.

Finding 5. server/utils/AiProviders/openAi/index.js:125 high LP-PC-02

The chunks change with every question, so the history after them can never be reused from the provider's prefix cache. The same layout is in 38 of the 40 chat providers. The maintainers already describe this exactly in issue #6401 (open, core-team-only).

What to change
Follow the plan in #6401: keep the system message static and put retrieved context, memories and the current time into the newest user turn, assembled in one place (compressMessages) instead of in each provider.
Why it matters
On OpenAI, Gemini, DeepSeek and local engines with prefix reuse, every turn after the first recomputes the whole chat history at the full input price.
Already planned
Issue #6401 (open, core team): keep the system message static and move retrieved context, memories and the time into the newest user turn. https://github.com/Mintplex-Labs/anything-llm/issues/6401
Estimate
about 1.2M prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes

1,000 app calls = 700 chat turns, 250 agent calls, 50 other; 85% of chat on providers with automatic prefix reuse; 60% of chat in workspaces with documents or memories; 85% of turns are not the first of a thread; average history 4,000 tokens; average prompt 6,900 tokens.

How to check the fix With the reorder applied, the second of two turns in the same thread a minute apart reports cached tokens (prompt_tokens_details.cached_tokens or input_tokens_details.cached_tokens) close to the history size instead of 0. Answer check required: the context moves away from the instructions.

The default system prompt contains 'The current date and time is {datetime}', which expands to the time to the minute near the start of every request.

Finding 6. server/models/systemSettings.js:40 high LP-PC-03

Consecutive turns rarely share a minute, so even in a workspace with no documents the whole history is recomputed each turn. Reported as #6398, moved by the maintainer into #6401; PR #6399 was closed unmerged.

What to change
As planned in #6401: drop the datetime sentence from the default system prompt and send the time in the newest user turn; recognise the old default text stored in existing workspaces.
Why it matters
The first changing token sits about 40 tokens into the prompt, so nothing after it can be reused.
Already planned
Reported in #6398, which the maintainers closed into #6401 (open, core team); #6401 drops the datetime from the default system prompt. https://github.com/Mintplex-Labs/anything-llm/issues/6401
Estimate
about 0.8M prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes

Same call mix as the first finding; counts only the 40% of chat in workspaces without documents or memories, so it does not overlap the first finding; default prompt in use.

How to check the fix Build the system prompt twice across a minute boundary: the bytes must be equal. Then two turns a minute apart show cached tokens near the history size.

With the Anthropic 'Prompt Caching' option on, the only cache mark is on the system block, which holds the per-turn context and the per-minute datetime, and there is no mark on the history.

Finding 7. server/utils/AiProviders/anthropic/index.js:145 high LP-PC-01

Each turn pays the cache-write premium (1.25x, or 2x for 1 hour) on a block that is never read again, and the history is never cached. Already listed as point 4 of #6401.

What to change
After the system block is made static (#6401), keep the mark there and add a second mark on the last history message, as #6401 proposes.
Why it matters
Anthropic caches only up to a mark, so without a mark on the history it is recomputed every turn; a mark on changing content costs more than no mark.
Already planned
Point 4 of issue #6401 (open, core team): a second cache mark on the last history message. https://github.com/Mintplex-Labs/anything-llm/issues/6401
Estimate
about 0.36M prompt tokens per 1,000 calls not served from cache (estimate)
What the estimate assumes

15% of chat traffic on Anthropic (unknown, assumed); 85% non-first turns; history 4,000 tokens. Caching is off by default ('No caching'), a deliberate opt-in from #6035.

How to check the fix Two turns a minute apart: cache_read_input_tokens on the second rises from 0 to about the history size, and cache_creation_input_tokens drops to the new turn only.

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.

The Anthropic chat connector looks up the model's output limit on every turn

Note 1. server/utils/AiProviders/anthropic/index.js:58 not scored

A new AnthropicLLM is built for each chat (helpers/index.js:183-185), and its constructor starts fetchModelMaxTokens (lines 58-61); assertModelMaxTokens (lines 84-88) awaits a second models.retrieve if the first has not returned. That is one or two API round trips per turn, one before the first token. On any error, including a transient one, the lookup returns 4096 (lines 107-110), so that turn runs with max_tokens 4096 instead of the model's limit.

What to change
Cache the output limit per model in a module-level map (helpers/contextWindowCache.js does this for context windows), and do not fall back silently to 4096 on a transient error.

How to check the fix Two chat turns on the same model make one models.retrieve call, not two or four.

A reply cut off at the output limit is saved as complete

Note 2. server/utils/AiProviders/anthropic/index.js:380 LP-GE-12 medium not scored

handleStream resolves on message_stop whatever the stop_reason (lines 378-393), and the chat path does not call watchTokenLimit as the agent path does, so a reply that stopped at max_tokens is saved and shown as a complete answer. After a provider error mid-stream (lines 330-351) the partial text is also saved as a normal answer (chats/stream.js:357-375) and sent as history on later turns; for a user abort that is deliberate, for a provider error probably not.

What to change
Surface stop_reason max_tokens to the user, as the agent path does, and mark a reply that ended in a provider error so it is not reused as a complete answer.

How to check the fix With a small output limit, the saved chat shows that the reply was cut off.

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-PD-05 at server/utils/chats/stream.js:105: History is the last 20 saved exchanges (openAiHistory, default 20). Once a thread passes 20 exchanges, every new turn drops the oldest one, so the start of the history changes on every turn. This is not covered in #6401 and would defeat its stated goal that everything before the latest user turn stays byte-identical.
2. LP-PC-01 at server/utils/agents/aibitat/providers/anthropic.js:270: In the agent tool loop on Anthropic, the cache mark (when enabled) sits only on the system prompt and there is none on the messages, so each step of a multi-step tool task recomputes the preloaded history and every earlier tool result. With caching off (the default) nothing is cached at all. #6401 covers the chat path but does not name the agent loop.
3. LP-PD-04 at server/utils/agents/aibitat/plugins/web-scraping.js:124: The scrape tool returns the whole page text into the agent conversation whenever it is smaller than the model's entire context window, and summarises only above that. A 100k-token page on a 200k model goes in whole and is carried by every later call of the session.
4. LP-PC-05 at server/utils/agents/aibitat/index.js:1162: When an agent task reaches the tool-call limit, the final call is sent with no tools, which removes the tool definitions from the front of the prompt and makes that call recompute everything.

Already known to the project (read the link first; do not duplicate work the project has planned or started):
- LP-PC-02 (server/utils/AiProviders/openAi/index.js:125): Retrieved document chunks and the user's memories are appended to the system message, which comes before the chat history. The chunks change with every question, so the history after them can never be reused from the provider's prefix cache. The same layout is in 38 of the 40 chat providers. The maintainers already describe this exactly in issue #6401 (open, core-team-only). Already planned: Issue #6401 (open, core team): keep the system message static and move retrieved context, memories and the time into the newest user turn. https://github.com/Mintplex-Labs/anything-llm/issues/6401
- LP-PC-03 (server/models/systemSettings.js:40): The default system prompt contains 'The current date and time is {datetime}', which expands to the time to the minute near the start of every request. Consecutive turns rarely share a minute, so even in a workspace with no documents the whole history is recomputed each turn. Reported as #6398, moved by the maintainer into #6401; PR #6399 was closed unmerged. Already planned: Reported in #6398, which the maintainers closed into #6401 (open, core team); #6401 drops the datetime from the default system prompt. https://github.com/Mintplex-Labs/anything-llm/issues/6401
- LP-PC-01 (server/utils/AiProviders/anthropic/index.js:145): With the Anthropic 'Prompt Caching' option on, the only cache mark is on the system block, which holds the per-turn context and the per-minute datetime, and there is no mark on the history. Each turn pays the cache-write premium (1.25x, or 2x for 1 hour) on a block that is never read again, and the history is never cached. Already listed as point 4 of #6401. Already planned: Point 4 of issue #6401 (open, core team): a second cache mark on the last history message. https://github.com/Mintplex-Labs/anything-llm/issues/6401

Other problems found (check each against the code first; not scored):
- The Anthropic chat connector looks up the model's output limit on every turn (server/utils/AiProviders/anthropic/index.js:58): A new AnthropicLLM is built for each chat (helpers/index.js:183-185), and its constructor starts fetchModelMaxTokens (lines 58-61); assertModelMaxTokens (lines 84-88) awaits a second models.retrieve if the first has not returned. That is one or two API round trips per turn, one before the first token. On any error, including a transient one, the lookup returns 4096 (lines 107-110), so that turn runs with max_tokens 4096 instead of the model's limit. Change: Cache the output limit per model in a module-level map (helpers/contextWindowCache.js does this for context windows), and do not fall back silently to 4096 on a transient error.
- A reply cut off at the output limit is saved as complete (server/utils/AiProviders/anthropic/index.js:380) [LP-GE-12]: handleStream resolves on message_stop whatever the stop_reason (lines 378-393), and the chat path does not call watchTokenLimit as the agent path does, so a reply that stopped at max_tokens is saved and shown as a complete answer. After a provider error mid-stream (lines 330-351) the partial text is also saved as a normal answer (chats/stream.js:357-375) and sent as history on later turns; for a user abort that is deliberate, for a provider error probably not. Change: Surface stop_reason max_tokens to the user, as the agent path does, and mark a reply that ended in a provider error so it is not reused as a complete answer.

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).

90static
E, prefill reuse
0.84
S, prefix stability
1.00
G, generation waste
0.00
Default shares
0 of 4

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

It leaves out 3 findings the project already knows about (planned, in progress, declined or reported); with them it would be 74.

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.