diff --git a/litellm/responses/main.py b/litellm/responses/main.py index c719b993a9..337e7fc3b0 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -120,6 +120,18 @@ async def aresponses( response_api_optional_params=response_api_optional_params, ) + # Pre Call logging + litellm_logging_obj.update_environment_variables( + model=model, + user=user, + optional_params=dict(responses_api_request_params), + litellm_params={ + "litellm_call_id": litellm_call_id, + **responses_api_request_params, + }, + custom_llm_provider=custom_llm_provider, + ) + response = await base_llm_http_handler.async_response_api_handler( model=model, input=input, diff --git a/litellm/utils.py b/litellm/utils.py index 97c8171b36..cebc0ed7cf 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -716,6 +716,11 @@ def function_setup( # noqa: PLR0915 call_type == CallTypes.aspeech.value or call_type == CallTypes.speech.value ): messages = kwargs.get("input", "speech") + elif ( + call_type == CallTypes.aresponses.value + or call_type == CallTypes.responses.value + ): + messages = args[0] if len(args) > 0 else kwargs["input"] else: messages = "default-message-value" stream = True if "stream" in kwargs and kwargs["stream"] is True else False diff --git a/tests/llm_responses_api_testing/test_openai_responses_api.py b/tests/llm_responses_api_testing/test_openai_responses_api.py index 32e2e4f80f..6d86cddb76 100644 --- a/tests/llm_responses_api_testing/test_openai_responses_api.py +++ b/tests/llm_responses_api_testing/test_openai_responses_api.py @@ -76,8 +76,9 @@ async def test_basic_openai_responses_api_non_streaming_with_logging(): litellm.set_verbose = True test_custom_logger = TestCustomLogger() litellm.callbacks = [test_custom_logger] + request_model = "gpt-4o" response = await litellm.aresponses( - model="gpt-4o", + model=request_model, input="hi", ) @@ -111,9 +112,14 @@ async def test_basic_openai_responses_api_non_streaming_with_logging(): assert test_custom_logger.standard_logging_object["response_cost"] > 0 # validate response id matches OpenAI + assert test_custom_logger.standard_logging_object["id"] == response["id"] # validate model matches + assert test_custom_logger.standard_logging_object["model"] == request_model # validate messages matches + assert test_custom_logger.standard_logging_object["messages"] == [ + {"content": "hi", "role": "user"} + ] # validate responses matches