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_decrease_anys_opus5

mateo-berric37260a2bd8e
diff --cc basedpyright-code-budget.json
index 3fa30f96dea,962d1266fd7..0a71a81693d
--- a/basedpyright-code-budget.json
+++ b/basedpyright-code-budget.json
@@@ -1,18 -1,18 +1,18 @@@
{
"reportAny": {
- "limit": 15800
- "limit": 17271
++ "limit": 16827
},
"reportArgumentType": {
- "limit": 2262
- "limit": 2539
++ "limit": 2384
},
"reportAssignmentType": {
- "limit": 319
+ "limit": 320
},
"reportAttributeAccessIssue": {
- "limit": 480
+ "limit": 488
},
"reportCallIssue": {
- "limit": 112
+ "limit": 114
},
"reportConstantRedefinition": {
"limit": 40
@@@ -24,7 -24,7 +24,7 @@@
"limit": 19
},
"reportExplicitAny": {
- "limit": 5174
- "limit": 5486
++ "limit": 5364
},
"reportFunctionMemberAccess": {
"limit": 7
@@@ -54,10 -54,10 +54,10 @@@
"limit": 0
},
"reportMissingParameterType": {
- "limit": 5590
- "limit": 5658
++ "limit": 5636
},
"reportMissingTypeArgument": {
- "limit": 15327
- "limit": 15425
++ "limit": 15390
},
"reportMissingTypeStubs": {
"limit": 40
@@@ -72,7 -72,7 +72,7 @@@
"limit": 0
},
"reportOptionalMemberAccess": {
- "limit": 0
- "limit": 1055
++ "limit": 418
},
"reportOptionalOperand": {
"limit": 0
@@@ -90,34 -90,34 +90,34 @@@
"limit": 8
},
"reportReturnType": {
- "limit": 181
- "limit": 213
++ "limit": 197
},
"reportTypedDictNotRequiredAccess": {
- "limit": 25
+ "limit": 26
},
"reportUndefinedVariable": {
"limit": 0
},
"reportUnknownArgumentType": {
- "limit": 44375
- "limit": 44526
++ "limit": 44458
},
"reportUnknownLambdaType": {
"limit": 109
},
"reportUnknownMemberType": {
- "limit": 38487
- "limit": 38721
++ "limit": 38608
},
"reportUnknownParameterType": {
- "limit": 19590
- "limit": 19778
++ "limit": 19725
},
"reportUnknownVariableType": {
- "limit": 30126
- "limit": 30290
++ "limit": 30190
},
"reportUnnecessaryCast": {
- "limit": 113
- "limit": 117
++ "limit": 114
},
"reportUnnecessaryComparison": {
-- "limit": 697
++ "limit": 696
},
"reportUnnecessaryContains": {
"limit": 5
@@@ -135,12 -135,12 +135,12 @@@
"limit": 21
},
"reportUnusedFunction": {
- "limit": 138
+ "limit": 139
},
"reportUnusedImport": {
- "limit": 541
+ "limit": 543
},
"reportUnusedVariable": {
- "limit": 133
+ "limit": 139
}
}
diff --cc enterprise/litellm_enterprise/proxy/audit_logging_endpoints.py
index 21bde06e86a,8f4e999bb9d..b6f8bf2dc5b
--- a/enterprise/litellm_enterprise/proxy/audit_logging_endpoints.py
+++ b/enterprise/litellm_enterprise/proxy/audit_logging_endpoints.py
@@@ -7,9 -7,7 +7,7 @@@ GET - /audit/{id} - Get audit log by i
GET - /audit - Get all audit logs
"""
- from collections.abc import Mapping, Sequence
- from datetime import datetime
- from typing import Final, Protocol
-from typing import TYPE_CHECKING, Final, Optional
++from typing import TYPE_CHECKING, Final
#### AUDIT LOGGING ####
from fastapi import APIRouter, Depends, HTTPException, Query
diff --cc litellm/_lazy_imports.py
index dff3b11e353,d7e00a81b38..553aeb6680d
--- a/litellm/_lazy_imports.py
+++ b/litellm/_lazy_imports.py
@@@ -17,14 -17,11 +17,11 @@@ until they're actually needed
import importlib
import sys
-from collections.abc import Callable
+from collections.abc import Callable, Mapping
+ from types import ModuleType
from typing import TYPE_CHECKING, Any, Final, cast
- if TYPE_CHECKING:
- import httpx
- import tiktoken
-
- from .caching.llm_caching_handler import LLMClientCache as LLMClientCacheType
+ from typing_extensions import ReadOnly, TypedDict
# Import all the data structures that define what can be lazy-loaded
# These are just lists of names and maps of where to find them
@@@ -59,8 -56,11 +56,12 @@@ from ._lazy_imports_registry import
UTILS_NAMES,
)
+ if TYPE_CHECKING:
++ import httpx
+ from tiktoken import Encoding
+
-def get_litellm_globals() -> dict:
+def get_litellm_globals() -> dict[str, object]:
"""
Get the globals dictionary of the litellm module.
diff --cc litellm/integrations/bitbucket/bitbucket_client.py
index c6967ef3340,9c964d8c10c..e7256da0237
--- a/litellm/integrations/bitbucket/bitbucket_client.py
+++ b/litellm/integrations/bitbucket/bitbucket_client.py
@@@ -158,12 -163,15 +163,11 @@@ class BitBucketClient
response.raise_for_status()
data: Final[BitBucketSrcListing] = response.json()
- files: Final[list[str]] = []
-
- for item in data.get("values", []):
- if item.get("type") == "commit_file":
- file_path = item.get("path", "")
- if file_path.endswith(file_extension):
- files.append(file_path)
--
- return files
+ return [
+ file_path
+ for item in data.get("values", [])
+ if item.get("type") == "commit_file" and (file_path := item.get("path", "")).endswith(file_extension)
+ ]
except Exception as e:
# Check if it's an HTTP error
diff --cc litellm/llms/bedrock/realtime/handler.py
index e795e907eb4,96d7a79c6d8..3bda8dd8359
--- a/litellm/llms/bedrock/realtime/handler.py
+++ b/litellm/llms/bedrock/realtime/handler.py
@@@ -184,11 -166,6 +166,11 @@@ class BedrockRealtime(BaseAWSLLM)
)
bedrock_client: Final = BedrockRuntimeClient(config=config)
- async def open_bidirectional_stream() -> _BedrockBidirectionalStream:
++ async def open_bidirectional_stream() -> BedrockBidirectionalStream:
+ return await bedrock_client.invoke_model_with_bidirectional_stream(
+ InvokeModelWithBidirectionalStreamOperationInput(model_id=model)
+ )
+
transformation_config: Final = BedrockRealtimeConfig()
try:
diff --cc litellm/llms/chatgpt/chat/streaming_utils.py
index f8c54c0a1d8,d4a168a6984..ee3120bacea
--- a/litellm/llms/chatgpt/chat/streaming_utils.py
+++ b/litellm/llms/chatgpt/chat/streaming_utils.py
@@@ -54,13 -49,13 +49,13 @@@ class ChatGPTToolCallNormalizer
def __getattr__(self, name: str) -> object:
return getattr(self._stream, name)
- def __iter__(self):
+ def __iter__(self) -> "ChatGPTToolCallNormalizer":
return self
- def __aiter__(self):
+ def __aiter__(self) -> "ChatGPTToolCallNormalizer":
return self
- def __next__(self) -> ChatGPTStreamChunk:
+ def __next__(self) -> ModelResponseStream:
while True:
chunk = next(self._stream)
result = self._normalize(chunk)
diff --cc litellm/llms/compactifai/chat/transformation.py
index 3d189911e9e,63a5427d211..3c5a889ce63
--- a/litellm/llms/compactifai/chat/transformation.py
+++ b/litellm/llms/compactifai/chat/transformation.py
@@@ -60,11 -47,11 +62,11 @@@ class CompactifAIChatConfig(OpenAIGPTCo
raw_response: httpx.Response,
model_response: ModelResponse,
logging_obj: LiteLLMLoggingObj,
- request_data: dict,
- messages: list,
- optional_params: dict,
- litellm_params: dict,
+ request_data: Mapping[str, object],
+ messages: Sequence[AllMessageValues],
+ optional_params: Mapping[str, object],
+ litellm_params: Mapping[str, object],
- encoding: object,
+ encoding: "tiktoken.Encoding | None",
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse:
diff --cc litellm/proxy/guardrails/guardrail_hooks/hiddenlayer/hiddenlayer.py
index 0ae048c040d,c595952bec2..2c572eb8ea8
--- a/litellm/proxy/guardrails/guardrail_hooks/hiddenlayer/hiddenlayer.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/hiddenlayer/hiddenlayer.py
@@@ -2,7 -2,7 +2,7 @@@ from __future__ import annotation
import os
from collections.abc import Mapping, Sequence
- from typing import TYPE_CHECKING, Any, Final, Literal, Protocol
-from typing import TYPE_CHECKING, Any, Final, Literal, Protocol, TypedDict
++from typing import TYPE_CHECKING, Final, Literal, Protocol
from urllib.parse import urlparse
from uuid import uuid4
@@@ -49,22 -43,34 +50,34 @@@ class _HiddenlayerEvaluation(TypedDict
class _HiddenlayerAnalysisEntry(TypedDict, total=False):
- name: str
- detected: bool
+ name: ReadOnly[str]
+ detected: ReadOnly[bool]
+ class _HiddenlayerModifiedMessage(TypedDict):
+ content: ReadOnly[str | list[Mapping[str, str]]]
+
+
class _HiddenlayerModifiedSide(TypedDict):
- messages: ReadOnly[Any]
+ messages: ReadOnly[list[_HiddenlayerModifiedMessage]]
class _HiddenlayerResponse(TypedDict, total=False):
- evaluation: _HiddenlayerEvaluation
- analysis: Sequence[_HiddenlayerAnalysisEntry]
- modified_data: Mapping[str, _HiddenlayerModifiedSide]
+ evaluation: ReadOnly[_HiddenlayerEvaluation]
+ analysis: ReadOnly[Sequence[_HiddenlayerAnalysisEntry]]
+ modified_data: ReadOnly[Mapping[str, _HiddenlayerModifiedSide]]
+ class _ProxyServerRequest(TypedDict, total=False):
+ headers: ReadOnly[dict[str, str]]
+
+
+ class _HiddenlayerRequestData(TypedDict, total=False):
+ proxy_server_request: ReadOnly[_ProxyServerRequest]
+
+
class _LoggedCallMetadata(TypedDict, total=False):
- headers: ReadOnly[Mapping[str, str]]
+ headers: ReadOnly[dict[str, str]]
class _LoggedCallLitellmParams(TypedDict, total=False):
@@@ -491,9 -525,9 +532,9 @@@ class HiddenlayerGuardrailV2(CustomGuar
async def _call_hiddenlayer(
self,
- payload: Any,
+ payload: _HiddenlayerV2Payload,
input_type: Literal["request", "response"],
- hl_headers: dict[str, str],
+ hl_headers: Mapping[str, str],
) -> httpx.Response:
if input_type == "request":
path = "detection/v2/request-evaluations"
diff --cc ruff-strict-budget.json
index e1ffc03ae7c,c60988eccc0..61bef07fcb3
--- a/ruff-strict-budget.json
+++ b/ruff-strict-budget.json
@@@ -1,21 -1,21 +1,21 @@@
{
"ANN001": {
- "limit": 2990
- "limit": 3012
++ "limit": 3005
},
"ANN002": {
"limit": 71
},
"ANN003": {
- "limit": 800
- "limit": 827
++ "limit": 818
},
"ANN201": {
- "limit": 2003
+ "limit": 2005
},
"ANN202": {
- "limit": 845
+ "limit": 848
},
"ANN204": {
- "limit": 695
- "limit": 702
++ "limit": 700
},
"ANN205": {
"limit": 112
@@@ -24,7 -24,7 +24,7 @@@
"limit": 133
},
"ANN401": {
- "limit": 790
- "limit": 655
++ "limit": 733
},
"ASYNC230": {
"limit": 11
@@@ -198,10 -195,10 +198,10 @@@
"limit": 22
},
"SIM101": {
- "limit": 55
- "limit": 58
++ "limit": 57
},
"SIM102": {
- "limit": 315
+ "limit": 317
},
"SIM103": {
"limit": 119
@@@ -234,7 -231,7 +234,7 @@@
"limit": 5
},
"TID251": {
- "limit": 1170
- "limit": 1117
++ "limit": 1165
},
"TRY002": {
"limit": 524
diff --cc type-discipline-budget.json
index 51cc0a4d8d1,f3f1a7defe7..70376a56b9a
--- a/type-discipline-budget.json
+++ b/type-discipline-budget.json
@@@ -1,9 -1,9 +1,9 @@@
{
"LIT001": {
- "limit": 22518
- "limit": 22705
++ "limit": 22673
},
"LIT002": {
- "limit": 26823
- "limit": 26854
++ "limit": 26844
},
"LIT003": {
"limit": 269
@@@ -15,7 -15,7 +15,7 @@@
"limit": 0
},
"LIT006": {
- "limit": 1049
- "limit": 1063
++ "limit": 1052
},
"LIT007": {
"limit": 0
@@@ -27,12 -27,12 +27,12 @@@
"limit": 0
},
"LIT010": {
- "limit": 16611
- "limit": 16564
++ "limit": 16598
},
"LIT011": {
- "limit": 5580
- "limit": 5577
++ "limit": 5579
},
"LIT012": {
- "limit": 4491
- "limit": 4508
++ "limit": 4502
}
}