ollama - ✅(Solved) Fix Ollama's Cloud doesn't report number of cached tokens [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15758Fetched 2026-04-23 07:23:18
View on GitHub
Comments
0
Participants
1
Timeline
8
Reactions
7
Author
Participants
Timeline (top)
subscribed ×5cross-referenced ×1labeled ×1unsubscribed ×1

PR fix notes

PR #15768: feat(runner): expose prompt cache hit count in completion response

Description (problem / solution / changelog)

When the runner processes a completion request it consults the KV cache to skip re-evaluating prompt tokens that were already processed in a previous turn. The number of tokens actually served from that cache was tracked internally but never returned to callers, making it impossible to observe cache efficiency.

A new numCachedInputs field is added to the Sequence struct in runner/ollamarunner/runner.go. Immediately after loadCache populates seq.cache.Inputs, the length of that slice is captured as seq.numCachedInputs. That value is then included in the outgoing CompletionResponse as PromptCachedCount (omitted when zero so existing clients see no change).

On the server side, llm/server.go gains the corresponding PromptCachedCount int field with the prompt_cached_count,omitempty JSON tag so the information surfaces through the HTTP API without breaking backward compatibility.

Fixes #15758

Changed files

  • llm/server.go (modified, +1/-0)
  • runner/ollamarunner/runner.go (modified, +3/-0)
RAW_BUFFERClick to expand / collapse

What is the issue?

Behind the scenes requests are sped up with caches, but we currently always report 0 cached tokens.

extent analysis

TL;DR

The issue can likely be resolved by updating the cache reporting mechanism to accurately reflect the number of cached tokens.

Guidance

  • Review the cache implementation to ensure it is correctly updating the cache token count.
  • Verify that the cache reporting function is being called after the cache has been populated with tokens.
  • Check for any potential race conditions that might cause the cache token count to be reported as 0.
  • Investigate the cache invalidation logic to ensure it is not prematurely clearing the cache tokens.

Notes

The exact solution will depend on the specific cache implementation and reporting mechanism used in the system.

Recommendation

Apply workaround: Update the cache reporting mechanism to accurately reflect the number of cached tokens, as the current implementation is not providing correct information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - ✅(Solved) Fix Ollama's Cloud doesn't report number of cached tokens [1 pull requests, 1 participants]