Step 2b - Loading Custom Callbacks

This commit is contained in:
Ishaan Jaff 2025-07-15 15:48:15 -07:00
parent 83686f6baf
commit cf4efec485
2 changed files with 67 additions and 7 deletions

View file

@ -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

View file

@ -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"]