Skip to content

1.48.0: _cache_buckets raises AttributeError on litellm PromptTokensDetailsWrapper #5099

Closed

Description

@atineoSE

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.

Activity

  1. github-actions commented on Sep 16, 2026

    @github-actions
    Contributor

    ⚠️ Not yet ready-for-dev

    This issue does not yet meet the readiness criteria, so the
    ready-for-dev label has not been applied (or has been removed).
    The criteria are type-specific:

    Bug reports (bug label, see .github/ISSUE_TEMPLATE/bug_template.yml):

    • The ### Actual Behavior section must describe reproducible SDK steps
      and include a command such as python, pytest, uv, or pip.
    • An ### Acceptance Criteria section with at least one checklist item (- [ ] …).

    Enhancements (enhancement label, see .github/ISSUE_TEMPLATE/feature_request.yml):

    • A ### Desired Behavior section.
    • An ### Acceptance Criteria section with at least one checklist item.

    What is missing:

    • The issue has neither the bug nor enhancement label, so its readiness criteria cannot be evaluated. Add the appropriate label.

    Edit the issue to address the gaps and the ready-for-dev label will be
    applied automatically.

    Note: Section headings require exact ### matches from the templates.
    If a missing type label is reported, no action is needed from external
    contributors — maintainers will add the label during triage.

    This is an automated check — no AI was used to generate this comment.

  2. added
    bug
    llm
    priority:medium
    release-note-required
    on Sep 16, 2026
  3. dongjb commented on Sep 17, 2026

    @dongjb

    I encountered the same problem.

  4. carvalab commented on Sep 18, 2026

    @carvalab

    @dongjb I hit the same crash with MiniMax and put up PR #5169 with a fix. If you get a chance, please test it against your provider. I also verified it with ZAI glm-5.3-flash and it works there too.

  5. carvalab commented on Sep 18, 2026

    @carvalab

    Heads up: this is being tracked canonically in #5168, which carries ready-for-dev, with fix PR #5169. Steps to test the fix locally before it merges are here: #5168 (comment)

  6. VascoSch92 commented on Oct 12, 2026

    @VascoSch92
    Member

    Fixed by #5327 (v1.50.0): normalize_usage() in telemetry.py now checks hasattr as well as model_fields_set, so this no longer crashes on litellm 1.93–1.102. Please upgrade to ≥1.50.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugllmpriority:mediumrelease-note-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions