Skip to content

Commit d4b374b

Browse files
authored
Merge pull request #1433 from Portkey-AI/fix/autoForwardAnthropicHeaders
Auto add anthropic headers
2 parents aa49b75 + a738edd commit d4b374b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/handlers/handlerUtils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,17 +949,25 @@ export function constructConfigFromRequestHeaders(
949949
vertexModelName: requestHeaders[`x-${POWERED_BY}-provider-model`],
950950
vertexBatchEndpoint:
951951
requestHeaders[`x-${POWERED_BY}-provider-batch-endpoint`],
952-
anthropicBeta: requestHeaders[`x-${POWERED_BY}-anthropic-beta`],
952+
anthropicBeta:
953+
requestHeaders[`x-${POWERED_BY}-anthropic-beta`] ||
954+
requestHeaders[`anthropic-beta`],
953955
};
954956

955957
const fireworksConfig = {
956958
fireworksAccountId: requestHeaders[`x-${POWERED_BY}-fireworks-account-id`],
957959
fireworksFileLength: requestHeaders[`x-${POWERED_BY}-file-upload-size`],
958960
};
959961

962+
// we also support the anthropic headers without the x-${POWERED_BY}- prefix for claude code support
960963
const anthropicConfig = {
961-
anthropicBeta: requestHeaders[`x-${POWERED_BY}-anthropic-beta`],
962-
anthropicVersion: requestHeaders[`x-${POWERED_BY}-anthropic-version`],
964+
anthropicBeta:
965+
requestHeaders[`x-${POWERED_BY}-anthropic-beta`] ||
966+
requestHeaders[`anthropic-beta`],
967+
anthropicVersion:
968+
requestHeaders[`x-${POWERED_BY}-anthropic-version`] ||
969+
requestHeaders[`anthropic-version`],
970+
anthropicApiKey: requestHeaders[`x-api-key`],
963971
};
964972

965973
const vertexServiceAccountJson =

src/providers/anthropic/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const AnthropicAPIConfig: ProviderAPIConfig = {
1010
gatewayRequestBody,
1111
}) => {
1212
const apiKey =
13-
providerOptions.apiKey || requestHeaders?.['x-api-key'] || '';
13+
providerOptions.apiKey || providerOptions.anthropicApiKey || '';
1414
const headers: Record<string, string> = {
1515
'X-API-Key': apiKey,
1616
};

src/types/requestBody.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export interface Options {
152152
/** Anthropic specific headers */
153153
anthropicBeta?: string;
154154
anthropicVersion?: string;
155+
anthropicApiKey?: string;
155156

156157
/** Fireworks finetune required fields */
157158
fireworksAccountId?: string;

0 commit comments

Comments
 (0)