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
KnyazShc5e8a498b28a
diff --cc litellm/proxy/_types.pyindex c63c7cf3a91,feab3b04a5e..05a9ea53b59--- a/litellm/proxy/_types.py+++ b/litellm/proxy/_types.py@@@ -413,7 -419,7 +419,8 @@@ class LiteLLMRoutes(enum.Enum)"/vllm","/mistral","/milvus",+ "/gigachat",+ "/watsonx",]#########################################################diff --cc litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.pyindex 46d8b32369f,7c3a6f19013..7a0403194ab--- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py+++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py@@@ -2427,256 -2435,87 +2436,342 @@@ def create_generic_websocket_passthroug)[email protected]_route(+ "/gigachat/{endpoint:path}",+ methods=["GET", "POST", "PUT", "DELETE", "PATCH"],+ tags=["Gigachat Pass-through", "pass-through"],+)+async def gigachat_proxy_route(+ endpoint: str,+ request: Request,+ fastapi_response: Response,+ user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),+):+ """+ [Docs](https://docs.litellm.ai/docs/pass_through/gigachat)+ """+ from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing+ from litellm.proxy.proxy_server import (+ general_settings,+ llm_router,+ proxy_config,+ proxy_logging_obj,+ select_data_generator,+ user_api_base,+ user_max_tokens,+ user_model,+ user_request_timeout,+ user_temperature,+ version,+ )++ ## check for streaming+ request_body = await get_request_body(request)+ is_router_model = False++ model = request_body.get("model")+ if model:+ is_router_model = is_passthrough_request_using_router_model(+ request_body, llm_router+ )+ elif any(word in endpoint for word in ("completions", "embeddings")):+ raise HTTPException(+ status_code=400, detail={"error": "Model is required in request body"}+ )++ # If router model, use dedicated router passthrough handler+ # This uses the same common processing path as non-router models+ if model and is_router_model and llm_router:+ return await handle_gigachat_passthrough_router_model(+ model=model,+ endpoint=endpoint,+ request=request,+ request_body=request_body,+ fastapi_response=fastapi_response,+ llm_router=llm_router,+ user_api_key_dict=user_api_key_dict,+ proxy_logging_obj=proxy_logging_obj,+ general_settings=general_settings,+ proxy_config=proxy_config,+ select_data_generator=select_data_generator,+ user_model=user_model,+ user_temperature=user_temperature,+ user_request_timeout=user_request_timeout,+ user_max_tokens=user_max_tokens,+ user_api_base=user_api_base,+ version=version,+ )++ # Fall back to existing implementation for direct GigaChat models+ verbose_proxy_logger.debug(+ f"Gigachat passthrough: Using direct Gigachat model '{model}' for endpoint '{endpoint}'"+ )++ data: Dict[str, Any] = {}++ data["method"] = request.method+ data["endpoint"] = endpoint+ data["json"] = request_body+ data["custom_llm_provider"] = "gigachat"++ client = get_async_httpx_client( # type: ignore+ llm_provider=LlmProviders.GIGACHAT,+ params={+ "timeout": httpx.Timeout(timeout=600.0, connect=5.0),+ "ssl_verify": False,+ },+ )+ data["http_client"] = client++ base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)++ try:+ result = await base_llm_response_processor.base_passthrough_process_llm_request(+ request=request,+ fastapi_response=fastapi_response,+ user_api_key_dict=user_api_key_dict,+ proxy_logging_obj=proxy_logging_obj,+ llm_router=llm_router,+ general_settings=general_settings,+ proxy_config=proxy_config,+ select_data_generator=select_data_generator,+ model=model,+ user_model=user_model,+ user_temperature=user_temperature,+ user_request_timeout=user_request_timeout,+ user_max_tokens=user_max_tokens,+ user_api_base=user_api_base,+ version=version,+ )++ return result+ except Exception as e:+ raise await base_llm_response_processor._handle_llm_api_exception(+ e=e,+ user_api_key_dict=user_api_key_dict,+ proxy_logging_obj=proxy_logging_obj,+ )+++async def handle_gigachat_passthrough_router_model(+ model: str,+ endpoint: str,+ request: Request,+ request_body: dict,+ fastapi_response: Response,+ llm_router: litellm.Router,+ user_api_key_dict: UserAPIKeyAuth,+ proxy_logging_obj,+ general_settings: dict,+ proxy_config,+ select_data_generator,+ user_model: Optional[str],+ user_temperature: Optional[float],+ user_request_timeout: Optional[float],+ user_max_tokens: Optional[int],+ user_api_base: Optional[str],+ version: Optional[str],+) -> Union[Response, StreamingResponse]:+ """+ Handle Gigachat passthrough for router models (models defined in config.yaml).++ Uses the same common processing path as non-router models to ensure+ metadata and hooks are properly initialized.++ Args:+ model: The router model name (e.g., "gigachat/gigachat-2")+ endpoint: The Gigachat endpoint path (e.g., "/chat/completions")+ request: The FastAPI request object+ request_body: The parsed request body+ llm_router: The LiteLLM router instance+ user_api_key_dict: The user API key authentication dictionary+ (additional args for common processing)++ Returns:+ Response or StreamingResponse depending on endpoint type+ """+ from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing++ # Detect streaming based on request body+ is_streaming = request_body.get("stream", False)++ data: Dict[str, Any] = await _read_request_body(request=request)+ if user_api_key_dict is not None:+ if data.get("metadata") is None:+ data["metadata"] = {}+ if (+ hasattr(user_api_key_dict, "user_id")+ and user_api_key_dict.user_id is not None+ ):+ data["metadata"]["user_api_key_user_id"] = user_api_key_dict.user_id+ if (+ hasattr(user_api_key_dict, "team_id")+ and user_api_key_dict.team_id is not None+ ):+ data["metadata"]["user_api_key_team_id"] = user_api_key_dict.team_id+ if (+ hasattr(user_api_key_dict, "org_id")+ and user_api_key_dict.org_id is not None+ ):+ data["metadata"]["user_api_key_org_id"] = user_api_key_dict.org_id+ if (+ hasattr(user_api_key_dict, "agent_id")+ and user_api_key_dict.agent_id is not None+ ):+ data["metadata"]["agent_id"] = user_api_key_dict.agent_id++ verbose_proxy_logger.debug(+ f"Gigachat router passthrough: model='{model}', endpoint='{endpoint}', streaming={is_streaming}"+ )++ # Use the common processing path (same as non-router models)+ # This ensures all metadata, hooks, and logging are properly initialized++ data["model"] = model+ data["method"] = request.method+ data["endpoint"] = endpoint+ data["json"] = request_body+ data["custom_llm_provider"] = "gigachat"++ # Remove sensitive keys from data+ keys = [+ "gigachat_auth_url",+ "gigachat_access_token",+ "gigachat_scope",+ "api_base",+ "api_key",+ ]+ for key in keys:+ data.pop(key, None)++ client = get_async_httpx_client( # type: ignore+ llm_provider=LlmProviders.GIGACHAT,+ params={+ "timeout": httpx.Timeout(timeout=600.0, connect=5.0),+ "ssl_verify": False,+ },+ )++ data["http_client"] = client+ base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)++ # Use the common passthrough processing to handle metadata and hooks+ # This also handles all response formatting (streaming/non-streaming) and exceptions+ try:+ result = await base_llm_response_processor.base_passthrough_process_llm_request(+ request=request,+ fastapi_response=fastapi_response,+ user_api_key_dict=user_api_key_dict,+ proxy_logging_obj=proxy_logging_obj,+ llm_router=llm_router,+ general_settings=general_settings,+ proxy_config=proxy_config,+ select_data_generator=select_data_generator,+ model=model,+ user_model=user_model,+ user_temperature=user_temperature,+ user_request_timeout=user_request_timeout,+ user_max_tokens=user_max_tokens,+ user_api_base=user_api_base,+ version=version,+ )++ if isinstance(result, StreamingResponse):+ if result.headers.get("Content-Type") is None:+ result.headers["Content-Type"] = "text/event-stream; charset=utf-8"+ return result++ return result+ except Exception as e:+ # Use common exception handling+ raise await base_llm_response_processor._handle_llm_api_exception(+ e=e,+ user_api_key_dict=user_api_key_dict,+ proxy_logging_obj=proxy_logging_obj,+ )+++++ @router.api_route(+ "/watsonx/{endpoint:path}",+ methods=["GET", "POST", "PUT", "DELETE", "PATCH"],+ tags=["Watsonx Pass-through", "pass-through"],+ )+ async def watsonx_proxy_route(+ endpoint: str,+ request: Request,+ fastapi_response: Response,+ user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),+ ):+ """+ Watsonx pass-through endpoint.+ Allows using Watsonx APIs with automatic IAM token management and version parameter injection.++ Example:+ POST /watsonx/ml/v1/text/tokenization+ POST /watsonx/ml/v1/text/generation+ """+ # Direct passthrough with WatsonxPassthroughConfig+ from litellm.types.utils import LlmProviders+ from litellm.utils import ProviderConfigManager++ provider_config = ProviderConfigManager.get_provider_passthrough_config(+ provider=LlmProviders.WATSONX,+ model="",+ )++ if provider_config is None:+ raise HTTPException(+ status_code=404, detail="Watsonx passthrough config not found"+ )++ # Get complete URL with version parameter+ complete_url, _ = provider_config.get_complete_url(+ api_base=None,+ api_key=None,+ model="",+ endpoint=endpoint,+ request_query_params=None,+ litellm_params={},+ )++ # Get auth headers with IAM token+ auth_headers = provider_config.validate_environment(+ headers={},+ model="",+ messages=[],+ optional_params={},+ litellm_params={},+ api_key=None,+ api_base=None,+ )++ # Check for streaming+ is_streaming_request = False+ if request.method == "POST":+ if "multipart/form-data" not in request.headers.get("content-type", ""):+ _request_body = await request.json()+ else:+ _request_body = await get_form_data(request)++ if _request_body.get("stream"):+ is_streaming_request = True++ request_query_params = dict(request.query_params)+ if request_query_params.get("version") is None:+ request_query_params["version"] = litellm.WATSONX_DEFAULT_API_VERSION++ # Create pass-through endpoint+ endpoint_func = create_pass_through_route(+ endpoint=endpoint,+ target=str(complete_url),+ custom_headers=auth_headers,+ is_streaming_request=is_streaming_request,+ custom_llm_provider="watsonx",+ query_params=request_query_params,+ )++ return await endpoint_func(+ request,+ fastapi_response,+ user_api_key_dict,+ )diff --cc litellm/utils.pyindex 1ad517aa9e5,7cac830b2c2..a98820cedd0--- a/litellm/utils.py+++ b/litellm/utils.py@@@ -8816,12 -9031,12 +9031,18 @@@ class ProviderConfigManager)return AzurePassthroughConfig()+ elif LlmProviders.GIGACHAT == provider:+ from litellm.llms.gigachat.passthrough.transformation import (+ GigaChatPassthroughConfig,+ )++ return GigaChatPassthroughConfig()+ elif LlmProviders.WATSONX == provider:+ from litellm.llms.watsonx.passthrough.transformation import (+ WatsonxPassthroughConfig,+ )++ return WatsonxPassthroughConfig()return None@staticmethod