Most TypeScript LLM providers never send the configured maxTokens

Setting that does nothing Reported

A memory layer for AI agents in Python and TypeScript; its Anthropic and Bedrock providers already send the configured limits.

The mistake: Setting that does nothingSETTINGmaxTokens, temperature andtopP in LLMConfigREQUESTOpenAI and 13 other providersleave them outRESULTEach provider's own defaultsapply insteadOnly Anthropic and Bedrock send themThe mistake: Setting that does nothingSETTINGmaxTokens,temperature andtopP in LLMConfigREQUESTOpenAI and 13 otherproviders leavethem outOnly Anthropic and Bedrock send themRESULTEach provider's owndefaults applyinsteadThe mistake: Setting that does nothingSETTINGmaxTokens, temperature and topPin LLMConfigREQUESTOpenAI and 13 other providersleave them outOnly Anthropic and Bedrock sendthemRESULTEach provider's own defaultsapply instead

Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.

Repository
mem0ai/mem0 69.7k GitHub stars
Commit audited
cae3d8c
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 cae3d8c and found 0 places where its LLM calls could use fewer tokens, 1 the project already knows about, plus 4 other problems, not scored. Static score: 100 of 100 (an estimate from the findings, leaving out what the project already knows about). The code may have changed since.

Findings

No open findings.

Already known to the project

The project’s own issues, pull requests or docs already cover these, so they are not counted above and are left out of the static score.

  1. LP-PC-01 Put cache marks where the provider needs them

    mem0/llms/anthropic.py:132 · severity medium · saves prefill

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

    The change. Send the system prompt as a block with cache_control (Anthropic) or a cachePoint (Bedrock Converse).

    Why it helps. About 8,500 tokens of an unchanging prefix are processed at the full input price on every add call.

    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)

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

    Who reaches this. only users who configure the Anthropic or Bedrock LLM

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.

  1. 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 Send the output cap the owner set, on every path · severity medium

    What happens. 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.

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

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

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

    mem0/llms/base.py:121 · LP-GE-17 Send the output cap the owner set, on every path · severity medium

    What happens. 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.

    The 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

  3. 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 Read the finish reason before using an answer · severity high

    What happens. 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.

    The 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

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

    mem0/llms/openai.py:40 · LP-GE-13 Default to a model the provider still serves · severity high

    What happens. 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.

    The 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

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.