openai: surface prompt_tokens_details.cached_tokens as CacheReadInputTokens
OpenAI-compatible servers (llama.cpp, vLLM) report server-side prefix cache hits via prompt_tokens_details.cached_tokens. The streaming provider mapped only prompt/completion tokens and silently dropped the cache figure, so downstream usage analytics always saw zero cached input. Map it into Usage.CacheReadInputTokens.
This commit is contained in:
1 parent
9d338dd370
commit
eee6df9fc6
1 file changed
+7
@@ -315,6 +315,13 @@ func (p *OpenAIProvider) ChatStream(ctx context.Context, req llm.ChatRequest) (<
|
||||
InputTokens: resp.Usage.PromptTokens,
|
||||
OutputTokens: resp.Usage.CompletionTokens,
|
||||
}
|
||||
// OpenAI-compatible servers (vLLM, llama.cpp, ...) report
|
||||
// server-side prefix-cache hits via
|
||||
// prompt_tokens_details.cached_tokens. Surface them as cache
|
||||
// reads so downstream pricing/analytics see them.
|
||||
if resp.Usage.PromptTokensDetails != nil && resp.Usage.PromptTokensDetails.CachedTokens > 0 {
|
||||
lastUsage.CacheReadInputTokens = resp.Usage.PromptTokensDetails.CachedTokens
|
||||
}
|
||||
}
|
||||
|
||||
for _, choice := range resp.Choices {
|
||||
|
||||
Reference in new issue
Block a user