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
perf: pre-compute OpenAI client __init__ params at module load
Ryan Crabbe400304c2b785
diff --git a/litellm/llms/openai/common_utils.py b/litellm/llms/openai/common_utils.pyindex ce470f04aca..868d02ee1e7 100644--- a/litellm/llms/openai/common_utils.py+++ b/litellm/llms/openai/common_utils.py@@ -14,6 +14,8 @@ from openai import AsyncAzureOpenAI, AsyncOpenAI, AzureOpenAI, OpenAIif TYPE_CHECKING:from aiohttp import ClientSession+import inspect+import litellmfrom litellm.llms.base_llm.chat.transformation import BaseLLMExceptionfrom litellm.llms.custom_httpx.http_handler import (@@ -22,6 +24,14 @@ from litellm.llms.custom_httpx.http_handler import (get_ssl_configuration,)+def _get_client_init_params(cls: type) -> List[str]:+ """Extract __init__ parameter names (excluding 'self') from a class."""+ return [p for p in inspect.signature(cls.__init__).parameters if p != "self"]+++_OPENAI_INIT_PARAMS: List[str] = _get_client_init_params(OpenAI)+_AZURE_OPENAI_INIT_PARAMS: List[str] = _get_client_init_params(AzureOpenAI)+class OpenAIError(BaseLLMException):def __init__(@@ -183,18 +193,10 @@ class BaseOpenAILLM:client_type: Literal["openai", "azure"]) -> List[str]:"""Returns a list of fields that are used to initialize the OpenAI client"""- import inspect-- from openai import AzureOpenAI, OpenAI-if client_type == "openai":- signature = inspect.signature(OpenAI.__init__)+ return _OPENAI_INIT_PARAMSelse:- signature = inspect.signature(AzureOpenAI.__init__)-- # Extract parameter names, excluding 'self'- param_names = [param for param in signature.parameters if param != "self"]- return param_names+ return _AZURE_OPENAI_INIT_PARAMS@staticmethoddef _get_async_http_client(@@ -230,3 +232,5 @@ class BaseOpenAILLM:verify=ssl_config,follow_redirects=True,)++