diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index a7c5b47059..d08f1c91ca 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -390,7 +390,8 @@ def _extract_reasoning_content( def _extract_usage(self, usage: CompletionUsage | dict) -> TokenUsage: ptd = getattr(usage, "prompt_tokens_details", None) cached = getattr(ptd, "cached_tokens", 0) if ptd else 0 - prompt_tokens = getattr(usage, "prompt_tokens", 0) or 0 + cached = cached if isinstance(cached, int) else 0 # ptd.cached_tokens 可能为None + prompt_tokens = getattr(usage, "prompt_tokens", 0) or 0 # 安全 completion_tokens = getattr(usage, "completion_tokens", 0) or 0 return TokenUsage( input_other=prompt_tokens - cached,