From b99ffcf8ae5d97c89ada6801b86c2408b152a9b4 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 8 Jul 2024 10:16:58 -0700 Subject: [PATCH] SpendLogsPayload- track user ip --- litellm/proxy/_types.py | 3 +++ litellm/proxy/schema.prisma | 1 + litellm/proxy/spend_tracking/spend_tracking_utils.py | 2 ++ schema.prisma | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 4a1528108..966889ee2 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -1319,6 +1319,7 @@ class LiteLLM_SpendLogs(LiteLLMBase): cache_hit: Optional[str] = "False" cache_key: Optional[str] = None request_tags: Optional[Json] = None + requester_ip_address: Optional[str] = None class LiteLLM_ErrorLogs(LiteLLMBase): @@ -1510,6 +1511,7 @@ class SpendLogsMetadata(TypedDict): spend_logs_metadata: Optional[ dict ] # special param to log k,v pairs to spendlogs for a call + requester_ip_address: Optional[str] class SpendLogsPayload(TypedDict): @@ -1534,6 +1536,7 @@ class SpendLogsPayload(TypedDict): request_tags: str # json str team_id: Optional[str] end_user: Optional[str] + requester_ip_address: Optional[str] class SpanAttributes(str, enum.Enum): diff --git a/litellm/proxy/schema.prisma b/litellm/proxy/schema.prisma index 4dd42feb0..528d7e98d 100644 --- a/litellm/proxy/schema.prisma +++ b/litellm/proxy/schema.prisma @@ -191,6 +191,7 @@ model LiteLLM_SpendLogs { request_tags Json @default("[]") team_id String? end_user String? + requester_ip_address String? } // View spend, model, api_key per request diff --git a/litellm/proxy/spend_tracking/spend_tracking_utils.py b/litellm/proxy/spend_tracking/spend_tracking_utils.py index e4027b984..cd7004e41 100644 --- a/litellm/proxy/spend_tracking/spend_tracking_utils.py +++ b/litellm/proxy/spend_tracking/spend_tracking_utils.py @@ -55,6 +55,7 @@ def get_logging_payload( user_api_key_user_id=None, user_api_key_team_alias=None, spend_logs_metadata=None, + requester_ip_address=None, ) if isinstance(metadata, dict): verbose_proxy_logger.debug( @@ -109,6 +110,7 @@ def get_logging_payload( api_base=litellm_params.get("api_base", ""), model_group=_model_group, model_id=_model_id, + requester_ip_address=clean_metadata.get("requester_ip_address", None), ) verbose_proxy_logger.debug( diff --git a/schema.prisma b/schema.prisma index 2e39348ff..970a1197e 100644 --- a/schema.prisma +++ b/schema.prisma @@ -191,6 +191,7 @@ model LiteLLM_SpendLogs { request_tags Json @default("[]") team_id String? end_user String? + requester_ip_address String? } // View spend, model, api_key per request @@ -256,4 +257,4 @@ model LiteLLM_AuditLog { object_id String // id of the object being audited. This can be the key id, team id, user id, model id before_value Json? // value of the row updated_values Json? // value of the row after change -} \ No newline at end of file +}