MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / buildFetch

Function buildFetch

source code/services/api/client.ts:360–391  ·  view source on GitHub ↗
(
  fetchOverride: ClientOptions['fetch'],
  source: string | undefined,
)

Source from the content-addressed store, hash-verified

358export const CLIENT_REQUEST_ID_HEADER = 'x-client-request-id'
359
360function buildFetch(
361 fetchOverride: ClientOptions['fetch'],
362 source: string | undefined,
363): ClientOptions['fetch'] {
364 // eslint-disable-next-line eslint-plugin-n/no-unsupported-features/node-builtins
365 const inner = fetchOverride ?? globalThis.fetch
366 // Only send to the first-party API — Bedrock/Vertex/Foundry don't log it
367 // and unknown headers risk rejection by strict proxies (inc-4029 class).
368 const injectClientRequestId =
369 getAPIProvider() === 'firstParty' && isFirstPartyAnthropicBaseUrl()
370 return (input, init) => {
371 // eslint-disable-next-line eslint-plugin-n/no-unsupported-features/node-builtins
372 const headers = new Headers(init?.headers)
373 // Generate a client-side request ID so timeouts (which return no server
374 // request ID) can still be correlated with server logs by the API team.
375 // Callers that want to track the ID themselves can pre-set the header.
376 if (injectClientRequestId && !headers.has(CLIENT_REQUEST_ID_HEADER)) {
377 headers.set(CLIENT_REQUEST_ID_HEADER, randomUUID())
378 }
379 try {
380 // eslint-disable-next-line eslint-plugin-n/no-unsupported-features/node-builtins
381 const url = input instanceof Request ? input.url : String(input)
382 const id = headers.get(CLIENT_REQUEST_ID_HEADER)
383 logForDebugging(
384 `[API REQUEST] ${new URL(url).pathname}${id ? ` ${CLIENT_REQUEST_ID_HEADER}=${id}` : ''} source=${source ?? 'unknown'}`,
385 )
386 } catch {
387 // never let logging crash the fetch
388 }
389 return inner(input, { ...init, headers })
390 }
391}

Callers 1

getAnthropicClientFunction · 0.85

Calls 6

getAPIProviderFunction · 0.85
logForDebuggingFunction · 0.85
setMethod · 0.80
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected