Skip to content

Commit d89152b

Browse files
feat(litellm_logging.py): support new litellm debug parameter - litellm_request_debug on requests
enables printing raw request when flag is set to true on requests
1 parent b1025b5 commit d89152b

File tree

5 files changed

+73
-31
lines changed

5 files changed

+73
-31
lines changed

litellm/constants.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
os.getenv("DEFAULT_SQS_FLUSH_INTERVAL_SECONDS", 10)
1616
)
1717
DEFAULT_NUM_WORKERS_LITELLM_PROXY = int(
18-
os.getenv("DEFAULT_NUM_WORKERS_LITELLM_PROXY", os.cpu_count() or 4)
18+
os.getenv("DEFAULT_NUM_WORKERS_LITELLM_PROXY", 1)
1919
)
2020
DEFAULT_SQS_BATCH_SIZE = int(os.getenv("DEFAULT_SQS_BATCH_SIZE", 512))
2121
SQS_SEND_MESSAGE_ACTION = "SendMessage"
@@ -60,7 +60,9 @@
6060
os.getenv("DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGET_GEMINI_2_5_PRO", 128)
6161
)
6262
DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGET_GEMINI_2_5_FLASH_LITE = int(
63-
os.getenv("DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGET_GEMINI_2_5_FLASH_LITE", 512)
63+
os.getenv(
64+
"DEFAULT_REASONING_EFFORT_MINIMAL_THINKING_BUDGET_GEMINI_2_5_FLASH_LITE", 512
65+
)
6466
)
6567

6668
# Generic fallback for unknown models
@@ -949,7 +951,9 @@
949951
DB_SPEND_UPDATE_JOB_NAME = "db_spend_update_job"
950952
PROMETHEUS_EMIT_BUDGET_METRICS_JOB_NAME = "prometheus_emit_budget_metrics"
951953
CLOUDZERO_EXPORT_USAGE_DATA_JOB_NAME = "cloudzero_export_usage_data"
952-
CLOUDZERO_MAX_FETCHED_DATA_RECORDS = int(os.getenv("CLOUDZERO_MAX_FETCHED_DATA_RECORDS", 50000))
954+
CLOUDZERO_MAX_FETCHED_DATA_RECORDS = int(
955+
os.getenv("CLOUDZERO_MAX_FETCHED_DATA_RECORDS", 50000)
956+
)
953957
SPEND_LOG_CLEANUP_JOB_NAME = "spend_log_cleanup"
954958
SPEND_LOG_RUN_LOOPS = int(os.getenv("SPEND_LOG_RUN_LOOPS", 500))
955959
SPEND_LOG_CLEANUP_BATCH_SIZE = int(os.getenv("SPEND_LOG_CLEANUP_BATCH_SIZE", 1000))

litellm/litellm_core_utils/get_litellm_params.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def get_litellm_params(
6262
use_litellm_proxy: Optional[bool] = None,
6363
api_version: Optional[str] = None,
6464
max_retries: Optional[int] = None,
65+
litellm_request_debug: Optional[bool] = None,
6566
**kwargs,
6667
) -> dict:
6768
litellm_params = {
@@ -118,5 +119,6 @@ def get_litellm_params(
118119
"vertex_credentials": kwargs.get("vertex_credentials"),
119120
"vertex_project": kwargs.get("vertex_project"),
120121
"use_litellm_proxy": use_litellm_proxy,
122+
"litellm_request_debug": litellm_request_debug,
121123
}
122124
return litellm_params

litellm/litellm_core_utils/litellm_logging.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class Logging(LiteLLMLoggingBaseClass):
245245
global supabaseClient, promptLayerLogger, weightsBiasesLogger, logfireLogger, capture_exception, add_breadcrumb, lunaryLogger, logfireLogger, prometheusLogger, slack_app
246246
custom_pricing: bool = False
247247
stream_options = None
248+
litellm_request_debug: bool = False
248249

249250
def __init__(
250251
self,
@@ -470,6 +471,7 @@ def update_environment_variables(
470471
**self.litellm_params,
471472
**scrub_sensitive_keys_in_metadata(litellm_params),
472473
}
474+
self.litellm_request_debug = litellm_params.get("litellm_request_debug", False)
473475
self.logger_fn = litellm_params.get("logger_fn", None)
474476
verbose_logger.debug(f"self.optional_params: {self.optional_params}")
475477

@@ -907,13 +909,19 @@ def _print_llm_call_debugging_log(
907909
908910
Prints the RAW curl command sent from LiteLLM
909911
"""
910-
if _is_debugging_on():
912+
if _is_debugging_on() or self.litellm_request_debug:
911913
if json_logs:
912914
masked_headers = self._get_masked_headers(headers)
913-
verbose_logger.debug(
914-
"POST Request Sent from LiteLLM",
915-
extra={"api_base": {api_base}, **masked_headers},
916-
)
915+
if self.litellm_request_debug:
916+
verbose_logger.warning( # .warning ensures this shows up in all environments
917+
"POST Request Sent from LiteLLM",
918+
extra={"api_base": {api_base}, **masked_headers},
919+
)
920+
else:
921+
verbose_logger.debug(
922+
"POST Request Sent from LiteLLM",
923+
extra={"api_base": {api_base}, **masked_headers},
924+
)
917925
else:
918926
headers = additional_args.get("headers", {})
919927
if headers is None:
@@ -926,7 +934,12 @@ def _print_llm_call_debugging_log(
926934
additional_args=additional_args,
927935
data=data,
928936
)
929-
verbose_logger.debug(f"\033[92m{curl_command}\033[0m\n")
937+
if self.litellm_request_debug:
938+
verbose_logger.warning(
939+
f"\033[92m{curl_command}\033[0m\n"
940+
) # .warning ensures this shows up in all environments
941+
else:
942+
verbose_logger.debug(f"\033[92m{curl_command}\033[0m\n")
930943

931944
def _get_request_body(self, data: dict) -> str:
932945
return str(data)
@@ -1714,12 +1727,16 @@ def success_handler( # noqa: PLR0915
17141727
response_obj=result,
17151728
start_time=start_time,
17161729
end_time=end_time,
1717-
litellm_call_id=current_call_id
1718-
if (
1719-
current_call_id := litellm_params.get("litellm_call_id")
1720-
)
1721-
is not None
1722-
else str(uuid.uuid4()),
1730+
litellm_call_id=(
1731+
current_call_id
1732+
if (
1733+
current_call_id := litellm_params.get(
1734+
"litellm_call_id"
1735+
)
1736+
)
1737+
is not None
1738+
else str(uuid.uuid4())
1739+
),
17231740
print_verbose=print_verbose,
17241741
)
17251742
if callback == "wandb" and weightsBiasesLogger is not None:
@@ -3367,6 +3384,7 @@ def _init_custom_logger_compatible_class( # noqa: PLR0915
33673384
return galileo_logger # type: ignore
33683385
elif logging_integration == "cloudzero":
33693386
from litellm.integrations.cloudzero.cloudzero import CloudZeroLogger
3387+
33703388
for callback in _in_memory_loggers:
33713389
if isinstance(callback, CloudZeroLogger):
33723390
return callback # type: ignore
@@ -3594,6 +3612,7 @@ def get_custom_logger_compatible_class( # noqa: PLR0915
35943612
return callback
35953613
elif logging_integration == "cloudzero":
35963614
from litellm.integrations.cloudzero.cloudzero import CloudZeroLogger
3615+
35973616
for callback in _in_memory_loggers:
35983617
if isinstance(callback, CloudZeroLogger):
35993618
return callback
@@ -4504,7 +4523,7 @@ def get_standard_logging_object_payload(
45044523

45054524
def emit_standard_logging_payload(payload: StandardLoggingPayload):
45064525
if os.getenv("LITELLM_PRINT_STANDARD_LOGGING_PAYLOAD"):
4507-
print(json.dumps(payload, indent=4)) # noqa
4526+
print(json.dumps(payload, indent=4)) # noqa
45084527

45094528

45104529
def get_standard_logging_metadata(

litellm/main.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@
150150
from .llms.custom_llm import CustomLLM, custom_chat_llm_router
151151
from .llms.databricks.embed.handler import DatabricksEmbeddingHandler
152152
from .llms.deprecated_providers import aleph_alpha, palm
153+
from .llms.gemini.common_utils import get_api_key_from_env
153154
from .llms.groq.chat.handler import GroqChatCompletion
154155
from .llms.heroku.chat.transformation import HerokuChatConfig
155-
from .llms.gemini.common_utils import get_api_key_from_env
156156
from .llms.huggingface.embedding.handler import HuggingFaceEmbedding
157157
from .llms.nlp_cloud.chat.handler import completion as nlp_cloud_chat_completion
158158
from .llms.oci.chat.transformation import OCIChatConfig
@@ -358,7 +358,9 @@ async def acompletion(
358358
logprobs: Optional[bool] = None,
359359
top_logprobs: Optional[int] = None,
360360
deployment_id=None,
361-
reasoning_effort: Optional[Literal["none", "minimal", "low", "medium", "high", "default"]] = None,
361+
reasoning_effort: Optional[
362+
Literal["none", "minimal", "low", "medium", "high", "default"]
363+
] = None,
362364
safety_identifier: Optional[str] = None,
363365
# set api_base, api_version, api_key
364366
base_url: Optional[str] = None,
@@ -504,7 +506,9 @@ async def acompletion(
504506
}
505507
if custom_llm_provider is None:
506508
_, custom_llm_provider, _, _ = get_llm_provider(
507-
model=model, custom_llm_provider=custom_llm_provider, api_base=completion_kwargs.get("base_url", None)
509+
model=model,
510+
custom_llm_provider=custom_llm_provider,
511+
api_base=completion_kwargs.get("base_url", None),
508512
)
509513

510514
fallbacks = fallbacks or litellm.model_fallbacks
@@ -899,7 +903,9 @@ def completion( # type: ignore # noqa: PLR0915
899903
logit_bias: Optional[dict] = None,
900904
user: Optional[str] = None,
901905
# openai v1.0+ new params
902-
reasoning_effort: Optional[Literal["none", "minimal", "low", "medium", "high", "default"]] = None,
906+
reasoning_effort: Optional[
907+
Literal["none", "minimal", "low", "medium", "high", "default"]
908+
] = None,
903909
response_format: Optional[Union[dict, Type[BaseModel]]] = None,
904910
seed: Optional[int] = None,
905911
tools: Optional[List] = None,
@@ -1116,10 +1122,12 @@ def completion( # type: ignore # noqa: PLR0915
11161122
)
11171123

11181124
if provider_specific_header is not None:
1119-
headers.update(ProviderSpecificHeaderUtils.get_provider_specific_headers(
1120-
provider_specific_header=provider_specific_header,
1121-
custom_llm_provider=custom_llm_provider,
1122-
))
1125+
headers.update(
1126+
ProviderSpecificHeaderUtils.get_provider_specific_headers(
1127+
provider_specific_header=provider_specific_header,
1128+
custom_llm_provider=custom_llm_provider,
1129+
)
1130+
)
11231131

11241132
if model_response is not None and hasattr(model_response, "_hidden_params"):
11251133
model_response._hidden_params["custom_llm_provider"] = custom_llm_provider
@@ -1325,6 +1333,7 @@ def completion( # type: ignore # noqa: PLR0915
13251333
azure_scope=kwargs.get("azure_scope"),
13261334
max_retries=max_retries,
13271335
timeout=timeout,
1336+
litellm_request_debug=kwargs.get("litellm_request_debug", False),
13281337
)
13291338
cast(LiteLLMLoggingObj, logging).update_environment_variables(
13301339
model=model,
@@ -2712,9 +2721,7 @@ def completion( # type: ignore # noqa: PLR0915
27122721
)
27132722

27142723
api_key = (
2715-
api_key
2716-
or litellm.api_key
2717-
or get_secret("VERCEL_AI_GATEWAY_API_KEY")
2724+
api_key or litellm.api_key or get_secret("VERCEL_AI_GATEWAY_API_KEY")
27182725
)
27192726

27202727
vercel_site_url = get_secret("VERCEL_SITE_URL") or "https://litellm.ai"
@@ -2730,7 +2737,7 @@ def completion( # type: ignore # noqa: PLR0915
27302737
vercel_headers.update(_headers)
27312738

27322739
headers = vercel_headers
2733-
2740+
27342741
## Load Config
27352742
config = litellm.VercelAIGatewayConfig.get_config()
27362743
for k, v in config.items():
@@ -3712,7 +3719,9 @@ async def aembedding(*args, **kwargs) -> EmbeddingResponse:
37123719
func_with_context = partial(ctx.run, func)
37133720

37143721
_, custom_llm_provider, _, _ = get_llm_provider(
3715-
model=model, custom_llm_provider=custom_llm_provider, api_base=kwargs.get("api_base", None)
3722+
model=model,
3723+
custom_llm_provider=custom_llm_provider,
3724+
api_base=kwargs.get("api_base", None),
37163725
)
37173726

37183727
# Await normally
@@ -5780,7 +5789,14 @@ async def ahealth_check(
57805789
input=input or ["test"],
57815790
),
57825791
"audio_speech": lambda: litellm.aspeech(
5783-
**{**_filter_model_params(model_params), **({"voice": "alloy"} if "voice" not in _filter_model_params(model_params) else {})},
5792+
**{
5793+
**_filter_model_params(model_params),
5794+
**(
5795+
{"voice": "alloy"}
5796+
if "voice" not in _filter_model_params(model_params)
5797+
else {}
5798+
),
5799+
},
57845800
input=prompt or "test",
57855801
),
57865802
"audio_transcription": lambda: litellm.atranscription(

litellm/types/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ class StandardLoggingGuardrailInformation(TypedDict, total=False):
19951995
]
19961996
guardrail_request: Optional[dict]
19971997
guardrail_response: Optional[Union[dict, str, List[dict]]]
1998-
guardrail_status: Literal["success", "failure","blocked"]
1998+
guardrail_status: Literal["success", "failure", "blocked"]
19991999
start_time: Optional[float]
20002000
end_time: Optional[float]
20012001
duration: Optional[float]
@@ -2123,6 +2123,7 @@ class StandardCallbackDynamicParams(TypedDict, total=False):
21232123
"metadata",
21242124
"litellm_metadata",
21252125
"litellm_trace_id",
2126+
"litellm_request_debug",
21262127
"guardrails",
21272128
"tags",
21282129
"acompletion",

0 commit comments

Comments
 (0)