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 branch 'litellm_internal_staging' into feature/improve-gigachat-provider
KnyazSh2d75d24c3436
diff --cc litellm/litellm_core_utils/get_litellm_params.pyindex fd82ad72d93,352e55e9c23..b70eadb4c18--- a/litellm/litellm_core_utils/get_litellm_params.py+++ b/litellm/litellm_core_utils/get_litellm_params.py@@@ -34,11 -34,10 +34,13 @@@ OPTIONAL_KWARGS_KEYS = frozenset"aws_external_id","aws_bedrock_runtime_endpoint","aws_bedrock_project_id",+ "gigachat_scope",+ "gigachat_auth_url",+ "gigachat_access_token","tpm","rpm",+ "itpm",+ "otpm","use_xai_oauth",})diff --cc litellm/passthrough/main.pyindex 75ed91c1d3b,cdeedd7b522..829aa769491--- a/litellm/passthrough/main.py+++ b/litellm/passthrough/main.py@@@ -350,27 -166,26 +350,26 @@@ def llm_passthrough_routemethod: str,endpoint: str,model: str,- custom_llm_provider: Optional[str] = None,- api_base: Optional[str] = None,- api_key: Optional[str] = None,- request_query_params: Optional[dict] = None,- request_headers: Optional[dict] = None,- content: Optional[Any] = None,- data: Optional[dict] = None,- files: Optional[RequestFiles] = None,- json: Optional[Any] = None,- params: Optional[QueryParamTypes] = None,- cookies: Optional[CookieTypes] = None,- client: Optional[Union[HTTPHandler, AsyncHTTPHandler]] = None,+ custom_llm_provider: str | None = None,+ api_base: str | None = None,+ api_key: str | None = None,+ request_query_params: dict | None = None,+ request_headers: dict | None = None,- allm_passthrough_route: bool = False,+ content: Any | None = None,+ data: dict | None = None,+ files: RequestFiles | None = None,+ json: Any | None = None,+ params: QueryParamTypes | None = None,+ cookies: CookieTypes | None = None,+ client: HTTPHandler | AsyncHTTPHandler | None = None,**kwargs,-) -> Union[- httpx.Response,- Coroutine[Any, Any, httpx.Response],- Coroutine[Any, Any, Union[httpx.Response, AsyncGenerator[Any, Any]]],- Generator[Any, Any, Any],- AsyncGenerator[Any, Any],-]:+) -> (+ httpx.Response+ | Coroutine[Any, Any, httpx.Response]+ | Coroutine[Any, Any, httpx.Response | AsyncGenerator[Any, Any]]+ | Generator[Any, Any, Any]+ | AsyncGenerator[Any, Any]+):"""Pass through requests to the LLM APIs.@@@ -382,9 -197,9 +381,9 @@@from litellm.types.utils import LlmProvidersfrom litellm.utils import ProviderConfigManager- _is_async = allm_passthrough_route+ _is_async = bool(kwargs.get("allm_passthrough_route", False))- litellm_logging_obj = cast("LiteLLMLoggingObj", kwargs.get("litellm_logging_obj"))+ litellm_logging_obj = cast(LiteLLMLoggingObj, kwargs.get("litellm_logging_obj"))model, custom_llm_provider, api_key, api_base = get_llm_provider(model=model,diff --cc tests/test_litellm/passthrough/test_passthrough_main.pyindex 3600aeed59e,6e9c75e085a..7f12829c1a5--- a/tests/test_litellm/passthrough/test_passthrough_main.py+++ b/tests/test_litellm/passthrough/test_passthrough_main.py@@@ -708,17 -706,98 +708,93 @@@ async def test_allm_passthrough_route_4patch.object(async_client.client, "send", mock_send),patch.object(async_client.client, "build_request", mock_build_request),):- result = await allm_passthrough_route(- model="azure/gpt-4",- endpoint="openai/deployments/gpt-4/responses",- method="POST",- custom_llm_provider="azure",- api_base="https://my-azure.openai.azure.com",- api_key="fake-azure-key",- json={"model": "gpt-4", "input": "hello", "stream": True},- client=async_client,- litellm_logging_obj=mock_logging_obj,- )-- # result is an async generator — consuming it must raise, not silently yield error bytes- chunks = []with pytest.raises(httpx.HTTPStatusError) as exc_info:- async for chunk in result: # type: ignore[union-attr]- chunks.append(chunk)+ await allm_passthrough_route(+ model="azure/gpt-4",+ endpoint="openai/deployments/gpt-4/responses",+ method="POST",+ custom_llm_provider="azure",+ api_base="https://my-azure.openai.azure.com",+ api_key="fake-azure-key",+ json={"model": "gpt-4", "input": "hello", "stream": True},+ client=async_client,+ litellm_logging_obj=mock_logging_obj,+ )assert exc_info.value.response.status_code == 429+ assert len(chunks) == 0, "No chunks should be yielded before the 429 raises"+++ def test_llm_passthrough_route_propagates_allm_passthrough_route_to_logging_obj():+ """+ Regression guard for LIT-4192: `allm_passthrough_route` sets+ `kwargs["allm_passthrough_route"] = True` on the async entrypoint, and the+ inner `llm_passthrough_route` must let that flag flow through+ `get_litellm_params(**kwargs)` and land in the logging object's+ `litellm_params`. Without that, `_is_sync_litellm_request` misclassifies+ the request as sync and fires duplicate success callbacks.+ """+ import asyncio++ from litellm.litellm_core_utils.litellm_logging import Logging as LitellmLogging++ client = HTTPHandler()++ mock_provider_config = MagicMock()+ mock_provider_config.get_complete_url.return_value = (+ httpx.URL("https://bedrock-runtime.us-east-1.amazonaws.com/model/foo/converse"),+ "https://bedrock-runtime.us-east-1.amazonaws.com",+ )+ mock_provider_config.get_api_key.return_value = "fake-key"+ mock_provider_config.validate_environment.return_value = {}+ mock_provider_config.sign_request.return_value = ({}, None)+ mock_provider_config.is_streaming_request.return_value = False++ captured_litellm_params: dict = {}++ def _capture_update_env(*args, **kwargs):+ captured_litellm_params.clear()+ captured_litellm_params.update(kwargs.get("litellm_params") or {})++ mock_logging_obj = MagicMock()+ mock_logging_obj.update_environment_variables.side_effect = _capture_update_env++ with (+ patch(+ "litellm.utils.ProviderConfigManager.get_provider_passthrough_config",+ return_value=mock_provider_config,+ ),+ patch(+ "litellm.litellm_core_utils.get_llm_provider_logic.get_llm_provider",+ return_value=(+ "bedrock/foo",+ "bedrock",+ "fake-key",+ "https://bedrock-runtime.us-east-1.amazonaws.com",+ ),+ ),+ patch.object(+ client.client,+ "send",+ return_value=MagicMock(status_code=200, json=lambda: {}),+ ),+ patch.object(client.client, "build_request"),+ ):+ result = llm_passthrough_route(+ model="bedrock/foo",+ endpoint="model/foo/converse",+ method="POST",+ custom_llm_provider="bedrock",+ api_base="https://bedrock-runtime.us-east-1.amazonaws.com",+ api_key="fake-key",+ json={"messages": []},+ client=client,+ litellm_logging_obj=mock_logging_obj,+ allm_passthrough_route=True,+ )++ if asyncio.iscoroutine(result):+ result.close()++ assert captured_litellm_params.get("allm_passthrough_route") is True+ assert LitellmLogging._is_sync_litellm_request(captured_litellm_params) is False