OpenHands / OpenHands/software-agent-sdk

1.48.0: _cache_buckets raises AttributeError on litellm PromptTokensDetailsWrapper

Open Beginner friendly
#5,099 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug llm priority:medium release-note-required
Dominant language
Python
Stars
1.1k
Forks
539
Avg merge
1d 19h
Merged PRs (30d)
137

Description

What happens

Every completion() whose provider reports no cache-creation tokens raises:

AttributeError: 'PromptTokensDetailsWrapper' object has no attribute 'cache_creation_tokens'

from openhands/sdk/llm/utils/telemetry.py, in Telemetry._cache_buckets.

Why

cache_write = (
    details.cache_creation_tokens
    if "cache_creation_tokens" in details.model_fields_set
    else 0
)

model_fields_set is not a safe test for this object. litellm's
PromptTokensDetailsWrapper extends SafeAttributeModel, which removes
attributes whose value is None — but the field name stays in
model_fields_set, because it was set at construction. So the guard passes
and the attribute access fails.

Reproduction

litellm 1.100.1, openhands-sdk 1.48.0:

from litellm.types.utils import PromptTokensDetailsWrapper

d = PromptTokensDetailsWrapper(cached_tokens=5, cache_creation_tokens=None)
print(sorted(d.model_fields_set))      # ['cache_creation_tokens', 'cache_write_tokens', 'cached_tokens']
print(hasattr(d, "cache_creation_tokens"))  # False
d.cache_creation_tokens                # AttributeError

Suggested fix

getattr(details, "cache_creation_tokens", 0), which is what 1.47.0 did and
what the sibling usage-level reads a few lines above still do.

Versions

  • openhands-sdk 1.48.0 (also present on main as of 2026-09-16)
  • litellm 1.100.1

1.47.0 is unaffected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in openhands/sdk/llm/utils/telemetry.py at Telemetry._cache_buckets, then compare its cache-creation read with the sibling usage-level reads above. Reproduce with the PromptTokensDetailsWrapper example from the issue and verify that completion() no longer raises AttributeError when cache-creation tokens are absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.