MCPcopy Create free account
hub / github.com/codeaashu/claude-code / getHeaderBasedEarlyWarning

Function getHeaderBasedEarlyWarning

src/services/claudeAiLimits.ts:255–294  ·  view source on GitHub ↗

* Check if early warning should be triggered based on surpassed-threshold header. * Returns ClaudeAILimits if a threshold was surpassed, null otherwise.

(
  headers: globalThis.Headers,
  unifiedRateLimitFallbackAvailable: boolean,
)

Source from the content-addressed store, hash-verified

253 * Returns ClaudeAILimits if a threshold was surpassed, null otherwise.
254 */
255function getHeaderBasedEarlyWarning(
256 headers: globalThis.Headers,
257 unifiedRateLimitFallbackAvailable: boolean,
258): ClaudeAILimits | null {
259 // Check each claim type for surpassed threshold header
260 for (const [claimAbbrev, rateLimitType] of Object.entries(
261 EARLY_WARNING_CLAIM_MAP,
262 )) {
263 const surpassedThreshold = headers.get(
264 `anthropic-ratelimit-unified-${claimAbbrev}-surpassed-threshold`,
265 )
266
267 // If threshold header is present, user has crossed a warning threshold
268 if (surpassedThreshold !== null) {
269 const utilizationHeader = headers.get(
270 `anthropic-ratelimit-unified-${claimAbbrev}-utilization`,
271 )
272 const resetHeader = headers.get(
273 `anthropic-ratelimit-unified-${claimAbbrev}-reset`,
274 )
275
276 const utilization = utilizationHeader
277 ? Number(utilizationHeader)
278 : undefined
279 const resetsAt = resetHeader ? Number(resetHeader) : undefined
280
281 return {
282 status: 'allowed_warning',
283 resetsAt,
284 rateLimitType: rateLimitType as RateLimitType,
285 utilization,
286 unifiedRateLimitFallbackAvailable,
287 isUsingOverage: false,
288 surpassedThreshold: Number(surpassedThreshold),
289 }
290 }
291 }
292
293 return null
294}
295
296/**
297 * Check if time-relative early warning should be triggered for a rate limit type.

Callers 1

Calls 2

entriesMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected