MCPcopy Create free account
hub / github.com/BerriAI/litellm / ProxyBaseLLMRequestProcessing

Class ProxyBaseLLMRequestProcessing

litellm/proxy/common_request_processing.py:1011–3222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1009
1010
1011class ProxyBaseLLMRequestProcessing:
1012 def __init__(self, data: dict):
1013 self.data = data
1014
1015 @staticmethod
1016 def get_custom_headers(
1017 *,
1018 user_api_key_dict: UserAPIKeyAuth,
1019 call_id: str | None = None,
1020 model_id: str | None = None,
1021 cache_key: str | None = None,
1022 api_base: str | None = None,
1023 version: str | None = None,
1024 model_region: str | None = None,
1025 response_cost: float | str | None = None,
1026 hidden_params: dict | None = None,
1027 fastest_response_batch_completion: bool | None = None,
1028 request_data: dict | None = {},
1029 timeout: float | httpx.Timeout | None = None,
1030 litellm_logging_obj: LiteLLMLoggingObj | None = None,
1031 **kwargs,
1032 ) -> dict:
1033 exclude_values: Final = {"", None, "None"}
1034 hidden_params = hidden_params or {}
1035
1036 # Extract discount and margin info from cost_breakdown if available
1037 (
1038 original_cost,
1039 discount_amount,
1040 margin_total_amount,
1041 margin_percent,
1042 ) = _get_cost_breakdown_from_logging_obj(litellm_logging_obj=litellm_logging_obj)
1043
1044 # Calculate updated spend for header (include current response_cost)
1045 current_spend: Final = user_api_key_dict.spend or 0.0
1046 updated_spend = current_spend
1047 if response_cost is not None:
1048 try:
1049 # Convert response_cost to float if it's a string
1050 cost_value: Final = float(response_cost) if isinstance(response_cost, str) else response_cost
1051 if cost_value > 0:
1052 updated_spend = current_spend + cost_value
1053 except (ValueError, TypeError):
1054 # If conversion fails, use original spend
1055 pass
1056
1057 model_name: Final = ProxyBaseLLMRequestProcessing._get_deployment_model_name(litellm_logging_obj)
1058 classifier_cost: Final = _classifier_cost_from_request_data(request_data)
1059
1060 headers: Final = {
1061 "x-litellm-call-id": call_id,
1062 "x-litellm-model-id": model_id,
1063 "x-litellm-model-name": model_name,
1064 "x-litellm-cache-key": cache_key,
1065 "x-litellm-model-api-base": (
1066 api_base.split("?")[0] if api_base else None
1067 ), # don't include query params, risk of leaking sensitive info
1068 "x-litellm-version": version,

Callers 15

chat_completionFunction · 0.90
completionFunction · 0.90
embeddingsFunction · 0.90
vector_store_searchFunction · 0.90
vector_store_createFunction · 0.90
vector_store_retrieveFunction · 0.90
vector_store_listFunction · 0.90
vector_store_updateFunction · 0.90
vector_store_deleteFunction · 0.90
bedrock_llm_proxy_routeFunction · 0.90

Calls

no outgoing calls