Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(bedrock): extract region and model ID from bedrock/{region}/{model} path format

Sameer Kankute5864317d929b
diff --git a/litellm/llms/bedrock/chat/converse_handler.py b/litellm/llms/bedrock/chat/converse_handler.py
index ec5b942ec1b..26986aab586 100644
--- a/litellm/llms/bedrock/chat/converse_handler.py
+++ b/litellm/llms/bedrock/chat/converse_handler.py
@@ -4,6 +4,9 @@ from typing import Any, Optional, Union
import httpx
import litellm
+from litellm.anthropic_beta_headers_manager import (
+ update_headers_with_filtered_beta,
+)
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject
from litellm.llms.custom_httpx.http_handler import (
AsyncHTTPHandler,
@@ -13,11 +16,9 @@ from litellm.llms.custom_httpx.http_handler import (
)
from litellm.types.utils import ModelResponse
from litellm.utils import CustomStreamWrapper
-from litellm.anthropic_beta_headers_manager import (
- update_headers_with_filtered_beta,
- )
+
from ..base_aws_llm import BaseAWSLLM, Credentials
-from ..common_utils import BedrockError
+from ..common_utils import BedrockError, _get_all_bedrock_regions
from .invoke_handler import AWSEventStreamDecoder, MockResponseIterator, make_call
@@ -279,11 +280,22 @@ class BedrockConverseLLM(BaseAWSLLM):
if _stripped.startswith(rp):
_stripped = _stripped[len(rp):]
break
+ # Strip embedded region prefix (e.g. "bedrock/us-east-1/model" -> "model")
+ # and capture it so it can be used as aws_region_name below.
+ _region_from_model: Optional[str] = None
+ _potential_region = _stripped.split("/", 1)[0]
+ if _potential_region in _get_all_bedrock_regions() and "/" in _stripped:
+ _region_from_model = _potential_region
+ _stripped = _stripped.split("/", 1)[1]
+ _model_for_id = _stripped
for _nova_prefix in ["nova-2/", "nova/"]:
if _stripped.startswith(_nova_prefix):
_model_for_id = _model_for_id.replace(_nova_prefix, "", 1)
break
modelId = self.encode_model_id(model_id=_model_for_id)
+ # Inject region extracted from model path so _get_aws_region_name picks it up
+ if _region_from_model is not None and "aws_region_name" not in optional_params:
+ optional_params["aws_region_name"] = _region_from_model
fake_stream = litellm.AmazonConverseConfig().should_fake_stream(
fake_stream=fake_stream,
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index f52288ea72a..cbd64a178b8 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -16289,7 +16289,7 @@
"cache_read_input_token_cost": 3e-08,
"input_cost_per_audio_token": 1e-06,
"input_cost_per_token": 3e-07,
- "litellm_provider": "vertex_ai-language-models",
+ "litellm_provider": "gemini",
"max_audio_length_hours": 8.4,
"max_audio_per_prompt": 1,
"supports_reasoning": false,