Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 1 addition & 6 deletions src/providers/anthropic/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { ProviderAPIConfig } from '../types';
const AnthropicAPIConfig: ProviderAPIConfig = {
getBaseURL: () => 'https://api.anthropic.com/v1',

headers: ({
providerOptions,
fn,
headers: requestHeaders,
gatewayRequestBody,
}) => {
headers: ({ providerOptions, fn, gatewayRequestBody }) => {
const apiKey =
providerOptions.apiKey || providerOptions.anthropicApiKey || '';
const headers: Record<string, string> = {
Expand Down
8 changes: 6 additions & 2 deletions src/providers/bedrock/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
generateAWSHeaders,
getFoundationModelFromInferenceProfile,
providerAssumedRoleCredentials,
getBedrockModelWithoutRegion,
} from './utils';
import { GatewayError } from '../../errors/GatewayError';

Expand Down Expand Up @@ -234,7 +235,10 @@ const BedrockAPIConfig: BedrockAPIConfigInterface = {
return `/model-invocation-job/${batchId}/stop`;
}
const { model, stream } = gatewayRequestBody;
const uriEncodedModel = encodeURIComponent(decodeURIComponent(model ?? ''));
const decodedModel = decodeURIComponent(model ?? '');
const uriEncodedModel = encodeURIComponent(decodedModel);
const modelWithoutRegion = getBedrockModelWithoutRegion(decodedModel);
const uriEncodedModelWithoutRegion = encodeURIComponent(modelWithoutRegion);
if (!model && !BEDROCK_NO_MODEL_ENDPOINTS.includes(fn as endpointStrings)) {
throw new GatewayError('Model is required');
}
Expand Down Expand Up @@ -305,7 +309,7 @@ const BedrockAPIConfig: BedrockAPIConfigInterface = {
return `/model-customization-jobs/${jobId}/stop`;
}
case 'messagesCountTokens': {
return `/model/${uriEncodedModel}/count-tokens`;
return `/model/${uriEncodedModelWithoutRegion}/count-tokens`;
}
default:
return '';
Expand Down
3 changes: 2 additions & 1 deletion src/providers/bedrock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {
BedrockConverseMessageCountTokensConfig,
BedrockConverseMessageCountTokensResponseTransform,
} from './countTokens';
import { getBedrockModelWithoutRegion } from './utils';

const BedrockConfig: ProviderConfigs = {
api: BedrockAPIConfig,
Expand All @@ -101,7 +102,7 @@ const BedrockConfig: ProviderConfigs = {

if (params.model) {
let providerModel = providerOptions.foundationModel || params.model;
providerModel = providerModel.replace(/^(us\.|eu\.|apac\.)/, '');
providerModel = getBedrockModelWithoutRegion(providerModel);
const providerModelArray = providerModel?.split('.');
const provider = providerModelArray?.[0];
const model = providerModelArray?.slice(1).join('.');
Expand Down
4 changes: 4 additions & 0 deletions src/providers/bedrock/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,7 @@ export const getBedrockErrorChunk = (id: string, model: string) => {
`data: [DONE]\n\n`,
];
};

export const getBedrockModelWithoutRegion = (model: string) => {
return model.replace(/^(us\.|eu\.|apac\.|au\.|ca\.|jp\.|global\.)/, '');
};