The page leanprompt report --html writes for ChatGPTNextWeb/NextChat at commit 1d3dc33, audited 2026-11-27. 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 ChatGPTNextWeb/NextChat

leanprompt audit of ChatGPTNextWeb/NextChat

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.

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

The biggest, at app/store/chat.ts:179, about 360k tokens per 1,000 calls: for gpt-* models the first message of every request is a system prompt that starts with the current time, written with seconds (new Date().toString()).

Together about 360k tokens per 1,000 calls An estimate from the code, not a measurement. Findings that overlap are counted once.

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

Plus 2 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 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 the audit marked as overlapping are counted once in the totals, the largest of each group; other findings can still overlap. 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-PC-03app/store/chat.ts:179360k not cached
LP-PC-08app/store/chat.ts:63675k not cached
LP-PC-01 (already reported)app/client/platforms/anthropic.ts:182360k not cached; the fix writes 600k to the cache at the write price

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

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

For gpt-* models the first message of every request is a system prompt that starts with the current time, written with seconds (new Date().toString()).

Finding 1. app/store/chat.ts:179 high LP-PC-03 size is assumed

It differs on every call, so OpenAI's automatic prefix cache cannot reuse anything after it: the memory summary, the mask's context messages and the history.

What to change
Drop the time line from the system message, or move it into the newest user message, so the system message is the same on every call.
Why it matters
Prompt caching matches from the first byte. A timestamp on line 4 of message 1 makes every later token a cache miss, even when the rest of the prompt is the same as the last turn.
How big it is
The code shows the problem and how often it happens; how many tokens it costs each time is assumed. To measure it: On a gpt-* chat whose prompt is over 1,024 tokens, send two turns a minute apart and read cached_tokens on the second; it should be about 0 today and rise after the time line moves.
Who reaches this
gpt-* and chatgpt-* models (the default model gpt-4o-mini), default setting on
Estimate
about 360,000 prompt tokens per 1,000 calls not served from cache
What the estimate assumes

average prompt 2,000 tokens; 30% of calls on gpt-* have a reusable prefix of about 1,200 tokens (the 1,024 minimum applies; short chats lose nothing); the history window and summaries move on some turns, so not every turn can reuse its prefix. The share is of all prompt tokens of gpt-* sessions.

How to check the fix Two requests a minute apart in one chat over 1,200 tokens: cached_tokens on the second request rises from 0 to about the size of the earlier turn, and the system message bytes are equal across the two requests.

The request is built as system prompt, then the rewritten memory summary, then the mask's fixed context messages, then history.

Finding 2. app/store/chat.ts:636 medium LP-PC-08 size is assumed

The summary changes each time it is refreshed, so the mask context that sits behind it is recomputed on every refresh although it never changes.

What to change
Build the list as system prompt, mask context, memory summary, history. The summary then starts after the stable part.
Why it matters
A cache only reuses tokens up to the first change. A part that changes (the summary) in front of a part that never changes (the mask context) throws the stable part away each time.
How big it is
The code shows the problem and how often it happens; how many tokens it costs each time is assumed. To measure it: How many sessions use a mask with context messages over about 500 tokens (masks the app ships, or user masks).
Who reaches this
sessions with a mask that has long context messages and a summary
Overlaps
Finding 1 loses some of the same tokens; the totals count the larger once.
Estimate
about 75,000 prompt tokens per 1,000 calls (estimate)
What the estimate assumes

10% of calls use a mask with about 1,500 tokens of context; half of those follow a summary refresh. Only pays off once the time line is also out of the first message on gpt-* models, which is why the two overlap.

How to check the fix In a chat with a long mask context, force a summary refresh and send the next turn: cached_tokens covers the mask context after the reorder and does not before.

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.

Requests to Anthropic carry no cache_control mark anywhere, and the system and memory messages are sent as ordinary user messages, so nothing is cached on Claude models.

Finding 3. app/client/platforms/anthropic.ts:182 high LP-PC-01 size is assumed

What to change
Send the fixed head (system, mask context) as a system block with one mark, and mark the last stable message. Do this together with the time and order fixes, since a changing head means the marks are written and never read.
Why it matters
Anthropic caches only at marks. Without them every turn pays full input price for the whole prompt.
How big it is
The code shows the problem and how often it happens; how many tokens it costs each time is assumed. To measure it: cache_read_input_tokens and cache_creation_input_tokens on two consecutive turns of a chat over the model's minimum cacheable length.
Who reaches this
sessions that use Anthropic models
Already reported
open feature request (Aug 2024) for Claude prompt caching; a maintainer replied that they would look into it. It proposes custom headers, not cache_control marks. https://github.com/ChatGPTNextWeb/NextChat/issues/5279
Estimate
about 360,000 prompt tokens per 1,000 calls could be read from cache; about 600,000 newly written (estimate)
What the estimate assumes

average prompt 2,000 tokens; 30% of calls continue a prefix of about 1,200 tokens that is above the model's minimum (1,024 or 4,096 by model); the history window slides on some turns, so reads per write are near the break-even of about 0.3. Net gain is small and uncertain on the default window settings.

How to check the fix Second request in a chat reports cache_read_input_tokens close to the marked prefix; the first reports cache_creation_input_tokens above 0.

The title and the memory summary use the chat's own model unless it is gpt-*, gemini* or deepseek-*.

Finding 4. app/store/chat.ts:151 medium LP-GE-08

A user on Claude, Qwen, Grok or any other model pays that model's price for a four-word title and for a 200-word summary that can run after every long turn.

What to change
Default the title and summary model to a small model of the same provider, and keep compressModel as the override.
Why it matters
A title and a short recap do not need the largest model; it costs more per token and is slower.
Already reported
open request to change the model used for auto titles; the compressModel setting (PR 5426, merged) lets a user pick one, but the default is still the chat model. https://github.com/ChatGPTNextWeb/NextChat/issues/5368
Estimate
no token loss; a price and latency difference (not scored)
What the estimate assumes

summary runs when more than 1,000 estimated tokens arrived since the last one (chat.ts:761), so with long answers on most turns.

How to check the fix Provider usage shows title and summary calls on the small model, and titles pass a fixed check on sample chats.

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.

A cut-off answer is shown as complete (OpenAI reasoning models)

Note 1. app/client/platforms/openai.ts:246 LP-GE-12 high not scored

For gpt-5 and o-series models the limit sent is max_completion_tokens = Max Tokens, 4000 by default (store/config.ts:71). Reasoning tokens count against it. The stream parser reads delta content only (openai.ts:333-366) and never reads finish_reason, so a reply that stopped on the limit, or an empty one after long reasoning, is stored and shown as a finished answer.

What to change
Read finish_reason from the last stream chunk; on length, mark the message as cut off in the UI and offer to continue, and raise or drop the default cap for reasoning models.
Why it matters
The user pays for the reasoning and gets half an answer with no sign it stopped early.

How to check the fix Set a low cap on a gpt-5 chat and ask a long question: the message shows a cut-off marker and the finish reason is length.

Claude replies cut at max_tokens are not flagged

Note 2. app/client/platforms/anthropic.ts:244 LP-GE-12 medium not scored

max_tokens defaults to 4000 (anthropic.ts:187). The stream handler checks stop_reason only for refusal; stop_reason max_tokens is ignored, so a long answer ends mid-sentence without notice.

What to change
On message_delta with stop_reason max_tokens, mark the reply as cut off and offer to continue.

How to check the fix Ask for a long answer with Max Tokens at 100: the reply shows a cut-off marker.

A failed summary leaves a half-written memory

Note 4. app/store/chat.ts:783 LP-GE-12 low not scored

While the summary streams, onUpdate writes the partial text straight into session.memoryPrompt. onError only logs (chat.ts:794), and lastSummarizeIndex is not advanced, so an aborted or failed summary replaces the old memory with a fragment and the same summary is attempted again on the next turn.

What to change
Keep the stream text in a local variable and write memoryPrompt and lastSummarizeIndex together in onFinish.

How to check the fix Abort a summary call midway: memoryPrompt keeps its previous value.

A chat's summary is built from the open chat's memory

Note 5. app/store/chat.ts:531 LP-GE-12 medium not scored

getMemoryPrompt reads currentSession(), but summarizeSession(targetSession) calls it at chat.ts:745. If the user opens another chat while a reply streams, the summary of the first chat is built from the second chat's memory.

What to change
Pass the target session into getMemoryPrompt.
In progress
open PR fixing issue 6935 (Nov 2026): summarize a chat with its own memory prompt, not the open chat's. https://github.com/ChatGPTNextWeb/NextChat/pull/6936

How to check the fix Start a reply, open another chat that has a memory, and check the first chat's summary does not mention it.

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-PC-03 at app/store/chat.ts:179: For gpt-* models the first message of every request is a system prompt that starts with the current time, written with seconds (new Date().toString()). It differs on every call, so OpenAI's automatic prefix cache cannot reuse anything after it: the memory summary, the mask's context messages and the history.
2. LP-PC-08 at app/store/chat.ts:636: The request is built as system prompt, then the rewritten memory summary, then the mask's fixed context messages, then history. The summary changes each time it is refreshed, so the mask context that sits behind it is recomputed on every refresh although it never changes.

Already known to the project (read the link first; do not duplicate work the project has planned or started):
- LP-PC-01 (app/client/platforms/anthropic.ts:182): Requests to Anthropic carry no cache_control mark anywhere, and the system and memory messages are sent as ordinary user messages, so nothing is cached on Claude models. Already reported: open feature request (Aug 2024) for Claude prompt caching; a maintainer replied that they would look into it. It proposes custom headers, not cache_control marks. https://github.com/ChatGPTNextWeb/NextChat/issues/5279
- LP-GE-08 (app/store/chat.ts:151): The title and the memory summary use the chat's own model unless it is gpt-*, gemini* or deepseek-*. A user on Claude, Qwen, Grok or any other model pays that model's price for a four-word title and for a 200-word summary that can run after every long turn. Already reported: open request to change the model used for auto titles; the compressModel setting (PR 5426, merged) lets a user pick one, but the default is still the chat model. https://github.com/ChatGPTNextWeb/NextChat/issues/5368

Other problems found (check each against the code first; not scored):
- A cut-off answer is shown as complete (OpenAI reasoning models) (app/client/platforms/openai.ts:246) [LP-GE-12]: For gpt-5 and o-series models the limit sent is max_completion_tokens = Max Tokens, 4000 by default (store/config.ts:71). Reasoning tokens count against it. The stream parser reads delta content only (openai.ts:333-366) and never reads finish_reason, so a reply that stopped on the limit, or an empty one after long reasoning, is stored and shown as a finished answer. Change: Read finish_reason from the last stream chunk; on length, mark the message as cut off in the UI and offer to continue, and raise or drop the default cap for reasoning models.
- Claude replies cut at max_tokens are not flagged (app/client/platforms/anthropic.ts:244) [LP-GE-12]: max_tokens defaults to 4000 (anthropic.ts:187). The stream handler checks stop_reason only for refusal; stop_reason max_tokens is ignored, so a long answer ends mid-sentence without notice. Change: On message_delta with stop_reason max_tokens, mark the reply as cut off and offer to continue.
- A failed summary leaves a half-written memory (app/store/chat.ts:783) [LP-GE-12]: While the summary streams, onUpdate writes the partial text straight into session.memoryPrompt. onError only logs (chat.ts:794), and lastSummarizeIndex is not advanced, so an aborted or failed summary replaces the old memory with a fragment and the same summary is attempted again on the next turn. Change: Keep the stream text in a local variable and write memoryPrompt and lastSummarizeIndex together in onFinish.
- A chat's summary is built from the open chat's memory (app/store/chat.ts:531) [LP-GE-12]: getMemoryPrompt reads currentSession(), but summarizeSession(targetSession) calls it at chat.ts:745. If the user opens another chat while a reply streams, the summary of the first chat is built from the second chat's memory. Change: Pass the target session into getMemoryPrompt.

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

89static
E, prefill reuse
0.82
S, prefix stability
1.00
G, generation waste
0.00
Default shares
0 of 2

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

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

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

Scored 2026-11-27 (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.