fix(ai-bedrock): pick the bedrock-mantle URL path per model family#959
Open
feiiiiii5 wants to merge 1 commit into
Open
fix(ai-bedrock): pick the bedrock-mantle URL path per model family#959feiiiiii5 wants to merge 1 commit into
feiiiiii5 wants to merge 1 commit into
Conversation
…anStack#925) `buildBaseURL` returned a single hardcoded path per endpoint — `/v1` on `bedrock-mantle`. AWS serves different model families on different mantle paths: Gemma is served on `/openai/v1` (per its model card's "In-Region endpoint URL"), while gpt-oss and DeepSeek use the `/v1` default. Sending a request to the wrong path returned a misleading `401 ... is not enabled for this account (access_denied)` instead of a 404 / "wrong path" error, which made the bug hard to diagnose (TanStack#925). Thread the model id through `withBedrockDefaults` → `buildBaseURL` → `mantlePathForModel`, which routes `google.gemma-*` to `/openai/v1` and falls back to `/v1` for every other id. The chat and responses adapter constructors pass the model id through; an explicit `baseURL` override still wins, preserving the existing escape hatch and the E2E → aimock wiring. The runtime (`bedrock-runtime`) endpoint is unchanged — every chat-capable model is served at `/openai/v1` there, so the model parameter is unused on that branch. Out of scope (called out as "Suggested directions" in TanStack#925): a catalog- driven refactor that carries the path per `(endpoint, api)` on the generated catalog entry. That's a larger follow-up; this is the minimal bug fix. Claude-on-mantle at `/anthropic/v1/messages` is also out of scope — that path serves the Anthropic Messages API, which has a different wire format from OpenAI Chat Completions, so the chat adapter can't drive it regardless of the path. The catalog already marks Claude models as `chat: false`, so that combination typechecks as an error today. Adds `tests/mantle-path.test.ts` (14 cases) pinning the per-family mantle path, the backward-compat default, the `baseURL` override, and the runtime-branch invariant that the model parameter has no effect there. Fixes TanStack#925.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughBedrock client URL construction now selects the mantle path by model family. Adapters pass model identifiers into default configuration, while tests cover Gemma, fallback models, overrides, prefix matching, and unchanged runtime routing. ChangesBedrock mantle routing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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.
🎯 Changes
@tanstack/ai-bedrockhardcoded thebedrock-mantlebase URL to/v1, but AWS serves different model families on different mantle paths. From the AWS model cards' "Programmatic Access → In-Region endpoint URL":google.gemma-*/openai/v1openai/v1/...path on thebedrock-mantleendpoint. This is different from thev1/...path used by other models."deepseek.*/v1openai.gpt-oss-*/v1The hardcoded
/v1was correct only for the latter two. Sending a Gemma request to/v1/chat/completionsreturned a misleading401 ... is not enabled for this account (access_denied)instead of a 404 / "wrong path" error, which made the bug hard to diagnose (#925). The SigV4 signing service (bedrock-mantle) was correct — only the path was wrong.This PR threads the model id through
withBedrockDefaults→buildBaseURL→mantlePathForModel, which routesgoogle.gemma-*to/openai/v1and falls back to/v1for every other id. The chat and responses adapter constructors pass the model id through; an explicitbaseURLoverride still wins (preserves the existing escape hatch and the E2E → aimock wiring).The runtime (
bedrock-runtime) endpoint is unchanged — every chat-capable model is served at/openai/v1there, so the model parameter is unused on that branch (covered by a separate test group).Out of scope (called out as "Suggested directions" in #925)
(endpoint, api)on the generated catalog entry so this becomes data-driven instead of a prefix switch. That's a larger follow-up; the prefix match here is the minimal bug fix./anthropic/v1/messages— that path serves the Anthropic Messages API, which has a different wire format from OpenAI Chat Completions, so the chat adapter can't drive it regardless of the path. The catalog already marks Claude models aschat: false, sobedrockText('anthropic.claude-…', { endpoint: 'mantle' })typechecks as an error today. A native Messages-API adapter would be a separate piece of work.✅ Checklist
🚀 Release Impact
Test Plan
Ran locally (skipping
test:react-nativewhich needs a RN simulator — RN packages are not touched by this PR):```
pnpm exec nx affected --targets=test:sherif,test:knip,test:docs,test:kiira,test:eslint,test:lib,test:types,test:build,build --exclude=examples/,testing/
pnpm test:dts
```
All green (9/9 Nx tasks,
test:dtsclean — 127 .d.ts files). The newtests/mantle-path.test.tsadds 14 cases pinning:/openai/v1on mantle/v1default on mantle/v1defaultacme.google.gemma-fake-v1:0does not match (usesstartsWith, notincludes— Bedrock model ids always start with the provider prefix)baseURLoverride wins even when model would route elsewhereThe signature change to
withBedrockDefaults(config, forced?, model?)is backward compatible —modelis optional and defaults to undefined →/v1(the pre-#925 behavior). Existingtests/client.test.tscalls withoutmodelstill pass unchanged.Fixes #925.
Summary by CodeRabbit
/openai/v1path./v1path for other model families.