Use dict spread instead of in-place mutation in _normalize_usage_cache_tokens
Some checks failed
Unit Tests: Caching (Redis) / caching-redis (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (auth-checks, tests/proxy_unit_tests/test_auth_checks.py tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (key-generation, tests/proxy_unit_tests/test_key_generate_prisma.py, 30, 0) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (remaining, tests/proxy_unit_tests --ignore=tests/proxy_unit_tests/test_key_generate_prisma.py --ignore=tests/proxy_unit_tests/test_auth_checks.py --ignore=tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled

Avoids mutating the caller's response_obj["usage"] dict as a side effect.
This commit is contained in:
Yuneng Jiang 2026-04-08 10:23:04 -07:00
parent 30459e949b
commit ff3b5135cb
No known key found for this signature in database

View file

@ -4920,13 +4920,13 @@ class StandardLoggingPayloadSetup:
cached = getattr(prompt_details, "cached_tokens", None)
creation = getattr(prompt_details, "cache_creation_tokens", None)
extra: dict = {}
if cached and not usage_dict.get("cache_read_input_tokens"):
usage_dict["cache_read_input_tokens"] = cached
extra["cache_read_input_tokens"] = cached
if creation and not usage_dict.get("cache_creation_input_tokens"):
usage_dict["cache_creation_input_tokens"] = creation
extra["cache_creation_input_tokens"] = creation
return usage_dict
return {**usage_dict, **extra} if extra else usage_dict
@staticmethod
def get_model_cost_information(