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

Function getAnthropicClient

src/services/api/client.ts:88–292  ·  view source on GitHub ↗
({
  apiKey,
  maxRetries,
  model,
  fetchOverride,
  source,
}: {
  apiKey?: string
  maxRetries: number
  model?: string
  fetchOverride?: ClientOptions['fetch']
  source?: string
})

Source from the content-addressed store, hash-verified

86}
87
88export async function getAnthropicClient({
89 apiKey,
90 maxRetries,
91 model,
92 fetchOverride,
93 source,
94}: {
95 apiKey?: string
96 maxRetries: number
97 model?: string
98 fetchOverride?: ClientOptions['fetch']
99 source?: string
100}): Promise<Anthropic> {
101 const defaultHeaders = await getFirstPartyRequestHeaders()
102 const resolvedFetch = getWrappedClientFetch(fetchOverride, source)
103
104 const ARGS = {
105 defaultHeaders,
106 maxRetries,
107 timeout: parseInt(process.env.API_TIMEOUT_MS || String(600 * 1000), 10),
108 dangerouslyAllowBrowser: true,
109 fetchOptions: getProxyFetchOptions({
110 forAnthropicAPI: true,
111 }) as ClientOptions['fetchOptions'],
112 ...(resolvedFetch && {
113 fetch: resolvedFetch,
114 }),
115 }
116 if (isEnvTruthy(process.env.CLAUDE_CODE_USE_BEDROCK)) {
117 const { AnthropicBedrock } = await import('@anthropic-ai/bedrock-sdk')
118 // Use region override for small fast model if specified
119 const awsRegion =
120 model === getSmallFastModel() &&
121 process.env.ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION
122 ? process.env.ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION
123 : getAWSRegion()
124
125 const bedrockArgs: ConstructorParameters<typeof AnthropicBedrock>[0] = {
126 ...ARGS,
127 awsRegion,
128 ...(isEnvTruthy(process.env.CLAUDE_CODE_SKIP_BEDROCK_AUTH) && {
129 skipAuth: true,
130 }),
131 ...(isDebugToStdErr() && { logger: createStderrLogger() }),
132 }
133
134 // Add API key authentication if available
135 if (process.env.AWS_BEARER_TOKEN_BEDROCK) {
136 bedrockArgs.skipAuth = true
137 // Add the Bearer token for Bedrock API key authentication
138 bedrockArgs.defaultHeaders = {
139 ...bedrockArgs.defaultHeaders,
140 Authorization: `Bearer ${process.env.AWS_BEARER_TOKEN_BEDROCK}`,
141 }
142 } else if (!isEnvTruthy(process.env.CLAUDE_CODE_SKIP_BEDROCK_AUTH)) {
143 // Refresh auth and get credentials with cache clearing
144 const cachedCredentials = await refreshCurrentAwsCredentials()
145 if (cachedCredentials) {

Callers 2

getInferenceClientFunction · 0.85
client.test.tsFile · 0.85

Calls 15

isEnvTruthyFunction · 0.90
getWrappedClientFetchFunction · 0.85
getProxyFetchOptionsFunction · 0.85
getSmallFastModelFunction · 0.85
getAWSRegionFunction · 0.85
isDebugToStdErrFunction · 0.85
createStderrLoggerFunction · 0.85
getVertexRegionForModelFunction · 0.85

Tested by

no test coverage detected