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' of https://github.com/BerriAI/litellm into litellm_decrease_anys_opus5_r2

mateo-berri4d19a889fbaf
diff --cc basedpyright-code-budget.json
index 45af8e1d7c9,229d1eca3e8..72b8066ade6
--- a/basedpyright-code-budget.json
+++ b/basedpyright-code-budget.json
@@@ -1,9 -1,9 +1,9 @@@
{
"reportAny": {
- "limit": 15468
- "limit": 16171
++ "limit": 14765
},
"reportArgumentType": {
- "limit": 2218
- "limit": 2224
++ "limit": 2216
},
"reportAssignmentType": {
"limit": 319
@@@ -24,7 -24,7 +24,7 @@@
"limit": 19
},
"reportExplicitAny": {
- "limit": 4846
- "limit": 5199
++ "limit": 4493
},
"reportFunctionMemberAccess": {
"limit": 7
@@@ -42,7 -42,7 +42,7 @@@
"limit": 12
},
"reportIndexIssue": {
- "limit": 30
- "limit": 35
++ "limit": 25
},
"reportInvalidTypeForm": {
"limit": 34
@@@ -54,10 -54,10 +54,10 @@@
"limit": 0
},
"reportMissingParameterType": {
- "limit": 5609
- "limit": 5611
++ "limit": 5607
},
"reportMissingTypeArgument": {
- "limit": 15330
- "limit": 15350
++ "limit": 15310
},
"reportMissingTypeStubs": {
"limit": 40
@@@ -105,13 -105,13 +105,13 @@@
"limit": 109
},
"reportUnknownMemberType": {
- "limit": 38418
- "limit": 38468
++ "limit": 38368
},
"reportUnknownParameterType": {
- "limit": 19649
- "limit": 19665
++ "limit": 19633
},
"reportUnknownVariableType": {
- "limit": 29987
- "limit": 30066
++ "limit": 29908
},
"reportUnnecessaryCast": {
"limit": 111
@@@ -141,6 -141,6 +141,6 @@@
"limit": 543
},
"reportUnusedVariable": {
- "limit": 138
- "limit": 139
++ "limit": 137
}
}
diff --cc litellm/litellm_core_utils/token_counter.py
index 9e8976940e6,c350bc5569e..3732ffd734c
--- a/litellm/litellm_core_utils/token_counter.py
+++ b/litellm/litellm_core_utils/token_counter.py
@@@ -698,8 -693,28 +698,28 @@@ def _count_document_tokens
)
+ def _count_file_tokens(
+ file_value: object,
+ count_function: TokenCounterFunction,
+ use_default_image_token_count: bool,
+ ) -> int:
+ """An OpenAI `file` block is the chat-completions spelling of a document, so it prices like one."""
+ if not isinstance(file_value, Mapping):
+ return 0
+ filename: Final = file_value.get("filename")
+ file_data: Final = file_value.get("file_data")
+ name_tokens: Final = count_function(filename) if isinstance(filename, str) and filename else 0
+ if not isinstance(file_data, str) or not file_data:
+ return name_tokens
+ return name_tokens + calculate_img_tokens(
+ data=file_data,
+ mode="auto",
+ use_default_image_token_count=use_default_image_token_count,
+ )
+
+
def _count_anthropic_content(
- content: Mapping[str, Any],
+ content: Mapping[str, object],
count_function: TokenCounterFunction,
use_default_image_token_count: bool,
default_token_count: int | None,
diff --cc ruff-strict-budget.json
index caa8eef252a,1e855ea1b71..569c23cd03f
--- a/ruff-strict-budget.json
+++ b/ruff-strict-budget.json
@@@ -1,6 -1,6 +1,6 @@@
{
"ANN001": {
- "limit": 2993
- "limit": 2995
++ "limit": 2991
},
"ANN002": {
"limit": 71
@@@ -12,10 -12,10 +12,10 @@@
"limit": 2002
},
"ANN202": {
- "limit": 843
- "limit": 845
++ "limit": 841
},
"ANN204": {
- "limit": 696
- "limit": 698
++ "limit": 694
},
"ANN205": {
"limit": 112
@@@ -24,7 -24,7 +24,7 @@@
"limit": 133
},
"ANN401": {
- "limit": 487
- "limit": 587
++ "limit": 387
},
"ASYNC230": {
"limit": 11
@@@ -117,7 -117,7 +117,7 @@@
"limit": 1
},
"PERF102": {
- "limit": 22
- "limit": 23
++ "limit": 21
},
"PERF401": {
"limit": 12
@@@ -168,7 -168,7 +168,7 @@@
"limit": 3
},
"RET504": {
- "limit": 174
- "limit": 175
++ "limit": 173
},
"RUF012": {
"limit": 239
@@@ -198,7 -198,7 +198,7 @@@
"limit": 56
},
"SIM102": {
- "limit": 312
- "limit": 314
++ "limit": 310
},
"SIM103": {
"limit": 119
@@@ -231,7 -231,7 +231,7 @@@
"limit": 5
},
"TID251": {
- "limit": 1096
- "limit": 1108
++ "limit": 1084
},
"TRY002": {
"limit": 524
diff --cc type-discipline-budget.json
index 57ee0606dca,ab34775c460..92c0509b072
--- a/type-discipline-budget.json
+++ b/type-discipline-budget.json
@@@ -1,9 -1,9 +1,9 @@@
{
"LIT001": {
- "limit": 22462
- "limit": 22521
++ "limit": 22403
},
"LIT002": {
- "limit": 26800
- "limit": 26820
++ "limit": 26780
},
"LIT003": {
"limit": 269
@@@ -27,10 -27,10 +27,10 @@@
"limit": 0
},
"LIT010": {
- "limit": 16529
- "limit": 16546
++ "limit": 16512
},
"LIT011": {
- "limit": 5556
- "limit": 5575
++ "limit": 5537
},
"LIT012": {
"limit": 4495