The Bedrock system prompt has no cache mark, so every call pays in full

A graph-based retrieval library that meters tokens per call and already has an open pull request adding prompt caching to its Anthropic binding.
≈ 1,500,000 tokens per 1,000 calls, prompt tokens paid at full price for a system prompt the cache could have served estimate
Audited with leanprompt 0.1.0-dev.15
Estimates, not measurements. Every figure on this page is an estimate from reading the code, not a measurement of the app in use.
- Repository
- HKUDS/LightRAG
- Commit audited
b3ca0dd- leanprompt version
- 0.1.0-dev.15
- Audit date
- Status
- The maintainers have been told about this audit; no response yet.
- Maintainers
- the pull request
- 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.
Three small pull requests were opened: Bedrock cache marks and cache token metering (#4743, linked below), a warning on the retired Claude 3 helpers (#4744) and cached-token metering for the OpenAI Responses binding (#4745).
leanprompt read the code at commit b3ca0dd and found 1 place where its LLM calls could use fewer tokens, plus 3 other problems, not scored. Static score: 74 of 100 (an estimate from the findings). The code may have changed since.
Findings
-
LP-PC-01Put cache marks where the provider needs themlightrag/llm/bedrock.py:334· severity medium · saves prefill · how often is assumedWhat happens. The Bedrock binding sends the system prompt as a plain text block with no cachePoint (bedrock.py:334). The entity-extraction system prompt is rendered once per run (operate.py:4655/4668) and is the same for every chunk and every gleaning call, about 1.5k tokens. AWS says Claude models on Bedrock do not cache requests without a checkpoint, and the repo's own Bedrock sample model is anthropic.claude-haiku-4-5 (env.example:1914). The Anthropic binding has the same gap (anthropic.py:208) and is already tracked (#4464, open PR #4729).
The change. Add an opt-in cache_system_prompt argument that appends {"cachePoint": {"type": "default"}} after the system text block, as #4729 does for Anthropic.
Why it helps. Every extraction call pays full input price for the same ~1.5k-token prefix. Claude Haiku 4.5 has a 4,096-token minimum, so the system prompt alone will not cache there; models with a 512 or 1,024 minimum will.
Estimate about 1.5M uncached prompt tokens per 1,000 extraction calls (about 42% of an average call); a cache read bills about a tenth of that on models where the prefix is long enough
Assumptions. system prompt about 1.5k tokens (the maintainers' own tiktoken estimate in #4464), chunk 1,200 tokens, one gleaning call per chunk; Bedrock Claude model whose minimum is at or below 1,024 tokens
How often. How many extraction calls the deployment sends to a Bedrock Claude model with a 512 or 1,024 token cache minimum.
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.
-
Bedrock usage ignores cache reads and writes
lightrag/llm/bedrock.py:400·LP-GE-11Meter every billed token, cached and unfinished ones too · severity mediumWhat happens. Both usage paths pass inputTokens straight to TokenTracker (bedrock.py:400 streaming, :480 non-streaming). Converse reports inputTokens for uncached tokens only; cache reads and writes arrive in cacheReadInputTokens and cacheWriteInputTokens (AWS prompt caching page). With caching on (e.g. BEDROCK_LLM_EXTRA_FIELDS with a top-level cache_control, bedrock.py:356-358), prompt_tokens drops to the uncached remainder and the cache share is never reported. OpenAI and Gemini bindings already report cached_prompt_tokens (#4572, #4687).
The change. prompt_tokens = inputTokens + cacheReadInputTokens + cacheWriteInputTokens; report cacheReadInputTokens as cached_prompt_tokens.
To check. Feed a Converse usage block with cacheReadInputTokens to a TokenTracker: prompt_tokens includes it and get_usage() shows cached_prompt_tokens.
-
Public Claude 3 helpers name retired models
lightrag/llm/anthropic.py:462·LP-GE-13Default to a model the provider still serves · severity lowWhat happens. claude_3_opus_complete, claude_3_sonnet_complete and claude_3_haiku_complete hard-code claude-3-opus-20240229 (:462), claude-3-sonnet-20240229 (:483) and claude-3-haiku-20240307 (:504). Anthropic's deprecations page lists them retired on 2026-01-05, 2025-07-21 and 2026-04-20; requests return 404. Library helpers only: the server does not use the Anthropic binding and nothing but a test calls them.
The change. Remove the three helpers or point them at a current model; use anthropic_complete with LLM_MODEL instead.
To check. grep for claude-3- under lightrag/ returns nothing.
-
Responses binding drops cached prompt tokens
lightrag/llm/openai_responses.py:358·LP-GE-11Meter every billed token, cached and unfinished ones too · severity lowWhat happens. _usage_counts forwards input, output and total tokens only, so a run through the OpenAI Responses binding shows no cached_prompt_tokens in the TokenTracker, while the Chat Completions binding does since #4572.
The change. Read usage.input_tokens_details.cached_tokens and forward it as cached_prompt_tokens, keeping a reported zero.
To check. A mocked Responses usage with input_tokens_details.cached_tokens=5 gives cached_prompt_tokens 5 in the tracker; absent or null details leave the field out.
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.