Repository navigation
fix(bedrock): backport #41870, the GPT-6 reasoning gate fix, and the Python 3.13 image pin to stable/1.98.x for v1.98.1 #42002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7996007
c32db1b
9f48cca
1af2cad
0c0dda9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import copy | ||
| import json | ||
| import re | ||
| import time | ||
| import types | ||
| from typing import Final, Literal, cast, overload | ||
|
|
@@ -92,6 +93,7 @@ | |
| "bash_", | ||
| "text_editor_", | ||
| ] | ||
| BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS: Final = 16 | ||
|
|
||
| # Beta header patterns that are not supported by Bedrock Converse API | ||
| # These will be filtered out to prevent errors | ||
|
|
@@ -280,6 +282,14 @@ def _validate_request_metadata(self, metadata: dict) -> None: | |
| llm_provider="bedrock", | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _requires_min_max_tokens(model: str) -> bool: | ||
| return re.search(r"openai\.gpt-\d|xai\.grok-", model) is not None | ||
|
Comment on lines
+285
to
+287
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name-pattern check violates the directive to store model-specific flags in Rule Used: What: Do not hardcode model-specific flags in the codebase. Instead, put them in model_prices_and_context_window.json and then read them in via get_model_info Why: Prevents need for users to upgrade litellm each time a new model supports this featu... (source) Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same shape as main's merged #41870. The pattern matches model families, not individual models, so new GPT or Grok releases need no cost-map entry
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s a fair distinction. I rechecked #41870: |
||
|
|
||
| @staticmethod | ||
| def _is_openai_gpt_reasoning_model(model: str) -> bool: | ||
| return re.search(r"openai\.gpt-\d", model) is not None | ||
|
|
||
| def _is_nova_2_model(self, model: str) -> bool: | ||
| """ | ||
| Check if the model is a Nova 2 model that supports reasoningConfig. | ||
|
|
@@ -410,12 +420,16 @@ def _handle_reasoning_effort_parameter(self, model: str, reasoning_effort: str, | |
| Handle the reasoning_effort parameter based on the model type. | ||
|
|
||
| - GPT-OSS models: passed through unchanged via additionalModelRequestFields. | ||
| - OpenAI GPT-5.x and GPT-6 models: mapped to ``reasoning.effort`` via additionalModelRequestFields. | ||
| - Nova 2 models: transformed to reasoningConfig. | ||
| - Anthropic models: mapped to ``thinking`` (and ``output_config.effort`` on | ||
| adaptive Claude 4.6 / 4.7). | ||
| """ | ||
| if "gpt-oss" in model: | ||
| optional_params["reasoning_effort"] = reasoning_effort | ||
| elif self._is_openai_gpt_reasoning_model(model): | ||
| reasoning: Final[BedrockConverseGptReasoningEffortBlock] = {"effort": reasoning_effort} | ||
| optional_params["reasoning"] = reasoning # rebind-ok: out-param store like siblings | ||
| elif self._is_nova_2_model(model): | ||
| reasoning_config: Final = self._transform_reasoning_effort_to_reasoning_config(reasoning_effort) | ||
| optional_params.update(reasoning_config) | ||
|
|
@@ -547,7 +561,11 @@ def get_supported_openai_params(self, model: str) -> list[str]: | |
| # only anthropic and mistral support tool choice config. otherwise (E.g. cohere) will fail the call - https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolChoice.html | ||
| supported_params.append("tool_choice") | ||
|
|
||
| if "gpt-oss" in model: | ||
| if ( | ||
| "gpt-oss" in model | ||
| or self._is_openai_gpt_reasoning_model(model) | ||
| or self._is_openai_gpt_reasoning_model(base_model) | ||
| ): | ||
| supported_params.append("reasoning_effort") | ||
| elif self._is_nova_2_model(model): | ||
| # Nova 2 models support reasoning_effort (transformed to reasoningConfig) | ||
|
|
@@ -858,7 +876,11 @@ def map_openai_params( | |
| is_thinking_enabled=is_thinking_enabled, | ||
| ) | ||
| if param == "max_tokens" or param == "max_completion_tokens": | ||
| optional_params["maxTokens"] = value | ||
| optional_params["maxTokens"] = ( | ||
| max(value, BEDROCK_OPENAI_COMPAT_MIN_MAX_TOKENS) | ||
| if isinstance(value, int) and self._requires_min_max_tokens(model) | ||
| else value | ||
|
Comment on lines
878
to
+882
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Backport of #41870, where this was withdrawn. The regex clamps ARNs embedding the model id; opaque application profiles carry none, so get_model_info cannot resolve them
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s fair. Opaque application-profile ARNs contain no model identifier, and |
||
| ) | ||
| if param == "stream": | ||
| optional_params["stream"] = value | ||
| if param == "stop": | ||
|
|
@@ -895,7 +917,7 @@ def map_openai_params( | |
| optional_params["_parallel_tool_use_config"] = { | ||
| "tool_choice": {"type": "auto", "disable_parallel_tool_use": not value} | ||
| } | ||
| if param == "thinking": | ||
| if param == "thinking" and not self._is_openai_gpt_reasoning_model(model): | ||
| if ( | ||
| isinstance(value, dict) | ||
| and value.get("type") == "adaptive" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary, backend, gateway, database, and non-root images now install Python 3.13 explicitly, but the separately shipped
migrations/Dockerfileremains on the old Wolfi digest and installs the movingpython3metapackage. It can therefore select a different Python version, including an incompatible newer interpreter, causing the migration image to fail during build or startup. Apply the same base-image and Python 3.13 pin to the migration image.