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

Function getAuthHeaders

src/utils/http.ts:69–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 * Returns either OAuth headers for Max/Pro users or API key headers for regular users
68 */
69export function getAuthHeaders(): AuthHeaders {
70 if (isClaudeAISubscriber()) {
71 const oauthTokens = getClaudeAIOAuthTokens()
72 if (!oauthTokens?.accessToken) {
73 return {
74 headers: {},
75 error: 'No OAuth token available',
76 }
77 }
78 return {
79 headers: {
80 Authorization: `Bearer ${oauthTokens.accessToken}`,
81 'anthropic-beta': OAUTH_BETA_HEADER,
82 },
83 }
84 }
85 // TODO: this will fail if the API key is being set to an LLM Gateway key
86 // should we try to query keychain / credentials for a valid Anthropic key?
87 const apiKey = getAnthropicApiKey()
88 if (!apiKey) {
89 return {
90 headers: {},
91 error: 'No API key available',
92 }
93 }
94 return {
95 headers: {
96 'x-api-key': apiKey,
97 },
98 }
99}
100
101/**
102 * Wrapper that handles OAuth 401 errors by force-refreshing the token and

Callers 3

submitFeedbackFunction · 0.50
submitTranscriptShareFunction · 0.50
doExportMethod · 0.50

Calls 2

getAnthropicApiKeyFunction · 0.85
isClaudeAISubscriberFunction · 0.70

Tested by

no test coverage detected