feat(bedrock): make default model region-aware based on AWS_REGION#664
Open
feat(bedrock): make default model region-aware based on AWS_REGION#664
Conversation
Move resolveBedrockModelId and helpers from providers.ts to provider-meta.ts so getDefaultModelId can resolve the correct region prefix (us./eu./ap.) for the default Bedrock model. - getDefaultModelId now accepts an optional region parameter - Falls back to process.env.AWS_REGION when no explicit region is given - Backend callers pass the project config region where available - Runtime model resolution in create() still rewrites as before Co-authored-by: Christophe Blefari <christophe.blefari@gmail.com>
Contributor
🚀 Preview Deployment
Preview will be automatically removed when this PR is closed. |
Co-authored-by: Christophe Blefari <christophe.blefari@gmail.com>
Contributor
There was a problem hiding this comment.
2 issues found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/backend/src/agents/provider-meta.ts">
<violation number="1" location="apps/backend/src/agents/provider-meta.ts:318">
P1: Avoid direct `process.env` access in this frontend-consumed helper; it can crash Bedrock settings UI in the browser when no region argument is passed.</violation>
</file>
<file name="apps/backend/src/utils/llm.ts">
<violation number="1" location="apps/backend/src/utils/llm.ts:180">
P2: Region-aware Bedrock defaults should not be emitted here unless the model metadata table also includes those regional IDs; otherwise the UI and cost/context lookups lose metadata for EU/AP defaults.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| return defaultModel?.id ?? models[0]?.id ?? ''; | ||
| const modelId = defaultModel?.id ?? models[0]?.id ?? ''; | ||
| if (provider === 'bedrock') { | ||
| const effectiveRegion = region ?? process.env.AWS_REGION; |
Contributor
There was a problem hiding this comment.
P1: Avoid direct process.env access in this frontend-consumed helper; it can crash Bedrock settings UI in the browser when no region argument is passed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/backend/src/agents/provider-meta.ts, line 318:
<comment>Avoid direct `process.env` access in this frontend-consumed helper; it can crash Bedrock settings UI in the browser when no region argument is passed.</comment>
<file context>
@@ -310,10 +310,17 @@ export const PROVIDER_META: ProviderMetaMap = {
- return defaultModel?.id ?? models[0]?.id ?? '';
+ const modelId = defaultModel?.id ?? models[0]?.id ?? '';
+ if (provider === 'bedrock') {
+ const effectiveRegion = region ?? process.env.AWS_REGION;
+ if (effectiveRegion) {
+ return resolveBedrockModelId(modelId, effectiveRegion);
</file context>
Suggested change
| const effectiveRegion = region ?? process.env.AWS_REGION; | |
| const effectiveRegion = region ?? (typeof process !== 'undefined' ? process.env.AWS_REGION : undefined); |
| // If no models explicitly enabled, add the default | ||
| const defaultModelId = getDefaultModelId(provider); | ||
| const region = (config.credentials as Record<string, string> | null)?.region; | ||
| const defaultModelId = getDefaultModelId(provider, region); |
Contributor
There was a problem hiding this comment.
P2: Region-aware Bedrock defaults should not be emitted here unless the model metadata table also includes those regional IDs; otherwise the UI and cost/context lookups lose metadata for EU/AP defaults.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/backend/src/utils/llm.ts, line 180:
<comment>Region-aware Bedrock defaults should not be emitted here unless the model metadata table also includes those regional IDs; otherwise the UI and cost/context lookups lose metadata for EU/AP defaults.</comment>
<file context>
@@ -176,8 +176,8 @@ export const getProjectAvailableModels = async (
- // If no models explicitly enabled, add the default
- const defaultModelId = getDefaultModelId(provider);
+ const region = (config.credentials as Record<string, string> | null)?.region;
+ const defaultModelId = getDefaultModelId(provider, region);
models.push({ provider, modelId: defaultModelId, name: getModelName(provider, defaultModelId) });
} else {
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The default Bedrock model (
us.anthropic.claude-sonnet-4-6) was hardcoded with aus.prefix. When users configureAWS_REGIONto an EU or AP region (e.g.eu-west-1,ap-southeast-1), the default model ID still used theus.prefix, which doesn't work for cross-region inference.While
resolveBedrockModelIdinproviders.tsalready handled rewriting model IDs at inference time,getDefaultModelId(used for fallback model selection, UI display, and project config initialization) always returned the rawus.prefixed ID.Solution
resolveBedrockModelId,getBedrockRegionPrefix, andBEDROCK_REGION_PREFIXESfromproviders.tstoprovider-meta.ts(no SDK imports — stays frontend-safe)getDefaultModelIdnow accepts an optionalregionparameter and resolves the correct geographic prefix (us./eu./ap.) for Bedrock modelsprocess.env.AWS_REGIONagent.ts,llm.ts,project-llm-config.queries.ts) to pass the project config region where availableHow it works
AWS_REGION=eu-west-1, no explicit regionus.anthropic.claude-sonnet-4-6eu.anthropic.claude-sonnet-4-6AWS_REGION=ap-southeast-1us.anthropic.claude-sonnet-4-6ap.anthropic.claude-sonnet-4-6AWS_REGION=us-east-1or unsetus.anthropic.claude-sonnet-4-6us.anthropic.claude-sonnet-4-6(unchanged)region: 'eu-central-1'us.anthropic.claude-sonnet-4-6eu.anthropic.claude-sonnet-4-6Files changed
apps/backend/src/agents/provider-meta.ts— added Bedrock region helpers and region-awaregetDefaultModelIdapps/backend/src/agents/providers.ts— removed duplicate helpers, re-exports fromprovider-meta.tsapps/backend/src/services/agent.ts— passes project config region togetDefaultModelIdapps/backend/src/utils/llm.ts— passes project config region togetDefaultModelIdapps/backend/src/queries/project-llm-config.queries.ts— passes project config region to fallback model lookup