Spaces:
Sleeping
Sleeping
File size: 563 Bytes
16bd88f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import time
from collections import defaultdict
# Store logs (replace with DB later)
USAGE_LOGS = defaultdict(list)
def log_request(api_key: str, endpoint: str):
USAGE_LOGS[api_key].append({
"endpoint": endpoint,
"time": int(time.time())
})
def get_usage(api_key: str):
return USAGE_LOGS.get(api_key, [])
def stats():
report = {}
for key, logs in USAGE_LOGS.items():
report[key] = {
"total_requests": len(logs),
"last_used": logs[-1]["time"] if logs else None
}
return report
|