Skip to content

feat(aws-bedrock): region routing with global default - #2344

Merged
steebchen merged 17 commits into
mainfrom
aws-bedrock-region-routing
May 31, 2026
Merged

steebchen merged 17 commits into
mainfrom
aws-bedrock-region-routing

Conversation

@steebchen

@steebchen steebchen commented May 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Add region-specific routing for AWS Bedrock, modeled on Alibaba's regionConfig pattern. The four regions correspond to AWS cross-region inference profile groups (global, us, eu, apac) — not individual AWS regions. global is the default and uses the cross-region inference profile (global. model-ID prefix) routed through the us-east-1 endpoint, which is the cheapest, most-available choice and works out of the box with any existing AWS Bedrock long-term API key.

claude-haiku-4-5 opts in via regions: [{ id: "global" }, { id: "us" }, { id: "eu" }, { id: "apac" }]. Other AWS Bedrock models are untouched and continue to use the existing single-endpoint path.

GCP / Vertex follows in a separate PR.

Notes

  • Extends ProviderRegionConfig with an optional modelPrefixMap so providers like Bedrock can have a region-dependent model-ID prefix in addition to a region-dependent endpoint URL.
  • Endpoint resolver precedence: explicit aws_bedrock_region_prefix provider-key option > region-derived prefix > env var > "global.". Existing keys with the legacy prefix option keep working.
  • AWS Bedrock long-term API keys are IAM-global; AWS auto-enables models on first invocation per region, so no per-region BYOK rows or env-var fallbacks are needed.
  • Replaced the legacy "Region Prefix" select in the provider-key create dialog with the generic regionConfig dropdown (now reachable via aws_bedrock_region).

Test plan

  • Unit tests in get-provider-endpoint.spec.ts covering global default, eu/us/apac routing, streaming variant, and provider-key prefix override
  • pnpm build (17/17 tasks)
  • pnpm format
  • Manual: hit gateway locally with claude-haiku-4-5 and claude-haiku-4-5:eu after pnpm setup

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added APAC as an AWS Bedrock region option and expanded selectable regions.
  • Improvements

    • Replaced Bedrock-specific region prefix input with a unified region field; label updated to "Cross-Region Prefix".
    • Endpoint routing now prefers region-specific bases and applies region-derived model prefixes.
    • Model selector and favorites are region-aware and emit region-suffixed identifiers.
  • Tests

    • Added tests validating Bedrock endpoint/routing across regions.

Review Change Stack

Add `regionConfig` (global/us/eu/apac) on the aws-bedrock provider with
a `modelPrefixMap` so the cross-region inference profile prefix is
derived from the selected region. `claude-haiku-4-5` opts in via
`regions`; default stays global (us-east-1 endpoint + `global.` prefix).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 12:19
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds AWS Bedrock multi-region support (coarse and specific regions including apac), region-configured endpoints and model-prefix mapping, updates endpoint resolution and tests, removes the UI's manual Bedrock prefix input, makes model selectors region-aware, and pins default regions in routing.

Changes

AWS Bedrock Multi-Region Configuration and Routing

Layer / File(s) Summary
Provider Configuration and Model Metadata
packages/models/src/providers.ts, packages/models/src/models/anthropic.ts, packages/db/src/schema.ts
ProviderRegionConfig adds optional modelPrefixMap. aws-bedrock regionConfig now contains optionsKey, defaultRegion, pinDefaultRegion, coarse and specific regions, endpointMap, and modelPrefixMap. Anthropic model metadata lists supported regions. DB schema replaces aws_bedrock_region_prefix with aws_bedrock_region (adds apac and explicit AWS regions).
Endpoint Resolution and Tests
packages/actions/src/get-provider-endpoint.ts, packages/actions/src/get-provider-endpoint.spec.ts
getProviderEndpoint prefers a region-specific regionBaseUrl when region is provided and computes model path prefixes from modelPrefixMap with fallback to options/env. Tests added for default behavior, coarse-region aliases (eu, apac, us), explicit AWS region routing (data residency), and prefix override.
Provider Key Request/Response Schemas
apps/api/src/routes/keys-provider.ts
providerKeySchema and createProviderKeySchema now accept apac in options.aws_bedrock_region.
UI Cleanup – Remove Manual Prefix Input
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx, apps/ui/src/components/provider-keys/provider-keys-list.tsx
Removed awsBedrockRegionPrefix state and related payload/reset/UI selector; updated formatOptionLabel to show “Cross-Region Prefix” for the legacy prefix option key.
Playground / Model Selector Region Keys
apps/playground/src/components/model-selector.tsx, apps/ui/src/components/models/playground-model-selector.tsx
Model entries and selectors now emit and parse region-aware keys using the provider/modelId:region format; selection, favorites, and mapping lookup updated to prefer provider+region mappings with fallback.
Gateway: Pin Default Regions in Routing
apps/gateway/src/chat/chat.ts
Introduced applyPinnedDefaultRegions() and applied it to auto-routing and multiple fallback/selection paths so providers with pinDefaultRegion only expose their defaultRegion candidates unless an explicit/requested region or explicit locks are present.

Sequence Diagram (high-level flow)

sequenceDiagram
  participant UI as Playground / ProviderKey Dialog
  participant API as Gateway / Keys API
  participant Resolver as getProviderEndpoint
  participant Bedrock as AWS Bedrock Runtime
  UI->>API: submit key or request model runtime (with region)
  API->>Resolver: resolve endpoint for aws-bedrock (region)
  Resolver->>Resolver: pick regionBaseUrl, compute modelPrefix from modelPrefixMap/options
  Resolver->>Bedrock: request (region-specific hostname + model path with prefix)
  Bedrock-->>Resolver: response
  Resolver-->>API: resolved runtime URL
  API-->>UI: runtime info / success
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • theopenco/llmgateway#2412: Related edits to playground model selector parsing/selection to handle region-suffixed model identifiers.

Suggested reviewers

  • smakosh
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: AWS Bedrock now supports region-specific routing with a global default configuration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aws-bedrock-region-routing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/src/routes/keys-provider.ts`:
- Around line 31-33: The Zod schema for aws_bedrock_region_prefix currently
lists only ["us.", "global.", "eu."] but aws_bedrock_region accepts "apac", so
update both schema objects that define aws_bedrock_region_prefix to include
"apac." in the z.enum array (i.e., add "apac." alongside "us.", "global.", and
"eu.") so explicit APAC prefix overrides pass validation; ensure you modify both
occurrences of the aws_bedrock_region_prefix enum.

In `@packages/db/src/schema.ts`:
- Around line 577-578: The aws_bedrock_region_prefix union
(aws_bedrock_region_prefix) is missing the "apac." variant while
aws_bedrock_region supports "apac"; update the aws_bedrock_region_prefix type to
include "apac." so the explicit prefix override can select APAC (i.e., add
"apac." to the union alongside "us.", "global.", and "eu."). Ensure the change
is applied where aws_bedrock_region_prefix is declared to keep the two types
consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6807339f-ec81-4b64-ae01-e5a48b7367e4

📥 Commits

Reviewing files that changed from the base of the PR and between 1146e11 and a17b15f.

⛔ Files ignored due to path filters (4)
  • apps/code/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/playground/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/ui/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • ee/admin/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
📒 Files selected for processing (8)
  • apps/api/src/routes/keys-provider.ts
  • apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
  • apps/ui/src/components/provider-keys/provider-keys-list.tsx
  • packages/actions/src/get-provider-endpoint.spec.ts
  • packages/actions/src/get-provider-endpoint.ts
  • packages/db/src/schema.ts
  • packages/models/src/models/anthropic.ts
  • packages/models/src/providers.ts
💤 Files with no reviewable changes (1)
  • apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx

Comment thread apps/api/src/routes/keys-provider.ts Outdated
Comment thread packages/db/src/schema.ts Outdated
Comment on lines +577 to +578
aws_bedrock_region_prefix?: "us." | "global." | "eu.";
aws_bedrock_region?: "global" | "us" | "eu" | "apac";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add apac. to aws_bedrock_region_prefix union for consistency.

With aws_bedrock_region now supporting "apac", the explicit override type should also allow "apac."; otherwise APAC cannot be explicitly selected via prefix override even though routing supports it.

Suggested patch
 export interface ProviderKeyOptions {
-	aws_bedrock_region_prefix?: "us." | "global." | "eu.";
+	aws_bedrock_region_prefix?: "us." | "global." | "eu." | "apac.";
 	aws_bedrock_region?: "global" | "us" | "eu" | "apac";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
aws_bedrock_region_prefix?: "us." | "global." | "eu.";
aws_bedrock_region?: "global" | "us" | "eu" | "apac";
aws_bedrock_region_prefix?: "us." | "global." | "eu." | "apac.";
aws_bedrock_region?: "global" | "us" | "eu" | "apac";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/db/src/schema.ts` around lines 577 - 578, The
aws_bedrock_region_prefix union (aws_bedrock_region_prefix) is missing the
"apac." variant while aws_bedrock_region supports "apac"; update the
aws_bedrock_region_prefix type to include "apac." so the explicit prefix
override can select APAC (i.e., add "apac." to the union alongside "us.",
"global.", and "eu."). Ensure the change is applied where
aws_bedrock_region_prefix is declared to keep the two types consistent.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds region-group routing support for AWS Bedrock (global/us/eu/apac) using the existing regionConfig pattern, with global as the default and region-dependent model prefixing for cross-region inference profiles.

Changes:

  • Extend provider region configuration to optionally include a per-region model-id prefix map (modelPrefixMap).
  • Add AWS Bedrock regionConfig (endpoint + prefix mapping) and opt claude-haiku-4-5 into multi-region availability.
  • Plumb aws_bedrock_region through DB/API/UI and add unit tests for Bedrock region routing.

Reviewed changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/models/src/providers.ts Extends ProviderRegionConfig with modelPrefixMap; defines Bedrock region routing config.
packages/models/src/models/anthropic.ts Opts the Bedrock mapping for claude-haiku-4-5 into global/us/eu/apac regions.
packages/db/src/schema.ts Adds aws_bedrock_region to provider key options typings.
packages/actions/src/get-provider-endpoint.ts Uses provider regionConfig endpoint map for Bedrock base URL and applies region-derived model prefixing.
packages/actions/src/get-provider-endpoint.spec.ts Adds unit coverage for Bedrock default + per-region routing and prefix override precedence.
apps/api/src/routes/keys-provider.ts Accepts/returns aws_bedrock_region in provider key create/list schemas.
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx Removes Bedrock-specific prefix selector; uses generic region selector via regionConfig.
apps/ui/src/components/provider-keys/provider-keys-list.tsx Adds display label for aws_bedrock_region and clarifies legacy prefix label.
ee/admin/src/lib/api/v1.d.ts Updates generated API types to include aws_bedrock_region.
apps/ui/src/lib/api/v1.d.ts Updates generated API types to include aws_bedrock_region.
apps/playground/src/lib/api/v1.d.ts Updates generated API types to include aws_bedrock_region.
apps/code/src/lib/api/v1.d.ts Updates generated API types to include aws_bedrock_region.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +252 to +260
case "aws-bedrock":
url =
regionBaseUrl ??
envValueOrDefault(
"aws-bedrock",
"baseUrl",
"https://bedrock-runtime.us-east-1.amazonaws.com",
) ?? "https://bedrock-runtime.us-east-1.amazonaws.com";
) ??
"https://bedrock-runtime.us-east-1.amazonaws.com";
Comment on lines 433 to 436
const prefix =
providerKeyOptions?.aws_bedrock_region_prefix ??
awsRegionPrefix ??
getProviderEnvValue("aws-bedrock", "region", configIndex, "global.") ??
Comment thread packages/db/src/schema.ts Outdated
@@ -575,6 +575,7 @@ export const masterKey = pgTable(

export interface ProviderKeyOptions {
aws_bedrock_region_prefix?: "us." | "global." | "eu.";
Comment thread apps/api/src/routes/keys-provider.ts Outdated
@@ -29,6 +29,7 @@ const providerKeySchema = z.object({
options: z
.object({
aws_bedrock_region_prefix: z.enum(["us.", "global.", "eu."]).optional(),

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a17b15fabb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 254 to 258
regionBaseUrl ??
envValueOrDefault(
"aws-bedrock",
"baseUrl",
"https://bedrock-runtime.us-east-1.amazonaws.com",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve explicit Bedrock base URL when region is set

The new regionBaseUrl ?? envValueOrDefault(...) order causes any regional Bedrock request to ignore an explicitly configured Bedrock base URL (for example LLM_AWS_BEDROCK_BASE_URL in credits/hybrid mode). Before this change, that explicit URL always won; now a :eu/:apac request is forced to the hardcoded AWS endpoint, which can bypass required proxies/private endpoints and break otherwise working deployments. Keep explicit base URL config precedence above derived regional endpoints.

Useful? React with 👍 / 👎.

Comment thread apps/api/src/routes/keys-provider.ts Outdated
@@ -69,6 +70,7 @@ const createProviderKeySchema = z.object({
options: z
.object({
aws_bedrock_region_prefix: z.enum(["us.", "global.", "eu."]).optional(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Allow APAC in Bedrock prefix override schema

After adding APAC regional routing (modelPrefixMap.apac = "apac."), the API schema still rejects aws_bedrock_region_prefix: "apac." because the enum only allows "us." | "global." | "eu.". That blocks clients from using the explicit prefix-override path for APAC and makes the override behavior inconsistent with the newly supported region set. Include "apac." in the Bedrock prefix enum (and matching types) to avoid 400s for valid APAC overrides.

Useful? React with 👍 / 👎.

Extend the aws-bedrock regionConfig with eight specific AWS regions
(us-east-1/2, us-west-2, eu-central-1, eu-west-1, ap-northeast-1,
ap-southeast-1/2). When a specific region is selected the model is
invoked with the bare model ID (no inference profile prefix) routed
directly to that region's endpoint, giving true single-region
residency for models that support direct invocation. Inference-
profile groups (global/us/eu/apac) remain the default for models
that require cross-region inference.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/actions/src/get-provider-endpoint.spec.ts (1)

496-536: ⚡ Quick win

Add one non-skipEnvVars regression test for specific-region no-prefix behavior

These new tests only exercise BYOK mode. Add a case with env-var fallback enabled and a non-empty Bedrock prefix env configured, then assert a specific region (e.g. us-east-2) still uses the bare model ID. That directly guards the empty-string short-circuit behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/actions/src/get-provider-endpoint.spec.ts` around lines 496 - 536,
Add a regression test to ensure getProviderEndpoint still uses the bare model ID
for specific-region routing when env-var fallback (skipEnvVars=false) and a
non-empty Bedrock prefix env is set: create a new it(...) case calling
getProviderEndpoint with provider "aws-bedrock", skipEnvVars false (or undefined
to enable env fallback), a non-empty bedrock prefix env configured, region
"us-east-2" (or another specific region), and expect the returned URL to contain
the raw model ID (no prefix) and the correct path (converse or converse-stream
depending on the EU flag). Locate and mirror the existing test structure around
get-provider-endpoint.spec.ts tests that call getProviderEndpoint so the new
test targets the same behaviors (model string like "anthropic.claude-...:0",
region "us-east-2", and dataResidency flag) to guard the empty-string
short-circuit logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/actions/src/get-provider-endpoint.spec.ts`:
- Around line 496-536: Add a regression test to ensure getProviderEndpoint still
uses the bare model ID for specific-region routing when env-var fallback
(skipEnvVars=false) and a non-empty Bedrock prefix env is set: create a new
it(...) case calling getProviderEndpoint with provider "aws-bedrock",
skipEnvVars false (or undefined to enable env fallback), a non-empty bedrock
prefix env configured, region "us-east-2" (or another specific region), and
expect the returned URL to contain the raw model ID (no prefix) and the correct
path (converse or converse-stream depending on the EU flag). Locate and mirror
the existing test structure around get-provider-endpoint.spec.ts tests that call
getProviderEndpoint so the new test targets the same behaviors (model string
like "anthropic.claude-...:0", region "us-east-2", and dataResidency flag) to
guard the empty-string short-circuit logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c016daa4-de5d-46c9-a2f7-ae9cf673cb7b

📥 Commits

Reviewing files that changed from the base of the PR and between a17b15f and 30ee955.

⛔ Files ignored due to path filters (4)
  • apps/code/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/playground/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/ui/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • ee/admin/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
📒 Files selected for processing (4)
  • apps/api/src/routes/keys-provider.ts
  • packages/actions/src/get-provider-endpoint.spec.ts
  • packages/db/src/schema.ts
  • packages/models/src/providers.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30ee9558d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +425 to +429
defaultRegion: "global",
regions: [
// Cross-region inference profile groups (spread inference across the
// pool — AWS picks the actual region per request).
{ id: "global", label: "Global (default)" },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Exempt Bedrock from per-region env key filtering

Adding Bedrock regionConfig here makes :us/:eu/:apac mappings go through the existing region-key gate in apps/gateway/src/chat/chat.ts (filterRegionsByAvailableKeys + hasRegionSpecificEnvKey), which only allows non-default regions when a __{REGION} env var exists. In credits mode (and hybrid without a DB key), deployments that only set LLM_AWS_BEDROCK_API_KEY will have those regions filtered out even though Bedrock keys are global and token resolution already falls back to the base key (getRegionSpecificEnvValue in packages/models/src/provider.ts). This effectively disables the new regional routing for those projects.

Useful? React with 👍 / 👎.

The playground model selector built the URL as `provider/modelName:region`
which leaked the provider-specific upstream model id (e.g.
`aws-bedrock/anthropic.claude-haiku-4-5-20251001-v1:0:global`). Switch
to `provider/model.id:region` so URLs are clean and stable
(`aws-bedrock/claude-haiku-4-5:global`) and the parser now resolves
the mapping by region instead of by modelName.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3309422c05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const ProviderIcon = provider ? getProviderIcon(provider.id) : null;
const entryKey = `${mapping!.providerId}-${model.id}-${mapping!.modelName}`;
const providerModelValue = `${mapping!.providerId}/${mapping!.region ? mapping!.modelName : model.id}`;
const providerModelValue = `${mapping!.providerId}/${mapping!.region ? `${model.id}:${mapping!.region}` : model.id}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep regional selector values aligned with mapping modelName

Emit mapping.modelName (or update all consumers together) for regional entries. This change switches the value to ${model.id}:${region}, but playground consumers like getSelectedMapping still resolve by exact mapping.modelName; for mappings where model.id !== mapping.modelName (for example Alibaba regional aliases), the selected regional mapping no longer matches and the UI falls back to a non-regional mapping, which can apply the wrong capability/override state for that selection.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx (1)

199-220: ⚡ Quick win

Consider simplifying the error extraction logic.

The current nested error extraction works for common cases but could miss messages in edge cases (e.g., when error.error exists as an object without a message property, but error.message does exist). Using optional chaining and nullish coalescing would be simpler and more robust.

♻️ Proposed simplification
 				onError: (error: unknown) => {
 					setIsValidating(false);
 					let description =
 						"Failed to validate the API key. Please check your key and region.";
-					if (typeof error === "object" && error !== null) {
-						const err = error as Record<string, unknown>;
-						const nested =
-							err.error && typeof err.error === "object"
-								? (err.error as Record<string, unknown>)
-								: err;
-						if (typeof nested.message === "string") {
-							description = nested.message;
-						}
-					} else if (error instanceof Error) {
+					if (error instanceof Error) {
 						description = error.message;
+					} else if (typeof error === "object" && error !== null) {
+						const err = error as { error?: { message?: string }; message?: string };
+						description = err.error?.message ?? err.message ?? description;
 					}
 					toast({
 						title: "Validation Failed",
 						description,
 						variant: "destructive",
 					});
 				},

This approach:

  • Checks Error instances first (most specific)
  • Uses a more descriptive type for the error object
  • Employs optional chaining to safely extract nested or flat messages
  • Falls back gracefully through nullish coalescing
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx` around
lines 199 - 220, The onError handler's nested error extraction is overly verbose
and can miss cases; modify the onError callback (the function using
setIsValidating and toast in create-provider-key-dialog.tsx) to first handle
Error instances, then use optional chaining and nullish coalescing to pull a
message from (error as any)?.error?.message ?? (error as any)?.message ?? a
default message, setIsValidating(false) as before, and pass that message into
toast({ title: "Validation Failed", description, variant: "destructive" }) so
all nested/flat error shapes are handled succinctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx`:
- Around line 199-220: The onError handler's nested error extraction is overly
verbose and can miss cases; modify the onError callback (the function using
setIsValidating and toast in create-provider-key-dialog.tsx) to first handle
Error instances, then use optional chaining and nullish coalescing to pull a
message from (error as any)?.error?.message ?? (error as any)?.message ?? a
default message, setIsValidating(false) as before, and pass that message into
toast({ title: "Validation Failed", description, variant: "destructive" }) so
all nested/flat error shapes are handled succinctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 50efa09d-6fa3-4d41-b521-7239330ffc32

📥 Commits

Reviewing files that changed from the base of the PR and between 3309422 and 53069a5.

⛔ Files ignored due to path filters (4)
  • apps/code/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/playground/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • apps/ui/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
  • ee/admin/src/lib/api/v1.d.ts is excluded by !**/v1.d.ts
📒 Files selected for processing (3)
  • apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
  • packages/db/src/schema.ts
  • packages/models/src/models/anthropic.ts
💤 Files with no reviewable changes (2)
  • packages/models/src/models/anthropic.ts
  • packages/db/src/schema.ts

steebchen and others added 2 commits May 24, 2026 19:43
Routing previously picked the cheapest among all expanded regional
candidates for a provider, which for AWS Bedrock meant `:global`,
`:us`, `:eu`, `:apac` were equally eligible and the winner was
order-dependent. Add `pinDefaultRegion: true` on aws-bedrock so
requests without a `:region` suffix and without a provider-key
region override always resolve to `:global` (the cross-region
inference profile). Alibaba (no `pinDefaultRegion`) keeps its
"route to the cheapest region" behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/gateway/src/chat/chat.ts`:
- Around line 1879-1890: The candidate-region filtering calls to
applyPinnedDefaultRegions currently only pass { requestedRegion } which allows
pinDefaultRegion to collapse providers (e.g., "aws-bedrock" -> "global") without
respecting org provider-key locks; update those calls (the ones wrapping
expandAllProviderRegions(...) and filterRegionsByAvailableKeys(...)) to also
pass the providerLockedRegions map (constructed from the providerKeys already
available in those paths) so applyPinnedDefaultRegions can honor
provider-specific region locks; apply the same change in the rate-limit and
low-uptime fallback blocks where providerKeys are present (also update the
occurrences around applyPinnedDefaultRegions usage at the other noted sites).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 92c09951-4afc-43ac-8d57-14e05610a05b

📥 Commits

Reviewing files that changed from the base of the PR and between 53069a5 and 63f7431.

📒 Files selected for processing (2)
  • apps/gateway/src/chat/chat.ts
  • packages/models/src/providers.ts

Comment thread apps/gateway/src/chat/chat.ts
Cost calculation and model resolution stripped the :region suffix
with split(":")[0], which broke for upstream model names that
already contain a colon (e.g. AWS Bedrock's
"anthropic.claude-haiku-4-5-20251001-v1:0"). With a :region suffix
applied, the naive split mangled the base name and the lookup fell
through, leading to a $0 billed cost. Use lastIndexOf so only the
trailing :region is removed.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…uting

# Conflicts:
#	apps/playground/src/components/model-selector.tsx

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f11668abc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +432 to +435
regionConfig: {
optionsKey: "aws_bedrock_region",
defaultRegion: "global",
pinDefaultRegion: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope Bedrock default region to mappings that declare regions

Adding a provider-level regionConfig with defaultRegion: "global" for AWS Bedrock applies a region lock to all Bedrock models, including mappings that do not define regional variants. In chat.ts, resolveRegionFromProviderKey now resolves Bedrock keys to global by default, but for non-regional mappings resolve-provider-context later looks up providerId + modelName + region and fails to match (because those mappings have region undefined). That causes provider capabilities to be read as missing (for example supportsReasoning becomes false and max-output validation is skipped), so requests to non-regional Bedrock models can silently lose reasoning behavior. Restrict the default region application to mappings/providers that actually expose regional entries, or fallback the capability lookup to the non-regional mapping when no region-specific mapping exists.

Useful? React with 👍 / 👎.

steebchen and others added 3 commits May 27, 2026 10:59
modelName is the provider's internal upstream id (e.g. AWS Bedrock's
"anthropic.claude-haiku-4-5-20251001-v1:0") and must never leak into
user-facing URLs or lookup logic. Remove the modelName-match
fallbacks that crept into the playground model selector during the
merge — keep only canonical model.id + region resolution.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31af618cee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/gateway/src/chat/chat.ts Outdated
: expandAllProviderRegions(
modelDef.providers as ProviderModelMapping[],
),
{ requestedRegion },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor provider-key regions during auto routing

When the request uses auto in API-key or hybrid mode and a Bedrock provider key is locked to a non-default region (for example aws_bedrock_region: "eu"), this path has already loaded the provider keys but calls applyPinnedDefaultRegions without passing any explicit locks. Because Bedrock has pinDefaultRegion, the candidate list is reduced to global before selection, usedRegion becomes global, and the later usedRegion ??= resolveRegionFromProviderKey(providerKey) cannot restore the key's EU/APAC choice. This makes auto-routed Bedrock requests ignore the configured provider-key region; build/pass the provider locked-region map here as in the later non-auto routing path.

Useful? React with 👍 / 👎.

…uting

# Conflicts:
#	apps/gateway/src/lib/costs.ts
#	apps/playground/src/components/model-selector.tsx
#	apps/ui/src/components/models/playground-model-selector.tsx
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

- Keep an explicit/env Bedrock base URL above the region-derived
  endpoint so :region requests don't bypass a configured proxy.
- Don't read LLM_AWS_BEDROCK_REGION for the model prefix in BYOK mode.
- Add `apac.` to the legacy aws_bedrock_region_prefix enums.
- Add `sharedCredentialAcrossRegions` so Bedrock regions aren't gated
  behind per-region env keys in credits mode (the base key is global).
- Only apply a provider key's default region to models that actually
  expose regional mappings, so non-regional Bedrock models keep their
  capabilities (reasoning, max-output).
- Honor provider-key region locks in the auto, rate-limit, and
  low-uptime fallback routing paths.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@steebchen
steebchen merged commit f4f800f into main May 31, 2026
16 checks passed
@steebchen
steebchen deleted the aws-bedrock-region-routing branch May 31, 2026 10:21
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