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 with main

yuneng-jiang31535ff4b61b
diff --cc litellm/proxy/common_utils/callback_utils.py
index 2fb4dfc60cc,7cd359f7ce0..cbb058cc361
--- a/litellm/proxy/common_utils/callback_utils.py
+++ b/litellm/proxy/common_utils/callback_utils.py
@@@ -372,42 -366,22 +370,43 @@@ def add_guardrail_to_applied_guardrails
def get_metadata_variable_name_from_kwargs(
- kwargs: dict
- ) -> Literal["metadata", "litellm_metadata"]:
- """
- Helper to return what the "metadata" field should be called in the request data
+ kwargs: dict,
+ ) -> Literal["metadata", "litellm_metadata"]:
+ """
+ Helper to return what the "metadata" field should be called in the request data
- - New endpoints return `litellm_metadata`
- - Old endpoints return `metadata`
+ - New endpoints return `litellm_metadata`
+ - Old endpoints return `metadata`
+
+ Context:
+ - LiteLLM used `metadata` as an internal field for storing metadata
+ - OpenAI then started using this field for their metadata
+ - LiteLLM is now moving to using `litellm_metadata` for our metadata
+ """
+ return "litellm_metadata" if "litellm_metadata" in kwargs else "metadata"
- Context:
- - LiteLLM used `metadata` as an internal field for storing metadata
- - OpenAI then started using this field for their metadata
- - LiteLLM is now moving to using `litellm_metadata` for our metadata
- """
- return "litellm_metadata" if "litellm_metadata" in kwargs else "metadata"
+def process_callback(_callback: str, callback_type: str, environment_variables: dict) -> dict:
+ """Process a single callback and return its data with environment variables"""
+ env_vars = CustomLogger.get_callback_env_vars(_callback)
+
+ env_vars_dict: dict[str, str | None] = {}
+ for _var in env_vars:
+ env_variable = environment_variables.get(_var, None)
+ if env_variable is None:
+ env_vars_dict[_var] = None
+ else:
+ # decode + decrypt the value
+ decrypted_value = decrypt_value_helper(
+ value=env_variable, key=_var
+ )
+ env_vars_dict[_var] = decrypted_value
+
+ return {
+ "name": _callback,
+ "variables": env_vars_dict,
+ "type": callback_type
+ }
def normalize_callback_names(callbacks: Iterable[Any]) -> List[Any]:
if callbacks is None:
return []
diff --cc litellm/proxy/proxy_server.py
index de228e7c582,9c98ad215b3..edd86c1b22a
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@@ -47,10 -48,7 +48,8 @@@ from litellm.types.utils import
TokenCountResponse,
)
from litellm.utils import load_credentials_from_list
+from litellm.proxy.common_utils.callback_utils import process_callback
- from litellm.proxy.common_utils.callback_utils import normalize_callback_names
-
if TYPE_CHECKING:
from aiohttp import ClientSession
from opentelemetry.trace import Span as _Span