MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / get_profile_usage

Function get_profile_usage

api_utils/utils_ext/usage_tracker.py:72–93  ·  view source on GitHub ↗

Returns the total usage for a profile. Reads directly from file (blocking), suitable for auth rotation logic which might run in sync context or low frequency. For high frequency, consider caching. Includes fallback logic to find usage by filename if absolute path doesn't match (hand

(profile_path: str)

Source from the content-addressed store, hash-verified

70
71
72def get_profile_usage(profile_path: str) -> int:
73 """
74 Returns the total usage for a profile.
75 Reads directly from file (blocking), suitable for auth rotation logic which might run in sync context or low frequency.
76 For high frequency, consider caching.
77 Includes fallback logic to find usage by filename if absolute path doesn't match (handles moved files).
78 """
79 profile_path = os.path.abspath(profile_path)
80 usage_data = _load_usage_data()
81
82 # Direct match
83 if profile_path in usage_data:
84 return usage_data[profile_path]
85
86 # Fallback: Match by filename
87 # This handles cases where files are moved (e.g. saved -> emergency) but usage data has old path
88 profile_basename = os.path.basename(profile_path)
89 for key, usage in usage_data.items():
90 if os.path.basename(key) == profile_basename:
91 return usage
92
93 return 0

Callers 2

_get_next_profileFunction · 0.90

Calls 1

_load_usage_dataFunction · 0.85

Tested by

no test coverage detected