MCPcopy
hub / github.com/codeaashu/claude-code / fetchUtilization

Function fetchUtilization

src/services/api/usage.ts:33–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

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