mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
Merge pull request #4603 from BerriAI/litellm_track_user_ip
[Enterprise-Feature: Proxy] Track user-ip address in requests & in LiteLLM_SpendLogs
This commit is contained in:
commit
fad595fd47
8 changed files with 27 additions and 4 deletions
|
|
@ -7,13 +7,11 @@ Interested in Enterprise? Schedule a meeting with us here 👉
|
|||
|
||||
:::
|
||||
|
||||
## [AWS Marketplace Listing](https://aws.amazon.com/marketplace/pp/prodview-gdm3gswgjhgjo?sr=0-1&ref_=beagle&applicationId=AWSMPContessa)
|
||||
|
||||
Deploy managed LiteLLM Proxy within your VPC.
|
||||
|
||||
Includes all enterprise features.
|
||||
|
||||
[**View Listing**](https://aws.amazon.com/marketplace/pp/prodview-gdm3gswgjhgjo?sr=0-1&ref_=beagle&applicationId=AWSMPContessa)
|
||||
[**View AWS Marketplace Listing**](https://aws.amazon.com/marketplace/pp/prodview-gdm3gswgjhgjo?sr=0-1&ref_=beagle&applicationId=AWSMPContessa)
|
||||
|
||||
[**Get early access**](https://calendly.com/d/4mp-gd3-k5k/litellm-1-1-onboarding-chat)
|
||||
|
||||
|
|
@ -26,6 +24,7 @@ This covers:
|
|||
- ✅ [JWT-Auth](../docs/proxy/token_auth.md)
|
||||
- ✅ [Control available public, private routes](./proxy/enterprise#control-available-public-private-routes)
|
||||
- ✅ [[BETA] AWS Key Manager v2 - Key Decryption](./proxy/enterprise#beta-aws-key-manager---key-decryption)
|
||||
- ✅ Track Request IP Address
|
||||
- ✅ [Use LiteLLM keys/authentication on Pass Through Endpoints](./proxy/pass_through#✨-enterprise---use-litellm-keysauthentication-on-pass-through-endpoints)
|
||||
- ✅ [Enforce Required Params for LLM Requests (ex. Reject requests missing ["metadata"]["generation_name"])](./proxy/enterprise#enforce-required-params-for-llm-requests)
|
||||
- **Spend Tracking**
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ Features:
|
|||
- ✅ [JWT-Auth](../docs/proxy/token_auth.md)
|
||||
- ✅ [Control available public, private routes](#control-available-public-private-routes)
|
||||
- ✅ [[BETA] AWS Key Manager v2 - Key Decryption](#beta-aws-key-manager---key-decryption)
|
||||
- ✅ Track Request IP Address
|
||||
- ✅ [Use LiteLLM keys/authentication on Pass Through Endpoints](pass_through#✨-enterprise---use-litellm-keysauthentication-on-pass-through-endpoints)
|
||||
- ✅ [Enforce Required Params for LLM Requests (ex. Reject requests missing ["metadata"]["generation_name"])](#enforce-required-params-for-llm-requests)
|
||||
- **Spend Tracking**
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ async def add_litellm_data_to_request(
|
|||
dict: The modified data dictionary.
|
||||
|
||||
"""
|
||||
from litellm.proxy.proxy_server import premium_user
|
||||
|
||||
query_params = dict(request.query_params)
|
||||
if "api-version" in query_params:
|
||||
data["api_version"] = query_params["api-version"]
|
||||
|
|
@ -156,6 +158,19 @@ async def add_litellm_data_to_request(
|
|||
if user_api_key_dict.allowed_model_region is not None:
|
||||
data["allowed_model_region"] = user_api_key_dict.allowed_model_region
|
||||
|
||||
## [Enterprise Only] Add User-IP Address
|
||||
requester_ip_address = ""
|
||||
if premium_user is True:
|
||||
# Only set the IP Address for Enterprise Users
|
||||
if (
|
||||
request is not None
|
||||
and hasattr(request, "client")
|
||||
and hasattr(request.client, "host")
|
||||
and request.client is not None
|
||||
):
|
||||
requester_ip_address = request.client.host
|
||||
data[_metadata_variable_name]["requester_ip_address"] = requester_ip_address
|
||||
|
||||
### TEAM-SPECIFIC PARAMS ###
|
||||
if user_api_key_dict.team_id is not None:
|
||||
team_config = await proxy_config.load_team_config(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ def test_spend_logs_payload():
|
|||
"user_api_key_team_id": None,
|
||||
"user_api_key_team_alias": None,
|
||||
"user_api_key_metadata": {},
|
||||
"requester_ip_address": "127.0.0.1",
|
||||
"spend_logs_metadata": {"hello": "world"},
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue