Skip to content

AttributeError: 'PromptTokensDetailsWrapper' object has no attribute 'cache_creation_tokens' on minimax-m3 (local, not SaaS) #5326

Closed

Description

@juanmichelini

Summary

When running OpenHands locally with minimax-m3, every LLM call crashes in usage telemetry:

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

This does not reproduce on the hosted SaaS, and does not reproduce with other models locally.

Root cause

openhands/sdk/llm/utils/telemetry.py normalize_usage() reads cache-write tokens via a bare attribute access guarded only by model_fields_set:

cache_write = 0
if (
    prompt_details is not None
    and "cache_creation_tokens" in prompt_details.model_fields_set
):
    cache_write = int(prompt_details.cache_creation_tokens or 0)   # AttributeError

litellm's PromptTokensDetailsWrapper.__init__() deletes optional fields whose value is None from the instance:

if self.cache_creation_tokens is None:
    del self.cache_creation_tokens

So when a provider reports prompt_tokens_details with cache_creation_tokens: null, the field is present in model_fields_set (guard passes) but physically deleted from the instance (bare access raises AttributeError).

minimax-m3's OpenAI-compatible usage emits exactly {"cached_tokens": ..., "cache_creation_tokens": null}; the other tested models either omit the field or report a real integer, so they don't trip it.

Reproduced against litellm 1.93.0 (the SDK pin) directly:

model_fields_set has it: True
AttributeError: 'PromptTokensDetailsWrapper' object has no attribute 'cache_creation_tokens'
hasattr: False

Why SaaS is unaffected / why this is a regression

  • The older SDK telemetry read cache-write tokens via getattr(usage, "_cache_creation_input_tokens", 0) — a litellm PrivateAttr that is always present (default 0) and never deleted. The SaaS still runs that code path.
  • Commit 52feb470 ("fix(sdk): normalize LLM usage telemetry through a typed adapter", fix(sdk): normalize LLM usage telemetry through a typed adapter #5029, shipped in SDK v1.49.5/v1.49.6) rewrote this to access prompt_details.cache_creation_tokens guarded only by model_fields_set, which is unsafe given litellm's del-on-None behavior.

Can it be fixed in litellm?

No — not by upgrading. The del self.cache_creation_tokens (on None) behavior is present across 1.93.0 → 1.100.0 → latest main → latest PyPI (1.102.1). The mismatch between model_fields_set (says present) and the bare attribute (deleted) is inherent to the SDK's access pattern regardless of litellm version.

Proposed fix

Use getattr with a default instead of a bare attribute access in normalize_usage():

cache_write = int(getattr(prompt_details, "cache_creation_tokens", 0) or 0)

This tolerates the field being set-but-deleted while preserving the existing model_fields_set semantics (only count a cache write when the provider actually reported the field). A regression test is added in the accompanying PR.

Environment

  • SDK: v1.49.5+ (regression introduced in 52feb470)
  • litellm: 1.93.0 (and reproduces on every version through latest)
  • Model: minimax-m3

OpenHands AI triage

The following comments and acceptance criteria were added by the OpenHands AI agent.

Triage

This is a well-scoped, already-diagnosed regression. Verified against the repository at v1.49.6: normalize_usage() in openhands-sdk/openhands/sdk/llm/utils/telemetry.py guards the cache-write read with "cache_creation_tokens" in prompt_details.model_fields_set and then does a bare prompt_details.cache_creation_tokens. In litellm 1.93.0 (the workspace pin) PromptTokensDetailsWrapper.__init__ deletes that attribute when its value is None, so a provider that reports cache_creation_tokens: null (as minimax-m3 does) passes the guard but raises AttributeError. The documented history (52feb470 in #5029) makes this a local-only regression, consistent with the report.

Bounded scope: make normalize_usage() tolerant of a cache_creation_tokens field that is recorded in model_fields_set but deleted from the instance, so a chat-completions response from such a provider normalizes to cache_write_tokens == 0 instead of crashing. The canonical normalization boundary (normalize_usage() / UsageSnapshot) is the place to fix this; no other call site should need to change.

Explicit non-goals: upgrading or patching litellm (the del-on-None behavior is present across 1.93.0 through current releases), changing UsageSnapshot fields or their meaning, altering cost accounting, and changing behavior for providers that report a real integer or omit the field.

Steps to Reproduce

  1. Run OpenHands locally with minimax-m3 (litellm 1.93.0) against a provider whose OpenAI-compatible usage reports prompt_tokens_details containing cache_creation_tokens: null.
  2. Make any LLM call.
  3. Usage telemetry raises AttributeError: 'PromptTokensDetailsWrapper' object has no attribute 'cache_creation_tokens'.

Acceptance Criteria

  • A chat-completions Usage whose prompt_tokens_details lists cache_creation_tokens in model_fields_set but has that attribute deleted (litellm's del-on-None) is normalized by normalize_usage() to cache_write_tokens == 0 with no AttributeError.
  • A provider that reports an integer cache_creation_tokens still yields that value, and a provider that never sets the field still yields cache_write_tokens == 0 (existing model_fields_set semantics preserved).
  • Other normalized fields (prompt_tokens, completion_tokens, reasoning_tokens, cache_read_tokens) are unchanged for the affected response, and normalize_usage() still returns None for unrecognized/absent usage.
  • An LLM call against a usage shape containing cache_creation_tokens: null completes without the telemetry AttributeError and records token usage/cost as before.
  • A regression test reproducing the set-but-deleted field lives under tests/sdk/llm/test_llm_telemetry.py and fails on the current code and passes after the change; the existing tests/sdk/llm telemetry tests continue to pass.
  • No public API, serialized UsageSnapshot/Metrics shape, or persisted-data compatibility change is introduced.

Activity

  1. added
    priority:medium
    ready-for-dev
    on Sep 25, 2026
  2. all-hands-bot commented on Sep 25, 2026

    @all-hands-bot
    Collaborator

    Issue #5326 reports the same AttributeError from Telemetry._cache_buckets reading details.cache_creation_tokens guarded only by model_fields_set, breaking litellm PromptTokensDetailsWrapper when the field is None/deleted. This is the identical root cause, file, and getattr-based fix already tracked by several open issues. #5168 is the community-designated canonical thread (it carries ready-for-dev and the active fix PR #5169), and #5099/#5134 already redirect there. #5326 adds only provider-specific detail (minimax-m3, explicit cache_creation_tokens: null, regression commit 52feb47/#5029), which belongs as a comment on the canonical issue rather than a separate thread.

    Found 3 possible duplicate issues:

    1. #5168 — AttributeError in Telemetry._cache_buckets for providers without prompt caching
    2. #5099 — 1.48.0: _cache_buckets raises AttributeError on litellm PromptTokensDetailsWrapper
    3. #5134 — AttributeError: 'PromptTokensDetailsWrapper' object has no attribute 'cache_creation_tokens' in Telemetry._cache_buckets

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    This comment was created by an AI assistant (OpenHands) on behalf of the repository maintainer.

  3. added
    duplicate-candidate
    on Sep 25, 2026
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

    duplicate-candidatepriority:mediumready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions