MCPcopy Create free account
hub / github.com/Noumena-Network/code / getFirstPartyRequestHeaders

Function getFirstPartyRequestHeaders

src/services/api/client.ts:329–370  ·  view source on GitHub ↗
(options?: {
  apiKey?: string
  includeApiKeyHeader?: boolean
})

Source from the content-addressed store, hash-verified

327}
328
329export 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
372function buildFetch(
373 fetchOverride: ClientOptions['fetch'],

Callers 5

getAnthropicClientFunction · 0.85
getInferenceClientFunction · 0.85
client.test.tsFile · 0.85

Calls 8

isEnvTruthyFunction · 0.90
getCustomHeadersFunction · 0.85
getUserAgentFunction · 0.85
getSessionIdFunction · 0.85
getAuthRuntimeFunction · 0.85
logForDebuggingFunction · 0.50

Tested by

no test coverage detected