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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_decrease_anys_opus5_0826
mateo-berri47d8ce6d1006
diff --cc basedpyright-code-budget.jsonindex 6463000c69d,122bd82c657..9ec7f114712--- a/basedpyright-code-budget.json+++ b/basedpyright-code-budget.json@@@ -1,18 -1,18 +1,18 @@@{"reportAny": {- "limit": 17259- "limit": 18483++ "limit": 17271},"reportArgumentType": {- "limit": 2551- "limit": 2557++ "limit": 2544},"reportAssignmentType": {- "limit": 320+ "limit": 319},"reportAttributeAccessIssue": {- "limit": 483+ "limit": 480},"reportCallIssue": {- "limit": 113+ "limit": 112},"reportConstantRedefinition": {"limit": 40@@@ -24,13 -24,13 +24,13 @@@"limit": 19},"reportExplicitAny": {- "limit": 5482- "limit": 5960++ "limit": 5486},"reportFunctionMemberAccess": {"limit": 7},"reportGeneralTypeIssues": {- "limit": 150- "limit": 105++ "limit": 101},"reportIncompatibleMethodOverride": {"limit": 56@@@ -54,10 -54,10 +54,10 @@@"limit": 0},"reportMissingParameterType": {- "limit": 5659+ "limit": 5658},"reportMissingTypeArgument": {- "limit": 15427- "limit": 15482++ "limit": 15425},"reportMissingTypeStubs": {"limit": 40@@@ -105,13 -105,13 +105,13 @@@"limit": 109},"reportUnknownMemberType": {- "limit": 38746- "limit": 38779++ "limit": 38721},"reportUnknownParameterType": {- "limit": 19780- "limit": 19827++ "limit": 19778},"reportUnknownVariableType": {- "limit": 30299- "limit": 30348++ "limit": 30292},"reportUnnecessaryCast": {"limit": 117@@@ -123,7 -123,7 +123,7 @@@"limit": 5},"reportUnnecessaryIsInstance": {-- "limit": 831++ "limit": 829},"reportUntypedBaseClass": {"limit": 0diff --cc enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.pyindex 87055ec1f02,5ec482c385a..b2eda76f9ae--- a/enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.py+++ b/enterprise/litellm_enterprise/proxy/management_endpoints/project_endpoints.py@@@ -37,18 -29,27 +37,20 @@@ from litellm.repositories.verification_if TYPE_CHECKING:from prisma import models as prisma_models- from prisma.actions import (- LiteLLM_ProjectTableActions,- LiteLLM_TeamTableActions,- LiteLLM_VerificationTokenActions,- )+ from litellm import Router+router = APIRouter()+_OBJECT_PERMISSION_PAYLOAD: Final = TypeAdapter(dict[str, object])-def _team_table(prisma_client: PrismaClient) -> "LiteLLM_TeamTableActions[prisma_models.LiteLLM_TeamTable]":- team_table: LiteLLM_TeamTableActions[prisma_models.LiteLLM_TeamTable] = prisma_client.db.litellm_teamtable- return team_table+def _team_table(prisma_client: PrismaClient) -> TableActions["prisma_models.LiteLLM_TeamTable"]:+ return TeamRepository(prisma_client).table-def _project_table(prisma_client: PrismaClient) -> "LiteLLM_ProjectTableActions[prisma_models.LiteLLM_ProjectTable]":- project_table: LiteLLM_ProjectTableActions[prisma_models.LiteLLM_ProjectTable] = (- prisma_client.db.litellm_projecttable- )- return project_table++def _project_table(prisma_client: PrismaClient) -> TableActions["prisma_models.LiteLLM_ProjectTable"]:+ return ProjectRepository(prisma_client).tabledef _verification_token_table(diff --cc litellm/llms/soniox/common_utils.pyindex b866237c0e1,e2b18736e0e..cb33f0b8996--- a/litellm/llms/soniox/common_utils.py+++ b/litellm/llms/soniox/common_utils.py@@@ -2,14 -2,15 +2,18 @@@Shared utilities for the Soniox provider (https://soniox.com)."""-from typing import Any, Final+from collections.abc import Mapping, Sequence- from dataclasses import dataclass+from typing import Final, TypeAlias+ from litellm.litellm_core_utils.audio_utils.subtitle_utils import (+ SubtitleToken,+ render_subtitle_tokens_as_srt,+ render_subtitle_tokens_as_vtt,+ )from litellm.llms.base_llm.chat.transformation import BaseLLMException+SonioxToken: TypeAlias = Mapping[str, object]+# Soniox API base URL.SONIOX_API_BASE: Final[str] = "https://api.soniox.com"@@@ -121,153 -114,25 +125,29 @@@ def render_soniox_tokens(tokens: Sequenreturn "".join(text_parts)- # ---------------------------------------------------------------------------- # SRT / VTT subtitle rendering- # ----------------------------------------------------------------------------def _soniox_token_to_subtitle_token(token: dict[str, Any]) -> SubtitleToken:++def _token_speaker(value: object) -> str | int | None:++ return value if isinstance(value, str | int) else None+- # Maximum number of tokens to group into a single subtitle cue.- _CUE_MAX_TOKENS: Final[int] = 15+- # Maximum duration (in ms) for a single cue before forcing a break.- _CUE_MAX_DURATION_MS: Final[int] = 5000--- def _format_timestamp_srt(ms: int) -> str:- """Format milliseconds as SRT timestamp: HH:MM:SS,mmm"""- ms = max(ms, 0)- hours: Final = ms // 3_600_000- ms %= 3_600_000- minutes: Final = ms // 60_000- ms %= 60_000- seconds: Final = ms // 1_000- millis: Final = ms % 1_000- return f"{hours:02d}:{minutes:02d}:{seconds:02d},{millis:03d}"--- def _format_timestamp_vtt(ms: int) -> str:- """Format milliseconds as VTT timestamp: HH:MM:SS.mmm"""- ms = max(ms, 0)- hours: Final = ms // 3_600_000- ms %= 3_600_000- minutes: Final = ms // 60_000- ms %= 60_000- seconds: Final = ms // 1_000- millis: Final = ms % 1_000- return f"{hours:02d}:{minutes:02d}:{seconds:02d}.{millis:03d}"--- @dataclass(frozen=True, slots=True)- class _SubtitleCue:- start_ms: int- end_ms: int- text: str--- def _group_tokens_into_cues(- tokens: Sequence[SonioxToken],- ) -> list[_SubtitleCue]:- """- Group Soniox tokens into subtitle cues.-- Each cue has:- - start_ms: int- - end_ms: int- - text: str-- Grouping heuristics:- - A new cue starts when token count exceeds _CUE_MAX_TOKENS.- - A new cue starts when duration exceeds _CUE_MAX_DURATION_MS.- - A new cue starts when the speaker changes (if diarization is on).- - Tokens without timestamps are appended to the current cue.- """- cues: Final[list[_SubtitleCue]] = []- current_tokens: list[str] = []- current_start: int | None = None- current_end: int | None = None- current_speaker: object = None-- def _flush() -> None:- if current_tokens and current_start is not None:- text: Final = "".join(current_tokens).strip()- if text:- cues.append(- _SubtitleCue(- start_ms=current_start,- end_ms=(current_end if current_end is not None else current_start),- text=text,- )- )-- for token in tokens:- start_ms = _token_milliseconds(token.get("start_ms"))- end_ms = _token_milliseconds(token.get("end_ms"))- text = _token_text(token.get("text", ""))- speaker = token.get("speaker")-- # Skip tokens with no timestamp data entirely if we have no cue started- if start_ms is None and current_start is None:- continue-- # Speaker change forces a new cue- if speaker is not None and speaker != current_speaker:- _flush()- current_tokens = []- current_start = start_ms- current_end = end_ms- current_speaker = speaker- current_tokens.append(text)- continue-- # Duration or token count exceeded -> flush- should_break = False- if (- len(current_tokens) >= _CUE_MAX_TOKENS- or current_start is not None- and start_ms is not None- and (start_ms - current_start) >= _CUE_MAX_DURATION_MS- ):- should_break = True-- if should_break:- _flush()- current_tokens = []- current_start = start_ms- current_end = end_ms- current_tokens.append(text)- else:- if current_start is None:- current_start = start_ms- if end_ms is not None:- current_end = end_ms- current_tokens.append(text)-- _flush()- return cues++def _soniox_token_to_subtitle_token(token: SonioxToken) -> SubtitleToken:+ return SubtitleToken(- text=token.get("text", ""),- start_ms=token.get("start_ms"),- end_ms=token.get("end_ms"),- speaker=token.get("speaker"),++ text=_token_text(token.get("text", "")),++ start_ms=_token_milliseconds(token.get("start_ms")),++ end_ms=_token_milliseconds(token.get("end_ms")),++ speaker=_token_speaker(token.get("speaker")),+ )-def render_soniox_tokens_as_srt(tokens: list[dict[str, Any]]) -> str:+def render_soniox_tokens_as_srt(tokens: Sequence[SonioxToken]) -> str:"""Render Soniox tokens as SRT (SubRip) subtitle format.Returns an empty string if no tokens have timestamp data."""- cues: Final = _group_tokens_into_cues(tokens)- if not cues:- return ""-- lines: Final[list[str]] = []- for idx, cue in enumerate(cues, start=1):- start = _format_timestamp_srt(cue.start_ms)- end = _format_timestamp_srt(cue.end_ms)- lines.append(str(idx))- lines.append(f"{start} --> {end}")- lines.append(cue.text)- lines.append("") # blank line between cues-- return "\n".join(lines)+ return render_subtitle_tokens_as_srt(tuple(_soniox_token_to_subtitle_token(token) for token in tokens))-def render_soniox_tokens_as_vtt(tokens: list[dict[str, Any]]) -> str:+def render_soniox_tokens_as_vtt(tokens: Sequence[SonioxToken]) -> str:"""Render Soniox tokens as WebVTT subtitle format.diff --cc ruff-strict-budget.jsonindex 44510a0e35d,0418eeaac8f..cf04d5bf61c--- a/ruff-strict-budget.json+++ b/ruff-strict-budget.json@@@ -9,13 -9,13 +9,13 @@@"limit": 827},"ANN201": {- "limit": 2008- "limit": 2011++ "limit": 2007},"ANN202": {- "limit": 847+ "limit": 846},"ANN204": {- "limit": 706+ "limit": 704},"ANN205": {"limit": 112@@@ -24,7 -24,7 +24,7 @@@"limit": 133},"ANN401": {- "limit": 903- "limit": 1153++ "limit": 904},"ASYNC230": {"limit": 11diff --cc type-discipline-budget.jsonindex e5a48872a98,a7dec330a26..ccb4f0698bf--- a/type-discipline-budget.json+++ b/type-discipline-budget.json@@@ -1,9 -1,9 +1,9 @@@{"LIT001": {- "limit": 22708- "limit": 22727++ "limit": 22705},"LIT002": {- "limit": 26843- "limit": 26873++ "limit": 26854},"LIT003": {"limit": 269@@@ -27,12 -27,12 +27,12 @@@"limit": 0},"LIT010": {- "limit": 16616+ "limit": 16565},"LIT011": {- "limit": 5579- "limit": 5583++ "limit": 5580},"LIT012": {-- "limit": 4509++ "limit": 4508}}