Skip to content

Commit

Permalink
fix: forwardHeaders logic
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Jan 8, 2025
1 parent 59ab7b7 commit bd93ef2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/_types/generalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ApiClientInterface {
anthropicBeta?: string | null | undefined;
anthropicVersion?: string | null | undefined;
mistralFimCompletion?: string | null | undefined;
[key: string]: any;
}

export interface APIResponseType {
Expand Down
16 changes: 15 additions & 1 deletion src/apis/createHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ export const createHeaders = (
config: Record<string, any>
): Record<string, string> => {
const headers: Record<string, string> = {};
let forwardHeaders: string[] = [];

if (config['forwardHeaders']) {
// logic to convert forwardHeaders values to kebab-case
forwardHeaders = config['forwardHeaders'].map((header: string) => {
return header
.replace('ID', 'Id')
.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
});
}

for (let k in config) {
let v = config[k];
Expand Down Expand Up @@ -31,7 +41,11 @@ export const createHeaders = (
if (!isEmpty(v) && typeof v == 'object') {
v = JSON.stringify(v);
}
headers[getPortkeyHeader(k)] = v || '';
if (forwardHeaders && forwardHeaders.includes(k)) {
headers[k] = v || '';
} else {
headers[getPortkeyHeader(k)] = v || '';
}
}
return headers;
};
2 changes: 2 additions & 0 deletions src/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export abstract class ApiClient {
anthropicBeta,
anthropicVersion,
mistralFimCompletion,
...rest
}: ApiClientInterface) {
this.apiKey = apiKey ?? '';
this.baseURL = baseURL ?? '';
Expand Down Expand Up @@ -205,6 +206,7 @@ export abstract class ApiClient {
anthropicVersion,
mistralFimCompletion,
anthropicBeta,
...rest,
});
this.portkeyHeaders = this.defaultHeaders();
this.fetch = fetch;
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class Portkey extends ApiClient {
anthropicBeta,
anthropicVersion,
mistralFimCompletion,
...rest
}: ApiClientInterface) {
super({
apiKey,
Expand Down Expand Up @@ -105,6 +106,7 @@ export class Portkey extends ApiClient {
anthropicBeta,
anthropicVersion,
mistralFimCompletion,
...rest,
});
this.baseURL = setBaseURL(baseURL, apiKey);
this.apiKey = setApiKey(this.baseURL, apiKey);
Expand Down

0 comments on commit bd93ef2

Please sign in to comment.