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

Function getAuthHeaders

src/services/policyLimits/index.ts:227–262  ·  view source on GitHub ↗

* Get auth headers for policy limits without calling getSettings() * Supports both API key and OAuth authentication

()

Source from the content-addressed store, hash-verified

225 * Supports both API key and OAuth authentication
226 */
227function getAuthHeaders(): {
228 headers: Record<string, string>
229 error?: string
230} {
231 // Try API key first (for Console users)
232 try {
233 const { key: apiKey } = getAnthropicApiKeyWithSource({
234 skipRetrievingKeyFromApiKeyHelper: true,
235 })
236 if (apiKey) {
237 return {
238 headers: {
239 'x-api-key': apiKey,
240 },
241 }
242 }
243 } catch {
244 // No API key available - continue to check OAuth
245 }
246
247 // Fall back to OAuth tokens (for Claude.ai users)
248 const oauthTokens = getClaudeAIOAuthTokens()
249 if (oauthTokens?.accessToken) {
250 return {
251 headers: {
252 Authorization: `Bearer ${oauthTokens.accessToken}`,
253 'anthropic-beta': OAUTH_BETA_HEADER,
254 },
255 }
256 }
257
258 return {
259 headers: {},
260 error: 'No authentication available',
261 }
262}
263
264/**
265 * Fetch policy limits with retry logic and exponential backoff

Callers 9

fetchPolicyLimitsFunction · 0.70
grove.tsFile · 0.50
markGroveNoticeViewedFunction · 0.50
updateGroveSettingsFunction · 0.50
_fetchMetricsEnabledFunction · 0.50
fetchUtilizationFunction · 0.50
sendBatchWithRetryMethod · 0.50
growthbook.tsFile · 0.50

Calls 1

Tested by

no test coverage detected