* Get auth headers for policy limits without calling getSettings() * Supports both API key and OAuth authentication
()
| 225 | * Supports both API key and OAuth authentication |
| 226 | */ |
| 227 | function 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 |
no test coverage detected