From cf4efec48528aa9a92f04af929722f9e15c99660 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 15 Jul 2025 15:48:15 -0700 Subject: [PATCH] Step 2b - Loading Custom Callbacks --- docs/my-website/docs/proxy/logging.md | 66 +++++++++++++++++++++++++++ litellm/proxy/proxy_config.yaml | 8 +--- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/docs/my-website/docs/proxy/logging.md b/docs/my-website/docs/proxy/logging.md index b5b2b8bf50f..3467cf300f5 100644 --- a/docs/my-website/docs/proxy/logging.md +++ b/docs/my-website/docs/proxy/logging.md @@ -1768,6 +1768,72 @@ litellm_settings: ``` +#### Step 2b - Loading Custom Callbacks from S3/GCS (Alternative) + +Instead of using local Python files, you can load custom callbacks directly from S3 or GCS buckets. This is useful for centralized callback management or when deploying in containerized environments. + +**URL Format:** +- **S3**: `s3://bucket-name/module_name.instance_name` +- **GCS**: `gcs://bucket-name/module_name.instance_name` + +**Example - Loading from S3:** + +Let's say you have a file `custom_ui_sso_hook.py` stored in your S3 bucket `litellm-proxy` with the following content: + +```python +# custom_ui_sso_hook.py (stored in S3) +from litellm.integrations.custom_logger import CustomLogger +import litellm + +class MyCustomHandler(CustomLogger): + async def async_log_success_event(self, kwargs, response_obj, start_time, end_time): + print(f"Custom UI SSO callback executed!") + # Your custom logic here + + async def async_log_failure_event(self, kwargs, response_obj, start_time, end_time): + print(f"Custom UI SSO failure callback!") + # Your failure handling logic + +# Instance that will be loaded by LiteLLM +custom_handler = MyCustomHandler() +``` + +**Configuration:** + +```yaml +model_list: + - model_name: gpt-3.5-turbo + litellm_params: + model: gpt-3.5-turbo + +litellm_settings: + callbacks: ["s3://litellm-proxy/custom_ui_sso_hook.custom_ui_sso_sign_in_handler"] +``` + +**Example - Loading from GCS:** + +```yaml +model_list: + - model_name: gpt-3.5-turbo + litellm_params: + model: gpt-3.5-turbo + +litellm_settings: + callbacks: ["gcs://my-gcs-bucket/custom_callbacks.proxy_handler_instance"] +``` + +**How it works:** +1. LiteLLM detects the S3/GCS URL prefix +2. Downloads the Python file to a temporary location +3. Loads the module and extracts the specified instance +4. Cleans up the temporary file +5. Uses the callback instance for logging + +This approach allows you to: +- Centrally manage callback files across multiple proxy instances +- Share callbacks across different environments +- Version control callback files in cloud storage + #### Step 3 - Start proxy + test request ```shell diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml index bbccf93abdd..2f931e57b62 100644 --- a/litellm/proxy/proxy_config.yaml +++ b/litellm/proxy/proxy_config.yaml @@ -6,13 +6,7 @@ model_list: litellm_params: model: openai/* -guardrails: - - guardrail_name: "bedrock-pre-guard" - litellm_params: - guardrail: bedrock # supported values: "aporia", "bedrock", "lakera" - mode: "during_call" - guardrailIdentifier: ff6ujrregl1q - guardrailVersion: "DRAFT" + litellm_settings: callbacks: ["s3://litellm-proxy/custom_ui_sso_hook.custom_ui_sso_sign_in_handler"] \ No newline at end of file