OpenHands / OpenHands/software-agent-sdk

AttributeError in Telemetry._cache_buckets for providers without prompt caching

Open Beginner friendly
#5,168 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug llm priority:medium ready-for-dev sdk
Dominant language
Python
Stars
1.1k
Forks
542
Avg merge
1d 19h
Merged PRs (30d)
137

Description

Any provider whose usage response includes prompt_tokens_details without cache fields crashes profile validation and token recording with:

'PromptTokensDetailsWrapper' object has no attribute 'cache_creation_tokens'

Reproduced with MiniMax (Custom Model openai/MiniMax-M3, also the native minimax/MiniMax-M3 provider, Base URL https://api.minimax.io/v1, openhands-sdk 1.49.1), and other reporters hit it with different providers and models, including GLM-5.3 (see #5099 and the comments below). Also verified working with ZAI glm-5.3-flash.

Root cause: Telemetry._cache_buckets in openhands-sdk/openhands/sdk/llm/utils/telemetry.py reads details.cache_creation_tokens directly, guarded only by "cache_creation_tokens" in details.model_fields_set. LiteLLM's PromptTokensDetailsWrapper.__init__ deletes unset optional fields, while its __setattr__ mirroring keeps the name in model_fields_set. So the guard passes and the read raises AttributeError.

Actual Behavior

Saving the profile fails validation with the AttributeError above. Reproduced against the installed SDK with python:

from litellm.types.utils import Usage, PromptTokensDetailsWrapper
from openhands.sdk.llm.utils.telemetry import Telemetry

usage = Usage(
    prompt_tokens=100,
    completion_tokens=50,
    total_tokens=150,
    prompt_tokens_details=PromptTokensDetailsWrapper(cached_tokens=0),
)
Telemetry._cache_buckets(usage)

model_fields_set contains cache_creation_tokens even though the attribute was deleted, so the guard passes and the direct read raises.

Acceptance Criteria
  • Saving an LLM profile for a provider without prompt caching passes validation instead of raising AttributeError
  • The cache buckets default to 0 when the provider returns no cache fields

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/openhands/sdk/llm/utils/telemetry.py at Telemetry._cache_buckets, then run the Python reproduction using Usage and PromptTokensDetailsWrapper shown in the issue. Confirm that profile validation and token recording no longer raise AttributeError and that cache buckets default to 0 when cache fields 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.