Skip to content

Commit 3961628

Browse files
stainless-app[bot]RobertCraigie
authored andcommitted
fix(client): send all configured auth headers
1 parent 4c4d763 commit 3961628

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/client.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import * as API from './resources/index';
2121
import { APIPromise } from './core/api-promise';
2222
import { type Fetch } from './internal/builtin-types';
2323
import { isRunningInBrowser } from './internal/detect-platform';
24-
import { HeadersLike, NullableHeaders, buildHeaders, isEmptyHeaders } from './internal/headers';
24+
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
2525
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
2626
import {
2727
Completion,
@@ -307,32 +307,22 @@ export class BaseAnthropic {
307307
);
308308
}
309309

310-
protected authHeaders(opts: FinalRequestOptions): Headers | undefined {
311-
const apiKeyAuth = this.apiKeyAuth(opts);
312-
const bearerAuth = this.bearerAuth(opts);
313-
314-
if (apiKeyAuth != null && !isEmptyHeaders(apiKeyAuth)) {
315-
return apiKeyAuth;
316-
}
317-
318-
if (bearerAuth != null && !isEmptyHeaders(bearerAuth)) {
319-
return bearerAuth;
320-
}
321-
return undefined;
310+
protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
311+
return buildHeaders([this.apiKeyAuth(opts), this.bearerAuth(opts)]);
322312
}
323313

324-
protected apiKeyAuth(opts: FinalRequestOptions): Headers | undefined {
314+
protected apiKeyAuth(opts: FinalRequestOptions): NullableHeaders | undefined {
325315
if (this.apiKey == null) {
326316
return undefined;
327317
}
328-
return new Headers({ 'X-Api-Key': this.apiKey });
318+
return buildHeaders([{ 'X-Api-Key': this.apiKey }]);
329319
}
330320

331-
protected bearerAuth(opts: FinalRequestOptions): Headers | undefined {
321+
protected bearerAuth(opts: FinalRequestOptions): NullableHeaders | undefined {
332322
if (this.authToken == null) {
333323
return undefined;
334324
}
335-
return new Headers({ Authorization: `Bearer ${this.authToken}` });
325+
return buildHeaders([{ Authorization: `Bearer ${this.authToken}` }]);
336326
}
337327

338328
/**

0 commit comments

Comments
 (0)