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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_bedrock_invoke_native_structured_output
mateo-berri0042493bca5f
diff --cc tests/test_litellm/llms/bedrock/test_bedrock_common_utils.pyindex 609b5c75801,afd5e83ca52..9302dc01abe--- a/tests/test_litellm/llms/bedrock/test_bedrock_common_utils.py+++ b/tests/test_litellm/llms/bedrock/test_bedrock_common_utils.py@@@ -522,42 -522,54 +522,95 @@@ def test_merge_bedrock_aws_request_paraassert merged["aws_region_name"] == "us-west-2"+def test_strip_unsupported_output_config_keeps_format_drops_effort(local_model_cost_map):+ """On a model with neither effort flag, only the ``format`` key survives."""+ from litellm.llms.bedrock.common_utils import (+ strip_unsupported_bedrock_invoke_output_config_keys,+ )++ schema_format = {"type": "json_schema", "schema": {"type": "object"}}+ body = {"output_config": {"effort": "high", "format": schema_format}}++ strip_unsupported_bedrock_invoke_output_config_keys(+ model="anthropic.claude-3-haiku-20240307-v1:0",+ request_body=body,+ )++ assert body["output_config"] == {"format": schema_format}+++def test_apply_structured_output_prefers_legacy_output_format(local_model_cost_map):+ """The legacy ``output_format`` wins over ``output_config.format`` when a+ request carries both, matching the pre-existing precedence."""+ from litellm.llms.bedrock.common_utils import (+ apply_bedrock_invoke_structured_output,+ )++ legacy = {"type": "json_schema", "schema": {"type": "object", "properties": {"a": {"type": "string"}}}}+ newer = {"type": "json_schema", "schema": {"type": "object", "properties": {"b": {"type": "string"}}}}+ body = {+ "messages": [{"role": "user", "content": "hi"}],+ "output_format": legacy,+ "output_config": {"format": newer},+ }++ apply_bedrock_invoke_structured_output(+ model="us.anthropic.claude-sonnet-4-5-20250929-v1:0",+ request_body=body,+ )++ assert body["output_config"] == {"format": legacy}+ assert "output_format" not in body+++++ def test_sign_aws_request_assumes_role_with_external_id(monkeypatch):+ """A trust policy requiring sts:ExternalId must be satisfied when signing batch API requests."""+ import datetime+ from unittest.mock import patch++ import boto3+ from botocore.exceptions import ClientError++ from litellm.llms.bedrock.common_utils import CommonBatchFilesUtils++ monkeypatch.delenv("AWS_EXTERNAL_ID", raising=False)++ class FakeSTSClient:+ def get_caller_identity(self):+ return {"Arn": "arn:aws:iam::111111111111:user/litellm-proxy-pod"}++ def assume_role(self, **params):+ if params.get("ExternalId") != "external-id-batch-sign":+ raise ClientError(+ {"Error": {"Code": "AccessDenied", "Message": "is not authorized to perform: sts:AssumeRole"}},+ "AssumeRole",+ )+ return {+ "Credentials": {+ "AccessKeyId": "ASIABATCHSIGNROLE",+ "SecretAccessKey": "assumed-secret",+ "SessionToken": "assumed-session-token",+ "Expiration": datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(minutes=30),+ }+ }++ optional_params = {+ "aws_region_name": "us-east-1",+ "aws_access_key_id": "AKIABATCHSIGNCALLER",+ "aws_secret_access_key": "pod-caller-secret",+ "aws_role_name": "arn:aws:iam::999999999999:role/litellm-batch-sign-role",+ "aws_session_name": "litellm-batch-sign-session",+ "aws_external_id": "external-id-batch-sign",+ }++ with patch.object(boto3, "client", return_value=FakeSTSClient()):+ signed_headers, signed_data = CommonBatchFilesUtils().sign_aws_request(+ service_name="bedrock",+ data={"jobName": "litellm-batch-job"},+ endpoint_url="https://bedrock.us-east-1.amazonaws.com/model-invocation-job",+ optional_params=optional_params,+ )++ authorization = {key.lower(): value for key, value in signed_headers.items()}["authorization"]+ assert "ASIABATCHSIGNROLE" in authorization+ assert signed_data == b'{"jobName": "litellm-batch-job"}'