The page leanprompt report --html writes for mem0ai/mem0 at commit cae3d8c, audited 2026-11-30. 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 mem0ai/mem0

leanprompt audit of mem0ai/mem0

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.

The audit found no place where this app pays for tokens it doesn't need

Plus 1 finding 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 4 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-PC-01 (already reported)mem0/llms/anthropic.py:1328.5M 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

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

No confirmed findings.

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.

The extraction system prompt (ADDITIVE_EXTRACTION_PROMPT, about 34 KB) is sent as a plain string on every add() with no cache_control, on the Anthropic and Bedrock bindings (Python and TypeScript).

Finding 1. mem0/llms/anthropic.py:132 medium LP-PC-01

What to change
Send the system prompt as a block with cache_control (Anthropic) or a cachePoint (Bedrock Converse).
Why it matters
About 8,500 tokens of an unchanging prefix are processed at the full input price on every add call.
Who reaches this
only users who configure the Anthropic or Bedrock LLM
Already reported
open issue: Anthropic/Bedrock extraction prompt is never prompt-cached https://github.com/mem0ai/mem0/issues/8071
Estimate
about 8.5M prompt tokens per 1,000 add calls on Anthropic or Bedrock (estimate)
What the estimate assumes

34,000 characters at about 4 characters per token; average call about 10,000 prompt tokens; only users who pick Anthropic or Bedrock; add calls return within the 5 minute lifetime in a chat app.

How to check the fix On the second add within 5 minutes, cache_read_input_tokens is about 8,500.

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.

TypeScript OSS ignores configured maxTokens, temperature and topP on every LLM provider except Anthropic and Bedrock

Note 1. mem0-ts/src/oss/src/llms/openai.ts:23 LP-GE-17 medium not scored

LLMConfig accepts maxTokens, temperature and topP, config/manager.ts:151 reads them, and the docs show them for xAI, DeepSeek and Together (docs/components/llms/models/xAI.mdx:52). Only anthropic.ts:67 and aws_bedrock.ts:203 put maxTokens in the request. OpenAILLM, which 8 other providers extend, sends only model and messages, so the cap, the temperature and top_p never reach the provider. The LLM reranker's default maxTokens of 100 (utils/factory.ts:269) is lost the same way.

What to change
Pass the configured values in the request body in OpenAILLM, and in the Groq, Azure, Mistral, Google and Ollama bindings (max_completion_tokens for reasoning models, as Python does), or say in the docs that only Anthropic and Bedrock read them.
Why it matters
Python sends these values; TypeScript users who copy the documented config get a different temperature (the provider default) and no output cap, so extraction and reranking behave differently from the Python library and a long reply is not bounded by the setting.

How to check the fix Call generateResponse against a stub OpenAI client with maxTokens: 50 and temperature: 0 in the config and check the request body carries them.

Configured max_tokens is not sent for reasoning models, including the default gpt-5-mini

Note 2. mem0/llms/base.py:121 LP-GE-17 medium not scored

For models classified as reasoning (every gpt-5-* with a dash, o1/o3, gpt-6), _get_supported_params keeps only messages, response_format, tools, tool_choice and reasoning_effort. max_tokens is dropped and max_completion_tokens is not added, so the 2000-token default, and the reranker's 100, do nothing on the default model.

What to change
Send max_completion_tokens for these models and size it for reasoning tokens.
In progress
open PR: fix(llms): keep configured token limit for reasoning models https://github.com/mem0ai/mem0/pull/5628

A cut-off extraction reply is read as no facts and the messages are marked as seen

Note 3. mem0/memory/main.py:986 LP-GE-12 high not scored

No LLM binding returns finish_reason or stop_reason. When the extraction JSON is cut off at max_tokens, json.loads fails, extracted_memories becomes [] and the messages are saved as processed, so the facts in them are lost without an error.

What to change
Return the finish reason from the bindings, and on a length stop retry with a higher cap or salvage the complete memory objects.
Already reported
open issue: Truncated extraction output (max_tokens hit mid-JSON) drops all facts https://github.com/mem0ai/mem0/issues/5428

Default model gpt-5-mini is scheduled for shutdown on 2026-12-11

Note 4. mem0/llms/openai.py:40 LP-GE-13 high not scored

The default model of the OpenAI, Azure, LiteLLM and structured bindings, of the LLM reranker and of the TypeScript defaults (mem0-ts/src/oss/src/config/defaults.ts:25) is gpt-5-mini. The OpenAI deprecations page (checked 2026-11-28) lists gpt-5-mini as Deprecated with shutdown Dec 11, 2026 and replacement gpt-6.1-terra.

What to change
Move the defaults to a model that is not scheduled for shutdown.
Already reported
open issue: default model gpt-5-mini shuts down on Dec 11, 2026 https://github.com/mem0ai/mem0/issues/7974

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.

Already known to the project (read the link first; do not duplicate work the project has planned or started):
- LP-PC-01 (mem0/llms/anthropic.py:132): The extraction system prompt (ADDITIVE_EXTRACTION_PROMPT, about 34 KB) is sent as a plain string on every add() with no cache_control, on the Anthropic and Bedrock bindings (Python and TypeScript). Already reported: open issue: Anthropic/Bedrock extraction prompt is never prompt-cached https://github.com/mem0ai/mem0/issues/8071

Other problems found (check each against the code first; not scored):
- TypeScript OSS ignores configured maxTokens, temperature and topP on every LLM provider except Anthropic and Bedrock (mem0-ts/src/oss/src/llms/openai.ts:23) [LP-GE-17]: LLMConfig accepts maxTokens, temperature and topP, config/manager.ts:151 reads them, and the docs show them for xAI, DeepSeek and Together (docs/components/llms/models/xAI.mdx:52). Only anthropic.ts:67 and aws_bedrock.ts:203 put maxTokens in the request. OpenAILLM, which 8 other providers extend, sends only model and messages, so the cap, the temperature and top_p never reach the provider. The LLM reranker's default maxTokens of 100 (utils/factory.ts:269) is lost the same way. Change: Pass the configured values in the request body in OpenAILLM, and in the Groq, Azure, Mistral, Google and Ollama bindings (max_completion_tokens for reasoning models, as Python does), or say in the docs that only Anthropic and Bedrock read them.
- Configured max_tokens is not sent for reasoning models, including the default gpt-5-mini (mem0/llms/base.py:121) [LP-GE-17]: For models classified as reasoning (every gpt-5-* with a dash, o1/o3, gpt-6), _get_supported_params keeps only messages, response_format, tools, tool_choice and reasoning_effort. max_tokens is dropped and max_completion_tokens is not added, so the 2000-token default, and the reranker's 100, do nothing on the default model. Change: Send max_completion_tokens for these models and size it for reasoning tokens.
- A cut-off extraction reply is read as no facts and the messages are marked as seen (mem0/memory/main.py:986) [LP-GE-12]: No LLM binding returns finish_reason or stop_reason. When the extraction JSON is cut off at max_tokens, json.loads fails, extracted_memories becomes [] and the messages are saved as processed, so the facts in them are lost without an error. Change: Return the finish reason from the bindings, and on a length stop retry with a higher cap or salvage the complete memory objects.
- Default model gpt-5-mini is scheduled for shutdown on 2026-12-11 (mem0/llms/openai.py:40) [LP-GE-13]: The default model of the OpenAI, Azure, LiteLLM and structured bindings, of the LLM reranker and of the TypeScript defaults (mem0-ts/src/oss/src/config/defaults.ts:25) is gpt-5-mini. The OpenAI deprecations page (checked 2026-11-28) lists gpt-5-mini as Deprecated with shutdown Dec 11, 2026 and replacement gpt-6.1-terra. Change: Move the defaults to a model that is not scheduled for shutdown.

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

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

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

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

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

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