@@ -120,6 +120,52 @@ describe('AnthropicBedrockMantle', () => {
120120 } ) ;
121121 } ) ;
122122
123+ describe ( 'bearer token auth' , ( ) => {
124+ test ( 'sends Authorization: Bearer header when using apiKey' , async ( ) => {
125+ const client = new AnthropicBedrockMantle ( {
126+ apiKey : 'test-bearer-token' ,
127+ awsRegion : 'us-east-1' ,
128+ maxRetries : 0 ,
129+ } ) ;
130+
131+ await makeRequest ( client ) ;
132+
133+ const requestInit = mockFetch . mock . calls [ 0 ] ! [ 1 ] as RequestInit ;
134+ const headers = new Headers ( requestInit . headers as HeadersInit ) ;
135+ expect ( headers . get ( 'authorization' ) ) . toBe ( 'Bearer test-bearer-token' ) ;
136+ expect ( headers . get ( 'x-api-key' ) ) . toBeNull ( ) ;
137+ } ) ;
138+
139+ test ( 'sends Authorization: Bearer header when using AWS_BEARER_TOKEN_BEDROCK env var' , async ( ) => {
140+ process . env [ 'AWS_BEARER_TOKEN_BEDROCK' ] = 'env-bearer-token' ;
141+
142+ const client = new AnthropicBedrockMantle ( {
143+ awsRegion : 'us-east-1' ,
144+ maxRetries : 0 ,
145+ } ) ;
146+
147+ await makeRequest ( client ) ;
148+
149+ const requestInit = mockFetch . mock . calls [ 0 ] ! [ 1 ] as RequestInit ;
150+ const headers = new Headers ( requestInit . headers as HeadersInit ) ;
151+ expect ( headers . get ( 'authorization' ) ) . toBe ( 'Bearer env-bearer-token' ) ;
152+ expect ( headers . get ( 'x-api-key' ) ) . toBeNull ( ) ;
153+ } ) ;
154+
155+ test ( 'does not send Authorization: Bearer header when using SigV4' , async ( ) => {
156+ const client = new AnthropicBedrockMantle ( {
157+ awsAccessKey : 'my-access-key' ,
158+ awsSecretAccessKey : 'my-secret-key' ,
159+ awsRegion : 'us-east-1' ,
160+ maxRetries : 0 ,
161+ } ) ;
162+
163+ await makeRequest ( client ) ;
164+
165+ expect ( mockGetAuthHeaders ) . toHaveBeenCalledTimes ( 1 ) ;
166+ } ) ;
167+ } ) ;
168+
123169 describe ( 'endpoint restrictions' , ( ) => {
124170 test ( 'completions resource is not available' , ( ) => {
125171 const client = new AnthropicBedrockMantle ( {
0 commit comments