Skip to content

0.4.0: cache hit rates from Langfuse - #1

Merged
Haarris merged 1 commit into
mainfrom
feat/langfuse-import
Oct 20, 2026
Merged

Haarris merged 1 commit into
mainfrom
feat/langfuse-import

Conversation

@Haarris

@Haarris Haarris commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Adds cachecanary langfuse: hit rate and dollars lost per model from the generations a Langfuse project already records, so teams without Bedrock invocation logging can check their cache. Also available in the GitHub Action.

  • Reads only token counts, model names and timestamps (v2 observations API on Langfuse v4, v1 fallback on older servers).
  • Fixes counts that don't add up: Strands before 1.54 (input shown as 0), Strands 1.53 cache writes under a key Langfuse doesn't recognise, LiteLLM's langfuse callback counting cache writes twice. Rebuilt from the total when one was really sent; the output says how many calls were fixed.
  • Strips LiteLLM routing prefixes so one model stays one group and keeps its global endpoint price.
  • Tested against records from Strands 1.61/1.53, LiteLLM (both Langfuse integrations) and LangChain written into a real Langfuse 4.64 server, and against a production Langfuse Cloud project (matched a separate recount for every model).

…without Bedrock invocation logging can check their cache from the traces they already have

New `cachecanary langfuse` command (also in the GitHub Action). It reads only token counts, model names
and timestamps for the project's generations through the Langfuse public API (v2 on Langfuse v4, v1 on
older servers), and reports hit rate and input cost per model like `logs` does.

Langfuse stores the counts the way each integration sends them, and some don't add up: Strands before
1.54 makes the input look like 0 (so the cache looks perfect), Strands 1.53 sends its cache writes under
a name Langfuse doesn't recognise, and LiteLLM's langfuse callback counts cache writes twice. When a call
carries a total that was really sent, the uncached input is rebuilt from it and the output says how many
calls were fixed. LiteLLM routing prefixes are stripped so one model stays one group and keeps its
global endpoint price.

Tested against records that Strands 1.61 and 1.53, LiteLLM (both Langfuse integrations) and LangChain
wrote into a real Langfuse 4.64 server, and against a production Langfuse Cloud project, where the
numbers matched a separate recount for every model.
@Haarris
Haarris merged commit 47f551c into main Oct 20, 2026
9 of 10 checks passed

This branch was successfully deployed

1 active deployment
pypi — 47f551c5 Deployed Oct 20, 2026 by Haarris via publish-pypi #7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant