{"record":{"id":"ba1c6591cd3194f8","repo":"BerriAI/litellm","slug":"failed-to-update-key-spend","errorCode":null,"errorMessage":"Failed to update key spend","messagePattern":"Failed to update key spend","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"litellm/proxy/management_endpoints/key_management_endpoints.py","lineNumber":5200,"sourceCode":"            )\n\n        current_spend: Final = _key_in_db.spend or 0.0\n        reset_to: Final = _validate_reset_spend_value(data.reset_to, _key_in_db)\n\n        await _check_proxy_or_team_admin_for_key(\n            key_in_db=_key_in_db,\n            user_api_key_dict=user_api_key_dict,\n            prisma_client=prisma_client,\n            user_api_key_cache=user_api_key_cache,\n        )\n\n        updated_key: Final = await _prisma_table(VerificationTokenRepository(prisma_client)).update(\n            where={\"token\": hashed_api_key},\n            data={\"spend\": reset_to},\n        )\n\n        if updated_key is None:\n            raise HTTPException(\n                status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,\n                detail={\"error\": \"Failed to update key spend\"},\n            )\n\n        await _delete_cache_key_object(\n            hashed_token=hashed_api_key,\n            user_api_key_cache=user_api_key_cache,\n            proxy_logging_obj=proxy_logging_obj,\n        )\n\n        # Set Redis spend counter to the new value so get_current_spend()\n        # returns the correct amount immediately instead of the stale pre-reset value.\n        # We use reset_to (not 0.0) so partial resets are reflected correctly.\n        from litellm.proxy.proxy_server import spend_counter_cache\n\n        _counter_key: Final = f\"spend:key:{hashed_api_key}\"\n        spend_counter_cache.in_memory_cache.set_cache(key=_counter_key, value=reset_to, ttl=60)\n        if spend_counter_cache.redis_cache is not None:","sourceCodeStart":5182,"sourceCodeEnd":5218,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/key_management_endpoints.py#L5182-L5218","documentation":"Error \"Failed to update key spend\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/proxy/management_endpoints/key_management_endpoints.py:5200 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check proxy logs for the underlying database error.","Verify the key exists and the database connection is healthy, then retry."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}