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 branch 'litellm_internal_staging' into litellm_decrease_anys_opus5

mateo-berri43c838f4b9d7
diff --cc basedpyright-code-budget.json
index 7b114dcbb9a,83969d8dedf..f8ef0ce1732
--- a/basedpyright-code-budget.json
+++ b/basedpyright-code-budget.json
@@@ -1,9 -1,9 +1,9 @@@
{
"reportAny": {
- "limit": 16827
- "limit": 17270
++ "limit": 16389
},
"reportArgumentType": {
- "limit": 2384
- "limit": 2538
++ "limit": 2229
},
"reportAssignmentType": {
"limit": 319
@@@ -24,7 -24,7 +24,7 @@@
"limit": 19
},
"reportExplicitAny": {
- "limit": 5364
- "limit": 5485
++ "limit": 5242
},
"reportFunctionMemberAccess": {
"limit": 7
@@@ -54,10 -54,10 +54,10 @@@
"limit": 0
},
"reportMissingParameterType": {
- "limit": 5636
- "limit": 5658
++ "limit": 5614
},
"reportMissingTypeArgument": {
- "limit": 15390
- "limit": 15425
++ "limit": 15356
},
"reportMissingTypeStubs": {
"limit": 40
@@@ -72,7 -72,7 +72,7 @@@
"limit": 0
},
"reportOptionalMemberAccess": {
- "limit": 418
- "limit": 1055
++ "limit": 0
},
"reportOptionalOperand": {
"limit": 0
@@@ -90,7 -90,7 +90,7 @@@
"limit": 8
},
"reportReturnType": {
- "limit": 197
- "limit": 213
++ "limit": 181
},
"reportTypedDictNotRequiredAccess": {
"limit": 25
@@@ -99,25 -99,25 +99,25 @@@
"limit": 0
},
"reportUnknownArgumentType": {
- "limit": 44458
- "limit": 44526
++ "limit": 44389
},
"reportUnknownLambdaType": {
"limit": 109
},
"reportUnknownMemberType": {
- "limit": 38608
- "limit": 38721
++ "limit": 38500
},
"reportUnknownParameterType": {
- "limit": 19725
- "limit": 19778
++ "limit": 19673
},
"reportUnknownVariableType": {
- "limit": 30190
- "limit": 30290
++ "limit": 30092
},
"reportUnnecessaryCast": {
- "limit": 114
- "limit": 117
++ "limit": 111
},
"reportUnnecessaryComparison": {
- "limit": 696
- "limit": 697
++ "limit": 695
},
"reportUnnecessaryContains": {
"limit": 5
diff --cc litellm/litellm_core_utils/llm_response_utils/response_metadata.py
index ea97b90c61f,ac8cf438a9b..b53a2d36753
--- a/litellm/litellm_core_utils/llm_response_utils/response_metadata.py
+++ b/litellm/litellm_core_utils/llm_response_utils/response_metadata.py
@@@ -84,30 -121,15 +119,15 @@@ class ResponseMetadata
self.result._response_ms = total_response_time_ms
#########################################################
- # 1. Add _response_ms total duration
+ # 1. Add _response_ms total duration and the LiteLLM overhead within it
+ # (total minus the cache read on a cache hit, else total minus the provider call)
#########################################################
- self._update_hidden_params(
- {
- "_response_ms": total_response_time_ms,
- }
- )
+ self._update_hidden_params(timing_metrics)
#########################################################
- # 2. Add LiteLLM overhead duration
- #########################################################
- llm_api_duration_ms: Final[float | None] = logging_obj.model_call_details.get("llm_api_duration_ms")
- if llm_api_duration_ms is not None:
- overhead_ms = round(total_response_time_ms - llm_api_duration_ms, 4)
- self._update_hidden_params(
- {
- "litellm_overhead_time_ms": overhead_ms,
- }
- )
-
- #########################################################
- # 3. Add callback processing duration
+ # 2. Add callback processing duration
#########################################################
- callback_duration_ms: Final = getattr(logging_obj, "callback_duration_ms", None)
+ callback_duration_ms: Final[float | None] = getattr(logging_obj, "callback_duration_ms", None)
if callback_duration_ms is not None:
self._update_hidden_params(
{
@@@ -116,26 -138,11 +136,11 @@@
)
#########################################################
- # 4. Add duration for reading from cache
- # In this case overhead from litellm is the difference between the cache read duration and the total response time
- #########################################################
- if (
- logging_obj.caching_details is not None
- and logging_obj.caching_details.get("cache_hit") is True
- and (cache_duration_ms := logging_obj.caching_details.get("cache_duration_ms")) is not None
- ):
- overhead_ms = total_response_time_ms - cache_duration_ms
- self._update_hidden_params(
- {
- "litellm_overhead_time_ms": overhead_ms,
- }
- )
-
- #########################################################
- # 5. Detailed per-phase timing (opt-in via env var)
+ # 3. Detailed per-phase timing (opt-in via env var)
#########################################################
+ llm_api_duration_ms: Final = logging_obj.model_call_details.get("llm_api_duration_ms")
if LITELLM_DETAILED_TIMING and llm_api_duration_ms is not None:
- detailed: Final[dict] = {
+ detailed: Final[dict[str, float]] = {
"timing_llm_api_ms": round(llm_api_duration_ms, 4),
}
diff --cc litellm/proxy/guardrails/guardrail_hooks/hiddenlayer/hiddenlayer.py
index 2c572eb8ea8,f7ea1cb632f..a6ea2e09583
--- a/litellm/proxy/guardrails/guardrail_hooks/hiddenlayer/hiddenlayer.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/hiddenlayer/hiddenlayer.py
@@@ -37,16 -37,12 +37,19 @@@ if TYPE_CHECKING
from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigModel
+ _AUTH_TIMEOUT_SECONDS: Final[float] = 30.0
+
+
+class _CustomGuardrailOptions(TypedDict, total=False, extra_items=object):
+ """Base-class constructor options carried by this guardrail's forwarded keyword arguments."""
+
+ guardrail_name: ReadOnly[str | None]
+ supported_event_hooks: list[GuardrailEventHooks] | None
+
+
class _HiddenlayerEvaluation(TypedDict, total=False):
- action: str
- threat_level: str
+ action: ReadOnly[str]
+ threat_level: ReadOnly[str]
class _HiddenlayerAnalysisEntry(TypedDict, total=False):
diff --cc ruff-strict-budget.json
index 92148dddd76,b4107582000..fce91d57d88
--- a/ruff-strict-budget.json
+++ b/ruff-strict-budget.json
@@@ -1,12 -1,12 +1,12 @@@
{
"ANN001": {
- "limit": 3005
- "limit": 3012
++ "limit": 2998
},
"ANN002": {
"limit": 71
},
"ANN003": {
- "limit": 818
- "limit": 827
++ "limit": 809
},
"ANN201": {
"limit": 2003
@@@ -15,7 -15,7 +15,7 @@@
"limit": 845
},
"ANN204": {
- "limit": 700
- "limit": 702
++ "limit": 698
},
"ANN205": {
"limit": 112
@@@ -24,7 -24,7 +24,7 @@@
"limit": 133
},
"ANN401": {
- "limit": 655
- "limit": 654
++ "limit": 597
},
"ASYNC230": {
"limit": 11
@@@ -195,7 -195,7 +195,7 @@@
"limit": 22
},
"SIM101": {
- "limit": 57
- "limit": 58
++ "limit": 56
},
"SIM102": {
"limit": 315
@@@ -231,7 -231,7 +231,7 @@@
"limit": 5
},
"TID251": {
- "limit": 1117
- "limit": 1116
++ "limit": 1111
},
"TRY002": {
"limit": 524
@@@ -246,7 -246,7 +246,7 @@@
"limit": 113
},
"TRY300": {
- "limit": 856
- "limit": 857
++ "limit": 855
},
"UP028": {
"limit": 2
diff --cc type-discipline-budget.json
index 5c29d527709,7365cec4fdd..bb02618b11e
--- a/type-discipline-budget.json
+++ b/type-discipline-budget.json
@@@ -1,9 -1,9 +1,9 @@@
{
"LIT001": {
- "limit": 22673
- "limit": 22704
++ "limit": 22642
},
"LIT002": {
- "limit": 26844
- "limit": 26854
++ "limit": 26834
},
"LIT003": {
"limit": 269
@@@ -15,7 -15,7 +15,7 @@@
"limit": 0
},
"LIT006": {
- "limit": 1052
- "limit": 1063
++ "limit": 1041
},
"LIT007": {
"limit": 0
@@@ -27,12 -27,12 +27,12 @@@
"limit": 0
},
"LIT010": {
-- "limit": 16564
++ "limit": 16550
},
"LIT011": {
-- "limit": 5577
++ "limit": 5576
},
"LIT012": {
- "limit": 4502
- "limit": 4506
++ "limit": 4496
}
}