π OpenHands: AI-Driven Development
Fix cached tokens (#7679)
Engel Nystd7f651a06c23
diff --git a/openhands/llm/llm.py b/openhands/llm/llm.pyindex 38b721d880..42ffe5eac8 100644--- a/openhands/llm/llm.py+++ b/openhands/llm/llm.py@@ -551,14 +551,16 @@ class LLM(RetryMixin, DebugMixin):'prompt_tokens_details')cache_hit_tokens = (- prompt_tokens_details.cached_tokens if prompt_tokens_details else 0+ prompt_tokens_details.cached_tokens+ if prompt_tokens_details and prompt_tokens_details.cached_tokens+ else 0)if cache_hit_tokens:stats += 'Input tokens (cache hit): ' + str(cache_hit_tokens) + '\n'# For Anthropic, the cache writes have a different cost than regular input tokens# but litellm doesn't separate them in the usage stats- # so we can read it from the provider-specific extra field+ # we can read it from the provider-specific extra fieldmodel_extra = usage.get('model_extra', {})cache_write_tokens = model_extra.get('cache_creation_input_tokens', 0)if cache_write_tokens: