Working setting generic callbacks on UI

This commit is contained in:
yuneng-jiang
2025-12-05 14:37:48 -08:00
parent 98f9124444
commit 0dd4db34bd
6 changed files with 16 additions and 28 deletions
+5 -5
View File
@@ -42,21 +42,21 @@
"description": "Braintrust Logging Integration"
},
{
"id": "custom_callback_api",
"id": "generic_api",
"displayName": "Custom Callback API",
"logo": "custom.svg",
"supports_key_team_logging": true,
"dynamic_params": {
"custom_callback_api_url": {
"GENERIC_LOGGER_ENDPOINT": {
"type": "text",
"ui_name": "Callback URL",
"description": "Your custom webhook/API endpoint URL to receive logs",
"required": true
},
"custom_callback_api_headers": {
"GENERIC_LOGGER_HEADERS": {
"type": "text",
"ui_name": "Headers (JSON)",
"description": "Custom HTTP headers as JSON string (e.g., {\"Authorization\": \"Bearer token\"})",
"ui_name": "Headers",
"description": "Custom HTTP headers as a comma-separated string (e.g., Authorization: Bearer token, Content-Type: application/json)",
"required": false
}
},
+1 -1
View File
@@ -2577,7 +2577,7 @@ class AllCallbacks(LiteLLMPydanticObjectBase):
custom_callback_api: CallbackOnUI = CallbackOnUI(
litellm_callback_name="custom_callback_api",
litellm_callback_params=["GENERIC_LOGGER_ENDPOINT"],
litellm_callback_params=["GENERIC_LOGGER_ENDPOINT", "GENERIC_LOGGER_HEADER"],
ui_callback_name="Custom Callback API",
)
+1 -8
View File
@@ -6,9 +6,6 @@ from litellm._logging import verbose_proxy_logger
from litellm.integrations.custom_logger import CustomLogger
from litellm.proxy._types import CommonProxyErrors, LiteLLMPromptInjectionParams
from litellm.proxy.types_utils.utils import get_instance_fn
from litellm.proxy.common_utils.encrypt_decrypt_utils import (
decrypt_value_helper,
)
from litellm.types.utils import (
StandardLoggingGuardrailInformation,
StandardLoggingPayload,
@@ -434,11 +431,7 @@ def process_callback(_callback: str, callback_type: str, environment_variables:
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
env_vars_dict[_var] = env_variable
return {
"name": _callback,
+1 -1
View File
@@ -9476,7 +9476,7 @@ async def get_config(): # noqa: PLR0915
_litellm_settings = config_data.get("litellm_settings", {})
_general_settings = config_data.get("general_settings", {})
environment_variables = config_data.get("environment_variables", {})
_success_callbacks = _litellm_settings.get("success_callback", [])
_failure_callbacks = _litellm_settings.get("failure_callback", [])
_success_and_failure_callbacks = _litellm_settings.get("callbacks", [])
@@ -37,13 +37,9 @@ def test_get_remaining_tokens_and_requests_from_request_data():
"litellm.proxy.common_utils.callback_utils.CustomLogger.get_callback_env_vars",
return_value=["API_KEY", "MISSING_VAR"],
)
@patch(
"litellm.proxy.common_utils.callback_utils.decrypt_value_helper",
side_effect=lambda value, key: f"decrypted-{key}",
)
def test_process_callback_with_env_vars(mock_decrypt, mock_get_env_vars):
def test_process_callback_with_env_vars(mock_get_env_vars):
environment_variables = {
"API_KEY": "ENC_VALUE",
"API_KEY": "PLAIN_VALUE",
"UNUSED": "SHOULD_BE_IGNORED",
}
@@ -56,7 +52,7 @@ def test_process_callback_with_env_vars(mock_decrypt, mock_get_env_vars):
assert result["name"] == "my_callback"
assert result["type"] == "input"
assert result["variables"] == {
"API_KEY": "decrypted-API_KEY",
"API_KEY": "PLAIN_VALUE",
"MISSING_VAR": None,
}
@@ -252,13 +252,13 @@ def test_get_config_custom_callback_api_env_vars(monkeypatch):
"""
from litellm.proxy.proxy_server import app, proxy_config, user_api_key_auth
# Mock config with custom_callback_api enabled and custom env vars present
# Mock config with custom_callback_api enabled and generic logger env vars present
config_data = {
"litellm_settings": {"success_callback": ["custom_callback_api"]},
"general_settings": {},
"environment_variables": {
"custom_callback_api_url": "https://callback.example.com",
"custom_callback_api_headers": "Auth: token",
"GENERIC_LOGGER_ENDPOINT": "https://callback.example.com",
"GENERIC_LOGGER_HEADER": "Auth: token",
},
}
@@ -288,10 +288,9 @@ def test_get_config_custom_callback_api_env_vars(monkeypatch):
assert custom_cb is not None
assert custom_cb["variables"] == {
"custom_callback_api_url": "https://callback.example.com",
"custom_callback_api_headers": "Auth: token",
"GENERIC_LOGGER_ENDPOINT": "https://callback.example.com",
"GENERIC_LOGGER_HEADER": "Auth: token",
}
assert "GENERIC_LOGGER_ENDPOINT" not in custom_cb["variables"]
# Mock Prisma