From f4b4e0c1992a028c4e9aa1e04549f625395012e4 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Tue, 30 Jul 2024 10:41:44 -0700 Subject: [PATCH] anthropic[patch]: Pass custom headers through to request (#6275) * anthropic[patch]: Pass custom headers through to request * chore: lint files --- libs/langchain-anthropic/src/chat_models.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/libs/langchain-anthropic/src/chat_models.ts b/libs/langchain-anthropic/src/chat_models.ts index fd725018298d..e4b6f37ef856 100644 --- a/libs/langchain-anthropic/src/chat_models.ts +++ b/libs/langchain-anthropic/src/chat_models.ts @@ -61,6 +61,11 @@ export interface ChatAnthropicCallOptions * @default "auto" */ tool_choice?: AnthropicToolChoice; + /** + * Custom headers to pass to the Anthropic API + * when making a request. + */ + headers?: Record; } function _toolsInParams(params: AnthropicMessageCreateParams): boolean { @@ -422,11 +427,16 @@ export class ChatAnthropicMessages< stream: false, }); - const stream = await this.createStreamWithRetry({ - ...params, - ...formattedMessages, - stream: true, - }); + const stream = await this.createStreamWithRetry( + { + ...params, + ...formattedMessages, + stream: true, + }, + { + headers: options.headers, + } + ); for await (const data of stream) { if (options.signal?.aborted) { @@ -543,6 +553,7 @@ export class ChatAnthropicMessages< } else { return this._generateNonStreaming(messages, params, { signal: options.signal, + headers: options.headers, }); } }