Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const UPSTAGE: string = 'upstage';
export const LAMBDA: string = 'lambda';
export const DASHSCOPE: string = 'dashscope';
export const X_AI: string = 'x-ai';
export const CORTEX: string = 'cortex';
export const SAGEMAKER: string = 'sagemaker';
export const NEBIUS: string = 'nebius';
export const RECRAFTAI: string = 'recraft-ai';
Expand Down Expand Up @@ -129,6 +130,7 @@ export const VALID_PROVIDERS = [
LAMBDA,
DASHSCOPE,
X_AI,
CORTEX,
SAGEMAKER,
NEBIUS,
RECRAFTAI,
Expand Down
14 changes: 14 additions & 0 deletions src/handlers/handlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
STABILITY_AI,
SAGEMAKER,
FIREWORKS_AI,
CORTEX,
} from '../globals';
import Providers from '../providers';
import {
Expand Down Expand Up @@ -1030,6 +1031,11 @@ export function constructConfigFromRequestHeaders(
}
}

const cortexConfig = {
snowflakeAccount: requestHeaders[`x-${POWERED_BY}-snowflake-account`],
snowflakeApiKey: requestHeaders[`x-${POWERED_BY}-snowflake-api-key`],
};

if (requestHeaders[`x-${POWERED_BY}-config`]) {
let parsedConfigJson = JSON.parse(requestHeaders[`x-${POWERED_BY}-config`]);

Expand Down Expand Up @@ -1117,6 +1123,13 @@ export function constructConfigFromRequestHeaders(
...stabilityAiConfig,
};
}

if (parsedConfigJson.provider === CORTEX) {
parsedConfigJson = {
...parsedConfigJson,
...cortexConfig,
};
}
}
return convertKeysToCamelCase(parsedConfigJson, [
'override_params',
Expand Down Expand Up @@ -1157,6 +1170,7 @@ export function constructConfigFromRequestHeaders(
stabilityAiConfig),
...(requestHeaders[`x-${POWERED_BY}-provider`] === FIREWORKS_AI &&
fireworksConfig),
...(requestHeaders[`x-${POWERED_BY}-provider`] === CORTEX && cortexConfig),
};
}

Expand Down
22 changes: 22 additions & 0 deletions src/providers/cortex/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ProviderAPIConfig } from '../types';

const CortexAPIConfig: ProviderAPIConfig = {
getBaseURL: ({ providerOptions }) =>
`https://${(providerOptions as any).snowflakeAccount}.snowflakecomputing.com/api/v2`,
headers: ({ providerOptions }) => ({
'X-Snowflake-Authorization-Token-Type': 'KEYPAIR_JWT',
Authorization: `Bearer ${(providerOptions as any).snowflakeApiKey || providerOptions.apiKey}`,
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream',
}),
getEndpoint: ({ fn }) => {
switch (fn) {
case 'chatComplete':
return '/cortex/inference:complete';
default:
return '';
}
},
};

export default CortexAPIConfig;
23 changes: 23 additions & 0 deletions src/providers/cortex/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ProviderConfigs } from '../types';
import CortexAPIConfig from './api';
import { CORTEX } from '../../globals';
import {
chatCompleteParams,
completeParams,
embedParams,
responseTransformers,
} from '../open-ai-base';

const CortexConfig: ProviderConfigs = {
chatComplete: chatCompleteParams([], { model: 'mistral-large' }),
complete: completeParams([], { model: 'mistral-large' }),
embed: embedParams([], { model: 'mistral-large' }),
api: CortexAPIConfig,
responseTransforms: responseTransformers(CORTEX, {
chatComplete: true,
complete: true,
embed: true,
}),
};

export default CortexConfig;
4 changes: 4 additions & 0 deletions src/types/requestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export interface Options {

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

/** Cortex specific fields */
snowflakeAccount?: string;
snowflakeApiKey?: string;
Copy link
Collaborator

@narengogi narengogi Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove snowflakeApiKey and any references to it, the gateway standardizes using providerOptions.apiKey for the authorization header which is passed with x-portkey-api-key header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed api key

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also remove it from here?

const cortexConfig = {
    snowflakeAccount: requestHeaders[`x-${POWERED_BY}-snowflake-account`],
    snowflakeApiKey: requestHeaders[`x-${POWERED_BY}-snowflake-api-key`],
  };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed snowflakeApiKey from cortexConfig.

}

/**
Expand Down