MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / fetchUtilization

Function fetchUtilization

source code/services/api/usage.ts:35–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33}
34
35export async function fetchUtilization(): Promise<Utilization | null> {
36 if (!isClaudeAISubscriber() || !hasProfileScope()) {
37 return {}
38 }
39
40 // Skip API call if OAuth token is expired to avoid 401 errors
41 const tokens = getClaudeAIOAuthTokens()
42 if (tokens && isOAuthTokenExpired(tokens.expiresAt)) {
43 return null
44 }
45
46 const authResult = getAuthHeaders()
47 if (authResult.error) {
48 throw new Error(`Auth error: ${authResult.error}`)
49 }
50
51 const headers = {
52 'Content-Type': 'application/json',
53 'User-Agent': getClaudeCodeUserAgent(),
54 ...authResult.headers,
55 }
56
57 const url = `${getOauthConfig().BASE_API_URL}/api/oauth/usage`
58
59 const response = await axios.get<Utilization>(url, {
60 headers,
61 timeout: 5000, // 5 second timeout
62 })
63
64 return response.data
65}

Callers 3

UsageFunction · 0.85
runExtraUsageFunction · 0.85
checkOverageGateFunction · 0.85

Calls 6

isOAuthTokenExpiredFunction · 0.85
getClaudeCodeUserAgentFunction · 0.85
getOauthConfigFunction · 0.85
isClaudeAISubscriberFunction · 0.50
hasProfileScopeFunction · 0.50
getAuthHeadersFunction · 0.50

Tested by

no test coverage detected