Skip to content
Closed
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
95 changes: 89 additions & 6 deletions src/api/providers/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,47 +254,112 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
// Helper to guess model info from custom modelId string if not in bedrockModels
private guessModelInfoFromId(modelId: string): Partial<ModelInfo> {
// Define a mapping for model ID patterns and their configurations
// Order matters - more specific patterns should come first
const modelConfigMap: Record<string, Partial<ModelInfo>> = {
"claude-4": {
// Claude 4.5 Sonnet (most specific)
"claude-sonnet-4-5": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
supportsReasoningBudget: true,
},
"claude-3-7": {
// Claude 4 Sonnet
"claude-sonnet-4": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
supportsReasoningBudget: true,
},
"claude-3-5": {
// Claude 4 Opus
"claude-opus-4": {
Copy link
Author

Choose a reason for hiding this comment

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

P1: Pattern typo prevents detection of Claude 4 Opus; Anthropic naming uses 'claude-4-opus'. This key won't match real IDs like '...claude-4-opus-...'.

Suggested change
"claude-opus-4": {
"claude-4-opus": {

maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
supportsReasoningBudget: true,
},
"claude-4-opus": {
maxTokens: 4096,
// Claude 3.7 Sonnet
"claude-3-7-sonnet": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
supportsReasoningBudget: true,
},
// Claude 3.5 Sonnet
"claude-3-5-sonnet": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
},
// Claude 3.5 Haiku
"claude-3-5-haiku": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: false,
supportsPromptCache: true,
},
// Claude 3 Opus
"claude-3-opus": {
maxTokens: 4096,
contextWindow: 200_000,
supportsImages: true,
supportsPromptCache: true,
supportsPromptCache: false,
},
// Claude 3 Sonnet
"claude-3-sonnet": {
maxTokens: 4096,
contextWindow: 200_000,
supportsImages: true,
supportsPromptCache: false,
},
// Claude 3 Haiku
"claude-3-haiku": {
maxTokens: 4096,
contextWindow: 200_000,
supportsImages: true,
supportsPromptCache: false,
},
// Generic Claude 4 (fallback for any Claude 4 variant)
"claude-4": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
supportsReasoningBudget: true,
},
// Generic Claude 3.7
"claude-3-7": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
supportsReasoningBudget: true,
},
// Generic Claude 3.5
"claude-3-5": {
maxTokens: 8192,
contextWindow: 200_000,
supportsImages: true,
supportsComputerUse: true,
supportsPromptCache: true,
},
}

// Match the model ID to a configuration
const id = modelId.toLowerCase()

// Check patterns in order (more specific first)
for (const [pattern, config] of Object.entries(modelConfigMap)) {
if (id.includes(pattern)) {
return config
Expand Down Expand Up @@ -885,6 +950,24 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
}
}

// Also handle additional regional prefixes that might not be in the mapping
// These are commonly used in cross-region inference IDs
const additionalRegionalPrefixes = [
"au.", // Australia (e.g., au.anthropic.claude-sonnet-4-5-20250929-v1:0)
"af.", // Africa
"me.", // Middle East
"il.", // Israel
"cn.", // China
"jp.", // Japan (alternative to ap-)
Copy link
Author

Choose a reason for hiding this comment

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

P2: Unverified regional prefix 'jp.' may not be a documented AWS inference profile prefix; stripping it could inadvertently mangle legitimate model IDs. Recommend relying on AWS_INFERENCE_PROFILE_MAPPING or adding tests/docs reference before introducing new prefixes.

]

for (const prefix of additionalRegionalPrefixes) {
if (modelId.startsWith(prefix)) {
// Remove the regional prefix from the model ID
return modelId.substring(prefix.length)
}
}

// Return the model ID as-is for all other cases
return modelId
}
Expand Down