diff --git a/core/llm/llms/Bedrock.ts b/core/llm/llms/Bedrock.ts index 415ec0f10..74c8f29e6 100644 --- a/core/llm/llms/Bedrock.ts +++ b/core/llm/llms/Bedrock.ts @@ -49,8 +49,10 @@ class Bedrock extends BaseLLM { options: CompletionOptions, ): AsyncGenerator { const credentials = await this._getCredentials(); + const client = new BedrockRuntimeClient({ region: this.region, + endpoint: this.apiBase, credentials: { accessKeyId: credentials.accessKeyId, secretAccessKey: credentials.secretAccessKey, @@ -58,6 +60,24 @@ class Bedrock extends BaseLLM { }, }); + let config_headers = this.requestOptions && this.requestOptions.headers ? this.requestOptions.headers : {}; + // AWS SigV4 requires strict canonicalization of headers. + // DO NOT USE "_" in your header name. It will return an error like below. + // "The request signature we calculated does not match the signature you provided." + + client.middlewareStack.add( + (next) => async (args) => { + args.request.headers = { + ...args.request.headers, + ...config_headers + }; + return next(args); + }, + { + step: 'build' + } + ); + const input = this._generateConverseInput(messages, options); const command = new ConverseStreamCommand(input); const response = await client.send(command);