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_remove_types_ruff_exclusion

mateo-berri51c54b56acd9
diff --cc litellm/llms/bedrock/chat/invoke_handler.py
index 35ddbc70347,5068f3c9b05..8d2b3dae71b
--- a/litellm/llms/bedrock/chat/invoke_handler.py
+++ b/litellm/llms/bedrock/chat/invoke_handler.py
@@@ -784,10 -786,10 +784,10 @@@ class MockResponseIterator: # for retu
def _chunk_parser(self, chunk_data: ModelResponse) -> GChunk:
try:
chunk_usage: Final[Usage] = getattr(chunk_data, "usage")
- text = chunk_data.choices[0].message.content or "" # type: ignore
+ text = chunk_data.choices[0].message.content or ""
tool_use = None
_model_response_tool_call: Final = cast(
- List[ChatCompletionMessageToolCall] | None,
+ list[ChatCompletionMessageToolCall] | None,
cast(Choices, chunk_data.choices[0]).message.tool_calls,
)
if self.json_mode is True:
diff --cc litellm/types/google_genai/main.py
index 90b5eb9500c,467db318057..13ba9423a53
--- a/litellm/types/google_genai/main.py
+++ b/litellm/types/google_genai/main.py
@@@ -16,40 -19,41 +16,40 @@@ if TYPE_CHECKING
GenerateContentRequestParametersDict = _genai_types._GenerateContentParametersDict
ToolConfigDict = _genai_types.ToolConfigDict
- class GenerateContentRequestDict(GenerateContentRequestParametersDict): # type: ignore[misc, valid-type]
+ class GenerateContentRequestDict(GenerateContentRequestParametersDict):
- generationConfig: Optional[Any]
- tools: Optional[ToolConfigDict]
+ generationConfig: Any | None
- tools: ToolConfigDict | None # type: ignore[assignment, valid-type]
++ tools: ToolConfigDict | None
- class GenerateContentResponse(GoogleGenAIGenerateContentResponse, BaseLiteLLMOpenAIResponseObject): # type: ignore[misc, valid-type]
+ class GenerateContentResponse(GoogleGenAIGenerateContentResponse, BaseLiteLLMOpenAIResponseObject):
_hidden_params: dict = {}
- pass
else:
# Fallback types when google.genai is not available
ContentListUnion = Any
- ContentListUnionDict = Dict[str, Any]
- GenerateContentConfigOrDict = Dict[str, Any]
- GoogleGenAIGenerateContentResponse = Dict[str, Any]
- GenerateContentContentListUnionDict = Dict[str, Any]
+ ContentListUnionDict = dict[str, Any]
+ GenerateContentConfigOrDict = dict[str, Any]
+ GoogleGenAIGenerateContentResponse = dict[str, Any]
+ GenerateContentContentListUnionDict = dict[str, Any]
# Create a proper fallback class that can be instantiated
- class GenerateContentConfigDict(dict): # type: ignore[misc]
- def __init__(self, **kwargs) -> None: # type: ignore
+ class GenerateContentConfigDict(dict):
- def __init__(self, **kwargs):
++ def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
- class GenerateContentRequestParametersDict(dict): # type: ignore[misc]
- def __init__(self, **kwargs) -> None: # type: ignore
+ class GenerateContentRequestParametersDict(dict):
- def __init__(self, **kwargs):
++ def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
- ToolConfigDict = Dict[str, Any]
+ ToolConfigDict = dict[str, Any]
- class GenerateContentRequestDict(GenerateContentRequestParametersDict): # type: ignore[misc]
- def __init__(self, **kwargs) -> None: # type: ignore
+ class GenerateContentRequestDict(GenerateContentRequestParametersDict):
- def __init__(self, **kwargs):
++ def __init__(self, **kwargs) -> None:
# Extract specific fields
self.generationConfig = kwargs.get("generationConfig")
self.tools = kwargs.get("tools")
super().__init__(**kwargs)
- class GenerateContentResponse(BaseLiteLLMOpenAIResponseObject): # type: ignore[misc]
- def __init__(self, **kwargs) -> None: # type: ignore
+ class GenerateContentResponse(BaseLiteLLMOpenAIResponseObject):
- def __init__(self, **kwargs):
++ def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self._hidden_params = kwargs.get("_hidden_params", {})
diff --cc litellm/types/llms/base.py
index 4b4bd6bca6e,b33a8cc07b3..f09727ad92b
--- a/litellm/types/llms/base.py
+++ b/litellm/types/llms/base.py
@@@ -9,9 -9,9 +9,9 @@@ class LiteLLMPydanticObjectBase(BaseMod
Implements default functions, all pydantic objects should have.
"""
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump(**kwargs) # noqa
+ return self.model_dump(**kwargs)
except Exception:
# if using pydantic v1
return self.dict(**kwargs)
@@@ -63,9 -63,9 +63,9 @@@ class HiddenParams(OpenAIObject)
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
diff --cc litellm/types/llms/openai.py
index d2dfa03dd3d,523255c0064..da0592e6bb2
--- a/litellm/types/llms/openai.py
+++ b/litellm/types/llms/openai.py
@@@ -332,9 -343,9 +332,9 @@@ class OpenAIFileObject(BaseModel)
# Allow dictionary-style access to attributes
return getattr(self, key)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -409,13 -420,13 +409,13 @@@ class CreateBatchRequest(TypedDict, tot
"""
completion_window: Literal["24h"]
- endpoint: Literal["/v1/chat/completions", "/v1/embeddings", "/v1/completions"]
+ endpoint: Literal["/v1/chat/completions", "/v1/embeddings", "/v1/completions", "/v1/responses"]
input_file_id: str
- metadata: Optional[Dict[str, str]]
+ metadata: dict[str, str] | None
output_expires_after: FileExpiresAfter
- extra_headers: Optional[Dict[str, str]]
- extra_body: Optional[Dict[str, str]]
- timeout: Optional[float]
+ extra_headers: dict[str, str] | None
+ extra_body: dict[str, str] | None
+ timeout: float | None
class LiteLLMBatchCreateRequest(CreateBatchRequest, total=False):
diff --cc litellm/types/utils.py
index 3c77b06365c,4f824262867..1a022e58495
--- a/litellm/types/utils.py
+++ b/litellm/types/utils.py
@@@ -1285,8 -1292,8 +1285,8 @@@ class Message(SafeAttributeModel, OpenA
if reasoning_content is not None:
init_values["reasoning_content"] = reasoning_content
- super(Message, self).__init__(
+ super().__init__(
- **init_values, # type: ignore
+ **init_values,
**params,
)
@@@ -1334,9 -1342,9 +1334,9 @@@
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -1839,9 -1847,9 +1839,9 @@@ class StreamingChoices(OpenAIObject)
if logprobs is not None and isinstance(logprobs, dict):
self.logprobs = ChoiceLogprobs(**logprobs)
else:
- self.logprobs = logprobs # type: ignore
+ self.logprobs = logprobs
- def __contains__(self, key):
+ def __contains__(self, key) -> bool:
# Define custom behavior for the 'in' operator
return hasattr(self, key)
@@@ -1970,9 -1978,9 +1970,9 @@@ class ModelResponseStream(ModelResponse
# Allow dictionary-style access to attributes
return getattr(self, key)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -2069,9 -2077,9 +2069,9 @@@ class ModelResponse(ModelResponseBase)
# Allow dictionary-style access to attributes
return getattr(self, key)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -2162,9 -2170,9 +2162,9 @@@ class EmbeddingResponse(OpenAIObject)
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -2213,9 -2221,9 +2213,9 @@@ class TextChoices(OpenAIObject)
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -2295,13 -2303,13 +2295,13 @@@ class TextCompletionResponse(OpenAIObje
else:
usage = Usage()
- super(TextCompletionResponse, self).__init__(
+ super().__init__(
- id=id, # type: ignore
- object=object, # type: ignore
- created=created, # type: ignore
- model=model, # type: ignore
- choices=choices, # type: ignore
- usage=usage, # type: ignore
+ id=id,
+ object=object,
+ created=created,
+ model=model,
+ choices=choices,
+ usage=usage,
**params,
)
@@@ -2356,8 -2364,8 +2356,8 @@@ class ImageObject(OpenAIImage)
revised_prompt=None,
provider_specific_fields=None,
**kwargs,
- ):
+ ) -> None:
- super().__init__(b64_json=b64_json, url=url, revised_prompt=revised_prompt) # type: ignore
+ super().__init__(b64_json=b64_json, url=url, revised_prompt=revised_prompt)
if provider_specific_fields:
self.provider_specific_fields = provider_specific_fields
@@@ -2377,9 -2385,9 +2377,9 @@@
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -2413,7 -2421,7 +2413,7 @@@ from openai.types.images_response impor
class ImageResponse(OpenAIImageResponse, BaseLiteLLMOpenAIResponseObject):
_hidden_params: dict = {}
- usage: ImageUsage | None = None # type: ignore
- usage: Optional[ImageUsage] = None
++ usage: ImageUsage | None = None
"""
Users might use litellm with older python versions, we don't want this to break for them.
Happens when their OpenAIImageResponse has the old OpenAI usage class.
@@@ -2483,9 -2491,9 +2483,9 @@@
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -2510,16 -2518,16 +2510,16 @@@ class TranscriptionUsageTokensObject(Ba
class TranscriptionResponse(OpenAIObject):
- text: Optional[str] = None
- usage: Optional[Union[TranscriptionUsageDurationObject, TranscriptionUsageTokensObject]] = None
+ text: str | None = None
+ usage: TranscriptionUsageDurationObject | TranscriptionUsageTokensObject | None = None
_hidden_params: dict = {}
- _response_headers: Optional[dict] = None
+ _response_headers: dict | None = None
- def __init__(self, text=None):
+ def __init__(self, text=None) -> None:
- super().__init__(text=text) # type: ignore
+ super().__init__(text=text)
- def __contains__(self, key):
+ def __contains__(self, key) -> bool:
# Define custom behavior for the 'in' operator
return hasattr(self, key)
@@@ -2535,9 -2543,9 +2535,9 @@@
# Allow dictionary-style assignment of attributes
setattr(self, key, value)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -3807,9 -3817,9 +3809,9 @@@ class SelectTokenizerResponse(TypedDict
class LiteLLMFineTuningJob(FineTuningJob):
_hidden_params: dict = {}
- seed: int | None = None # type: ignore
- seed: Optional[int] = None
++ seed: int | None = None
- def __init__(self, **kwargs):
+ def __init__(self, **kwargs) -> None:
if "error" in kwargs and kwargs["error"] is not None:
# check if error is all None - if so, set error to None
if all(value is None for value in kwargs["error"].values()):
@@@ -3820,9 -3830,9 +3822,9 @@@
class LiteLLMBatch(Batch):
_hidden_params: dict = {}
- usage: Usage | None = None # type: ignore[assignment]
- usage: Optional[Usage] = None
++ usage: Usage | None = None
- def __contains__(self, key):
+ def __contains__(self, key) -> bool:
# Define custom behavior for the 'in' operator
return hasattr(self, key)
@@@ -3834,9 -3844,9 +3836,9 @@@
# Allow dictionary-style access to attributes
return getattr(self, key)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
@@@ -3867,9 -3877,9 +3869,9 @@@ class LiteLLMRealtimeStreamLoggingObjec
# Allow dictionary-style access to attributes
return getattr(self, key)
- def json(self, **kwargs): # type: ignore
+ def json(self, **kwargs):
try:
- return self.model_dump() # noqa
+ return self.model_dump()
except Exception:
# if using pydantic v1
return self.dict()
diff --cc litellm/types/videos/main.py
index 07acb0cf4ed,e5a54934638..3677cec3c8f
--- a/litellm/types/videos/main.py
+++ b/litellm/types/videos/main.py
@@@ -1,6 -1,6 +1,6 @@@
-from typing import Any, Dict, List, Literal, Optional
+from typing import Any, Literal
- from openai.types.audio.transcription_create_params import FileTypes # type: ignore
+ from openai.types.audio.transcription_create_params import FileTypes
from pydantic import BaseModel
from typing_extensions import TypedDict
diff --cc ruff-strict-budget.json
index b5ffdf03de7,d03881416f0..43b3bab97ea
--- a/ruff-strict-budget.json
+++ b/ruff-strict-budget.json
@@@ -1,39 -1,39 +1,39 @@@
{
"ANN001": {
- "limit": 2849
+ "limit": 3132
},
"ANN002": {
- "limit": 65
+ "limit": 71
},
"ANN003": {
- "limit": 776
+ "limit": 840
},
"ANN201": {
- "limit": 2137
- "limit": 1961
++ "limit": 2039
},
"ANN202": {
- "limit": 941
- "limit": 868
++ "limit": 871
},
"ANN204": {
- "limit": 724
- "limit": 669
++ "limit": 715
},
"ANN205": {
- "limit": 127
+ "limit": 115
},
"ANN206": {
- "limit": 121
+ "limit": 133
},
"ANN401": {
- "limit": 1848
+ "limit": 1861
},
"ASYNC230": {
- "limit": 14
+ "limit": 11
},
"B004": {
- "limit": 4
+ "limit": 2
},
"B006": {
- "limit": 188
+ "limit": 178
},
"B008": {
"limit": 505
@@@ -60,58 -60,58 +60,58 @@@
"limit": 0
},
"BLE001": {
- "limit": 2897
+ "limit": 2926
},
"C401": {
- "limit": 11
+ "limit": 8
},
"C404": {
- "limit": 4
+ "limit": 1
},
"C405": {
- "limit": 21
+ "limit": 19
},
"C408": {
- "limit": 14
+ "limit": 11
},
"C414": {
- "limit": 7
+ "limit": 4
},
"C419": {
- "limit": 4
+ "limit": 1
},
"C901": {
- "limit": 310
+ "limit": 315
},
"D419": {
- "limit": 9
+ "limit": 6
},
"DTZ001": {
- "limit": 5
+ "limit": 2
},
"DTZ003": {
- "limit": 33
+ "limit": 26
},
"DTZ005": {
- "limit": 241
+ "limit": 233
},
"DTZ006": {
- "limit": 13
+ "limit": 10
},
"DTZ007": {
- "limit": 23
+ "limit": 19
},
"DTZ011": {
- "limit": 6
+ "limit": 3
},
"EXE001": {
- "limit": 7
+ "limit": 4
},
"EXE002": {
- "limit": 6
+ "limit": 3
},
"F401": {
- "limit": 23
+ "limit": 20
},
"FURB136": {
"limit": 0
@@@ -162,13 -162,13 +162,13 @@@
"limit": 0
},
"PLC0414": {
- "limit": 35
+ "limit": 46
},
"PLR0124": {
- "limit": 4
+ "limit": 1
},
"PLR0206": {
- "limit": 4
+ "limit": 1
},
"PLR0402": {
"limit": 0
@@@ -189,22 -189,22 +189,22 @@@
"limit": 0
},
"PLW0127": {
- "limit": 38
+ "limit": 57
},
"PLW0133": {
- "limit": 4
+ "limit": 1
},
"PLW0602": {
- "limit": 230
+ "limit": 215
},
"PLW0603": {
- "limit": 193
+ "limit": 191
},
"PLW1508": {
- "limit": 198
+ "limit": 190
},
"PLW1510": {
- "limit": 5
+ "limit": 2
},
"PYI030": {
"limit": 0
@@@ -228,13 -228,13 +228,13 @@@
"limit": 0
},
"RUF012": {
- "limit": 164
+ "limit": 241
},
"RUF015": {
- "limit": 11
+ "limit": 8
},
"RUF019": {
- "limit": 41
+ "limit": 38
},
"RUF022": {
"limit": 0
@@@ -249,28 -249,28 +249,28 @@@
"limit": 0
},
"RUF059": {
- "limit": 73
+ "limit": 67
},
"RUF100": {
- "limit": 480
+ "limit": 100
},
"S110": {
- "limit": 236
+ "limit": 220
},
"S112": {
- "limit": 24
+ "limit": 22
},
"SIM101": {
- "limit": 61
+ "limit": 58
},
"SIM102": {
- "limit": 324
- "limit": 314
++ "limit": 322
},
"SIM103": {
- "limit": 129
+ "limit": 119
},
"SIM113": {
- "limit": 6
+ "limit": 3
},
"SIM114": {
"limit": 0
@@@ -306,22 -306,22 +306,22 @@@
"limit": 0
},
"TID251": {
- "limit": 0
+ "limit": 1248
},
"TRY002": {
- "limit": 547
- "limit": 526
++ "limit": 528
},
"TRY004": {
- "limit": 97
+ "limit": 96
},
"TRY201": {
- "limit": 420
+ "limit": 407
},
"TRY203": {
- "limit": 121
+ "limit": 113
},
"TRY300": {
- "limit": 879
+ "limit": 860
},
"UP006": {
"limit": 0