fix: model-family-aware Mantle base URL resolution for OpenAI models#2922
Open
Ashutosh0x wants to merge 3 commits into
Open
fix: model-family-aware Mantle base URL resolution for OpenAI models#2922Ashutosh0x wants to merge 3 commits into
Ashutosh0x wants to merge 3 commits into
Conversation
Fixes strands-agents#2629 The _MANTLE_BASE_URL_TEMPLATE uses /v1 for all models, but openai.gpt-5.* models require /openai/v1. This adds a _resolve_mantle_base_url() helper that keys the path off the model_id, plus a base_url override in BedrockMantleConfig for unmapped model families.
Author
|
Note: This PR currently only modifies _openai_bedrock.py with the model-family-aware resolver. The callers (OpenAIModel and OpenAIResponsesModel) need a one-line update each to pass model_id: `python In openai.py (line ~144) and openai_responses.py (line ~198):Before:return resolve_bedrock_client_args(self._bedrock_mantle_config, self.client_args) After:return resolve_bedrock_client_args(self._bedrock_mantle_config, self.client_args, model_id=self.config.get('model_id')) |
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.
Issue
Fixes #2629
Problem
The _MANTLE_BASE_URL_TEMPLATE hardcodes /v1 for all models, but OpenAI model families require different path prefixes on Bedrock Mantle:
As confirmed by @SummerWJLiu in #2629: flipping the template wholesale to /openai/v1 would break gpt-oss models.
Solution
Instead of a single static template, this PR adds model-family-aware URL resolution:
1. New _resolve_mantle_base_url() helper
`python
def _resolve_mantle_base_url(region: str, model_id: str | None = None) -> str:
path_prefix = 'v1'
if model_id:
for prefix in _OPENAI_PATH_MODEL_PREFIXES:
if model_id.startswith(prefix):
path_prefix = 'openai/v1'
break
return _MANTLE_BASE_URL_TEMPLATE.format(region=region, path_prefix=path_prefix)
``n
2. model_id parameter added to
esolve_bedrock_client_args()`nCallers now pass model_id to enable automatic path resolution.
3. base_url override in BedrockMantleConfig`nFor unmapped model families, users can set base_url in the config dict to bypass automatic resolution:
`python
model = OpenAIResponsesModel(
model_id='openai.new-model',
bedrock_mantle_config={'region': 'us-east-1', 'base_url': 'https://bedrock-mantle.us-east-1.api.aws/custom/v1'}
)
``n
Changes
esolve_bedrock_client_args()
Note
Callers of
esolve_bedrock_client_args() (in OpenAIModel and OpenAIResponsesModel) need to be updated to pass model_id. The model_id parameter defaults to None (backward compatible — falls back to /v1).
Testing