(options?: {
apiKey?: string
includeApiKeyHeader?: boolean
})
| 327 | } |
| 328 | |
| 329 | export async function getFirstPartyRequestHeaders(options?: { |
| 330 | apiKey?: string |
| 331 | includeApiKeyHeader?: boolean |
| 332 | }): Promise<Record<string, string>> { |
| 333 | const containerId = process.env.CLAUDE_CODE_CONTAINER_ID |
| 334 | const remoteSessionId = process.env.CLAUDE_CODE_REMOTE_SESSION_ID |
| 335 | const clientApp = process.env.NCODE_AGENT_SDK_CLIENT_APP |
| 336 | const customHeaders = getCustomHeaders() |
| 337 | const defaultHeaders: { [key: string]: string } = { |
| 338 | 'x-app': 'cli', |
| 339 | 'User-Agent': getUserAgent(), |
| 340 | 'X-Claude-Code-Session-Id': getSessionId(), |
| 341 | ...customHeaders, |
| 342 | ...getOrganizationUuidHeader(), |
| 343 | ...(containerId ? { 'x-claude-remote-container-id': containerId } : {}), |
| 344 | ...(remoteSessionId |
| 345 | ? { 'x-claude-remote-session-id': remoteSessionId } |
| 346 | : {}), |
| 347 | ...(clientApp ? { 'x-client-app': clientApp } : {}), |
| 348 | } |
| 349 | |
| 350 | logForDebugging( |
| 351 | `[API:request] Creating client, ANTHROPIC_CUSTOM_HEADERS present: ${!!process.env.ANTHROPIC_CUSTOM_HEADERS}, has Authorization header: ${!!customHeaders['Authorization']}`, |
| 352 | ) |
| 353 | |
| 354 | if (isEnvTruthy(process.env.CLAUDE_CODE_ADDITIONAL_PROTECTION)) { |
| 355 | defaultHeaders['x-anthropic-additional-protection'] = 'true' |
| 356 | } |
| 357 | |
| 358 | logForDebugging('[API:auth] First-party auth runtime resolution starting') |
| 359 | Object.assign( |
| 360 | defaultHeaders, |
| 361 | await getAuthRuntime().buildFirstPartyHeaders({ |
| 362 | apiKey: options?.apiKey, |
| 363 | includeApiKeyHeader: options?.includeApiKeyHeader, |
| 364 | allowRefresh: true, |
| 365 | }), |
| 366 | ) |
| 367 | logForDebugging('[API:auth] First-party auth runtime resolution complete') |
| 368 | |
| 369 | return defaultHeaders |
| 370 | } |
| 371 | |
| 372 | function buildFetch( |
| 373 | fetchOverride: ClientOptions['fetch'], |
no test coverage detected