-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
feat(bedrock_mantle): Add support for native Responses API route #29476
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
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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """ | ||
| Amazon Bedrock Mantle - OpenAI-compatible Responses API. | ||
|
|
||
| Routes /v1/responses to the provider's native Responses endpoint instead of | ||
| the chat-completions translation fallback. | ||
| """ | ||
|
|
||
| from typing import Optional, cast | ||
|
|
||
| from litellm.llms.bedrock_mantle.chat.transformation import BedrockMantleChatConfig | ||
| from litellm.llms.openai.responses.transformation import OpenAIResponsesAPIConfig | ||
| from litellm.types.router import GenericLiteLLMParams | ||
| from litellm.types.utils import LlmProviders | ||
|
|
||
|
|
||
| class BedrockMantleResponsesAPIConfig(OpenAIResponsesAPIConfig): | ||
| @property | ||
| def custom_llm_provider(self) -> LlmProviders: | ||
| return LlmProviders.BEDROCK_MANTLE | ||
|
|
||
| def validate_environment( | ||
| self, | ||
| headers: dict, | ||
| model: str, | ||
| litellm_params: Optional[GenericLiteLLMParams], | ||
| ) -> dict: | ||
| litellm_params = litellm_params or GenericLiteLLMParams() | ||
| _, api_key = BedrockMantleChatConfig()._get_openai_compatible_provider_info( | ||
| api_base=litellm_params.api_base, | ||
| api_key=litellm_params.api_key, | ||
| ) | ||
| if api_key: | ||
| headers["Authorization"] = f"Bearer {api_key}" | ||
| return headers | ||
|
|
||
| def get_complete_url( | ||
| self, | ||
| api_base: Optional[str], | ||
| litellm_params: dict, | ||
| ) -> str: | ||
| ( | ||
| resolved_api_base, | ||
| _, | ||
| ) = BedrockMantleChatConfig()._get_openai_compatible_provider_info( | ||
| api_base=api_base or litellm_params.get("api_base"), | ||
| api_key=litellm_params.get("api_key"), | ||
| ) | ||
| api_base = cast(str, resolved_api_base).rstrip("/") | ||
| if api_base.endswith("/responses"): | ||
| return api_base | ||
| if api_base.endswith("/openai/v1"): | ||
| return f"{api_base}/responses" | ||
| if api_base.endswith("/openai"): | ||
| return f"{api_base}/v1/responses" | ||
| if api_base.endswith("/v1"): | ||
| return f"{api_base}/responses" | ||
|
Comment on lines
+55
to
+56
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.
When |
||
| return f"{api_base}/openai/v1/responses" | ||
|
|
||
| def supports_native_websocket(self) -> bool: | ||
| return False | ||
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.
High: Bedrock Mantle key can be sent to caller-controlled api_base
An authenticated proxy caller can POST to
/v1/responseswith a Bedrock Mantle model and anapi_basepointing at their server while omittingapi_key.validate_environment()still attachesBEDROCK_MANTLE_API_KEY, and this URL builder sends the request to the caller's host, exposing the provider bearer token. Only use operator-configured base URLs when using the environment credential, or require/allowlist per-requestapi_basebefore attaching the proxy's Bedrock Mantle key.