Skip to content

feat(bedrock): make default model region-aware based on AWS_REGION#664

Open
Bl3f wants to merge 2 commits intomainfrom
cursor/bedrock-region-default-model-cc25
Open

feat(bedrock): make default model region-aware based on AWS_REGION#664
Bl3f wants to merge 2 commits intomainfrom
cursor/bedrock-region-default-model-cc25

Conversation

@Bl3f
Copy link
Copy Markdown
Contributor

@Bl3f Bl3f commented Apr 23, 2026

Problem

The default Bedrock model (us.anthropic.claude-sonnet-4-6) was hardcoded with a us. prefix. When users configure AWS_REGION to an EU or AP region (e.g. eu-west-1, ap-southeast-1), the default model ID still used the us. prefix, which doesn't work for cross-region inference.

While resolveBedrockModelId in providers.ts already handled rewriting model IDs at inference time, getDefaultModelId (used for fallback model selection, UI display, and project config initialization) always returned the raw us. prefixed ID.

Solution

  • Moved resolveBedrockModelId, getBedrockRegionPrefix, and BEDROCK_REGION_PREFIXES from providers.ts to provider-meta.ts (no SDK imports — stays frontend-safe)
  • getDefaultModelId now accepts an optional region parameter and resolves the correct geographic prefix (us./eu./ap.) for Bedrock models
  • When no explicit region is passed, falls back to process.env.AWS_REGION
  • Updated backend callers (agent.ts, llm.ts, project-llm-config.queries.ts) to pass the project config region where available

How it works

Scenario Before After
AWS_REGION=eu-west-1, no explicit region us.anthropic.claude-sonnet-4-6 eu.anthropic.claude-sonnet-4-6
AWS_REGION=ap-southeast-1 us.anthropic.claude-sonnet-4-6 ap.anthropic.claude-sonnet-4-6
AWS_REGION=us-east-1 or unset us.anthropic.claude-sonnet-4-6 us.anthropic.claude-sonnet-4-6 (unchanged)
Project config with region: 'eu-central-1' us.anthropic.claude-sonnet-4-6 eu.anthropic.claude-sonnet-4-6

Files changed

  • apps/backend/src/agents/provider-meta.ts — added Bedrock region helpers and region-aware getDefaultModelId
  • apps/backend/src/agents/providers.ts — removed duplicate helpers, re-exports from provider-meta.ts
  • apps/backend/src/services/agent.ts — passes project config region to getDefaultModelId
  • apps/backend/src/utils/llm.ts — passes project config region to getDefaultModelId
  • apps/backend/src/queries/project-llm-config.queries.ts — passes project config region to fallback model lookup
Open in Web Open in Cursor 

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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

🚀 Preview Deployment

URL https://pr-664-082a9a1.preview.getnao.io
Commit 082a9a1

⚠️ No LLM API keys configured - you'll see the API key setup flow when trying to chat.


Preview will be automatically removed when this PR is closed.

Co-authored-by: Christophe Blefari <christophe.blefari@gmail.com>
@Bl3f Bl3f marked this pull request as ready for review April 23, 2026 17:34
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 23, 2026

Choose a reason for hiding this comment

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

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);
Fix with Cubic

// 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);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 23, 2026

Choose a reason for hiding this comment

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

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>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants