MCPcopy Create free account
hub / github.com/oboard/claude-code-rev / getAuthHeaders

Function getAuthHeaders

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

Source from the content-addressed store, hash-verified

79 * Returns either OAuth headers for Max/Pro users or API key headers for regular users
80 */
81export function getAuthHeaders(): AuthHeaders {
82 if (isClaudeAISubscriber()) {
83 const oauthTokens = getClaudeAIOAuthTokens()
84 if (!oauthTokens?.accessToken) {
85 return {
86 headers: {},
87 error: 'No OAuth token available',
88 }
89 }
90 return {
91 headers: {
92 Authorization: `Bearer ${oauthTokens.accessToken}`,
93 'anthropic-beta': OAUTH_BETA_HEADER,
94 },
95 }
96 }
97 // TODO: this will fail if the API key is being set to an LLM Gateway key
98 // should we try to query keychain / credentials for a valid Anthropic key?
99 const apiKey = getAnthropicApiKey()
100 const authToken = getConfiguredProviderAuthToken()
101 const providerType = getActiveProviderConfig().type
102 if (authToken && !isOpenAICompatibleProviderType(providerType)) {
103 return {
104 headers: {
105 Authorization: `Bearer ${authToken}`,
106 },
107 }
108 }
109 if (apiKey && isOpenAICompatibleProviderType(providerType)) {
110 return {
111 headers: {
112 Authorization: `Bearer ${apiKey}`,
113 },
114 }
115 }
116 if (!apiKey) {
117 return {
118 headers: {},
119 error: 'No API key available',
120 }
121 }
122 return {
123 headers: {
124 'x-api-key': apiKey,
125 },
126 }
127}
128
129/**
130 * Wrapper that handles OAuth 401 errors by force-refreshing the token and

Callers 3

submitFeedbackFunction · 0.50
submitTranscriptShareFunction · 0.50
doExportMethod · 0.50

Calls 5

getAnthropicApiKeyFunction · 0.85
getActiveProviderConfigFunction · 0.85
isClaudeAISubscriberFunction · 0.70

Tested by

no test coverage detected