Skip to content

fix(core): expand AWS_REGION in Bedrock Mantle base URL - #40076

Open
sergical wants to merge 1 commit into
anomalyco:devfrom
sergical:bedrock-mantle-region
Open

fix(core): expand AWS_REGION in Bedrock Mantle base URL#40076
sergical wants to merge 1 commit into
anomalyco:devfrom
sergical:bedrock-mantle-region

Conversation

@sergical

@sergical sergical commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #40075

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The catalog gives the Mantle endpoint as a template, https://bedrock-mantle.${AWS_REGION}.api.aws/openai/v1. v1 substitutes it through the bedrock loader's vars() hook (added in #31001, expanded at packages/opencode/src/provider/provider.ts:1712). The v2 plugin never did: it resolves a region for the SDK but leaves options.baseURL alone, and packages/core/src/aisdk.ts:80 assigns model.api.url verbatim. So every openai.* Bedrock model on v2 requested that literal hostname and could not connect.

This ports the same substitution to packages/core/src/plugin/provider/amazon-bedrock.ts, reusing the region the plugin already resolves (config region -> AWS_REGION -> us-east-1). It runs after the endpoint override so a VPC endpoint still wins. That matches how the other v2 plugins expand their own templates (google-vertex.ts:78, cloudflare-workers-ai.ts:64) — bedrock was simply missing it.

Also documents the Bedrock OpenAI models in providers.mdx: they are served by the OpenAI-compatible endpoint rather than Converse, and are in fewer regions than the rest of the catalog. A wrong region produces a failure indistinguishable from this bug, so it seemed worth writing down next to the fix.

How did you verify your code works?

Added two tests to packages/core/test/plugin/provider-amazon-bedrock.test.ts — one for a config-supplied region, one for AWS_REGION from the env — covering both /openai/v1 (responses) and /v1 (chat, used by gpt-oss-safeguard-*). Both were red before the change:

Expected: "https://bedrock-mantle.us-east-1.api.aws/v1/chat/completions"
Received: "https://bedrock-mantle.${AWS_REGION}.api.aws/v1/chat/completions"

From packages/core:

bun test test/plugin/command.test.ts test/plugin/provider-amazon-bedrock.test.ts

19 pass, 1 fail. Two caveats a reviewer will hit locally, neither caused by this change (both reproduce with it stashed):

  • The provider plugin tests cannot run standalone on dev. bun test test/plugin/provider-amazon-bedrock.test.ts alone dies with ReferenceError: Cannot access 'AmazonBedrockPlugin' before initialization from a TDZ cycle at packages/core/src/plugin/provider.ts:38. Loading any non-provider test file first avoids it, hence the two paths above.
  • The 1 failure is uses SigV4 credential env when bearer token is absent, which hits the real AWS credential chain and fails on my machine with an expired SSO token.

Also ran bun typecheck from packages/core: clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Re the duplicate bot's suggestion of #35787: that one prompts for a region during /connect on the v1 provider and touches packages/opencode. This is the v2 plugin failing to expand a catalog URL template. They do both edit the Bedrock section of providers.mdx, but different hunks.

🤖 Generated with Claude Code

The catalog advertises the Mantle endpoint as a template
(https://bedrock-mantle.${AWS_REGION}.api.aws/openai/v1). On the v1 path
the bedrock provider's vars() loader substitutes it, but the v2 plugin
never did, so every openai.* Bedrock model requested that literal
hostname and failed to connect.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

This PR might be related because it also addresses Bedrock provider region handling. However, the titles and descriptions suggest they address different aspects: #35787 focuses on prompting users for region selection, while #40076 focuses on template variable substitution in the Mantle base URL.

If #35787 is still open or was recently closed/merged, it would be worth reviewing to ensure the changes are compatible or don't conflict.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Bedrock Mantle models unreachable on v2 — ${AWS_REGION} in base URL is never substituted

1 participant