Sample code to prevent logging API key

Sample code in documentation to prevent logging API key. Ideally should be implemented in the codebase if not already
This commit is contained in:
navidre 2023-12-19 14:04:20 -06:00 committed by GitHub
parent c5340b8709
commit b8d7cafb8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,6 +41,18 @@ def send_slack_alert(
# get it from https://api.slack.com/messaging/webhooks
slack_webhook_url = os.environ['SLACK_WEBHOOK_URL'] # "https://hooks.slack.com/services/<>/<>/<>"
# Remove api_key from kwargs under litellm_params
if kwargs.get('litellm_params'):
kwargs['litellm_params'].pop('api_key', None)
if kwargs['litellm_params'].get('metadata'):
kwargs['litellm_params']['metadata'].pop('deployment', None)
# Remove deployment under metadata
if kwargs.get('metadata'):
kwargs['metadata'].pop('deployment', None)
# Prevent api_key from being logged
if kwargs.get('api_key'):
kwargs.pop('api_key', None)
# Define the text payload, send data available in litellm custom_callbacks
text_payload = f"""LiteLLM Logging: kwargs: {str(kwargs)}\n\n, response: {str(completion_response)}\n\n, start time{str(start_time)} end time: {str(end_time)}
"""
@ -90,4 +102,4 @@ response = litellm.completion(
- [Schedule Demo 👋](https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version)
- [Community Discord 💭](https://discord.gg/wuPM9dRgDw)
- Our numbers 📞 +1 (770) 8783-106 / +1 (412) 618-6238
- Our emails ✉️ ishaan@berri.ai / krrish@berri.ai
- Our emails ✉️ ishaan@berri.ai / krrish@berri.ai