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]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_lit_4162_bedrock_batch_tags

mateo-berri249e1f8ce791
diff --cc tests/test_litellm/test_router.py
index a13b3759865,1c175bf6f44..cffc3dd0aba
--- a/tests/test_litellm/test_router.py
+++ b/tests/test_litellm/test_router.py
@@@ -5432,61 -5730,79 +5730,139 @@@ class TestRouterRequestTimeoutPropagati
)
+ def test_get_configured_token_limits_reads_deployment_model_info():
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": "my-custom-model",
+ "litellm_params": {"model": "openai/some-unmapped-model"},
+ "model_info": {"max_input_tokens": 32000, "max_output_tokens": 8000},
+ }
+ ]
+ )
+
+ assert router.get_configured_token_limits("my-custom-model") == (32000, 8000)
+
+
+ def test_get_configured_token_limits_returns_none_for_unset_or_unknown():
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": "no-limits-model",
+ "litellm_params": {"model": "openai/some-unmapped-model"},
+ }
+ ]
+ )
+
+ assert router.get_configured_token_limits("no-limits-model") == (None, None)
+ assert router.get_configured_token_limits("not-a-real-model") == (None, None)
+
+
+ def test_get_configured_token_limits_skips_wildcard_pattern_matching():
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": "bedrock/*",
+ "litellm_params": {"model": "bedrock/*"},
+ "model_info": {"max_input_tokens": 12345},
+ }
+ ]
+ )
+
+ with patch.object(
+ router.pattern_router, "route", side_effect=AssertionError("pattern route called")
+ ):
+ assert router.get_configured_token_limits(
+ "bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0"
+ ) == (None, None)
+
+
+ def test_get_configured_token_limits_treats_malformed_values_as_absent():
+ malformed = ["", "unlimited", "128,000", [128000], {"max": 128000}, True]
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": f"bad-limit-{i}",
+ "litellm_params": {"model": "openai/some-unmapped-model"},
+ "model_info": {"max_input_tokens": bad, "max_output_tokens": bad},
+ }
+ for i, bad in enumerate(malformed)
+ ]
+ )
+
+ for i in range(len(malformed)):
+ assert router.get_configured_token_limits(f"bad-limit-{i}") == (None, None)
+
+
+ def test_get_configured_token_limits_coerces_numeric_strings():
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": "quoted-limits-model",
+ "litellm_params": {"model": "openai/some-unmapped-model"},
+ "model_info": {"max_input_tokens": "32000", "max_output_tokens": "8000"},
+ }
+ ]
+ )
+
+ assert router.get_configured_token_limits("quoted-limits-model") == (32000, 8000)
++
++
+async def test_acreate_batch_request_bedrock_tags_override_deployment_tags():
+ import httpx
+
+ from litellm.llms.bedrock.common_utils import CommonBatchFilesUtils
+
+ deployment_tags = [{"key": "application", "value": "config-level"}]
+ request_tags = [{"key": "application", "value": "request-level"}]
+ router = litellm.Router(
+ model_list=[
+ {
+ "model_name": "bedrock-batch-model",
+ "litellm_params": {
+ "model": "bedrock/us.anthropic.claude-sonnet-5",
+ "aws_batch_role_arn": "arn:aws:iam::123:role/batch-role",
+ "aws_region_name": "us-west-2",
+ "bedrock_tags": deployment_tags,
+ },
+ }
+ ]
+ )
+
+ def fake_response():
+ return httpx.Response(
+ status_code=200,
+ json={
+ "jobArn": "arn:aws:bedrock:us-west-2:123:model-invocation-job/abc1234567",
+ "status": "Submitted",
+ },
+ )
+
+ mock_client = MagicMock()
+ mock_client.post = AsyncMock(side_effect=lambda *args, **kwargs: fake_response())
+
+ with patch.object(
+ CommonBatchFilesUtils,
+ "sign_aws_request",
+ return_value=({"Authorization": "signed"}, b"{}"),
+ ) as mock_sign, patch(
+ "litellm.llms.custom_httpx.llm_http_handler.get_async_httpx_client",
+ return_value=mock_client,
+ ):
+ await router.acreate_batch(
+ model="bedrock-batch-model",
+ input_file_id="s3://bucket/input.jsonl",
+ endpoint="/v1/chat/completions",
+ completion_window="24h",
+ )
+ assert mock_sign.call_args.kwargs["data"]["tags"] == deployment_tags
+
+ await router.acreate_batch(
+ model="bedrock-batch-model",
+ input_file_id="s3://bucket/input.jsonl",
+ endpoint="/v1/chat/completions",
+ completion_window="24h",
+ bedrock_tags=request_tags,
+ )
+ assert mock_sign.call_args.kwargs["data"]["tags"] == request_tags