Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Bug Fix - responses api fix got multiple values for keyword argument 'litellm_trace_id' (#12225)

Ishaan Jaff4e7115bc3481
diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml
index 13724177c05..8a8fd6794e7 100644
--- a/litellm/proxy/proxy_config.yaml
+++ b/litellm/proxy/proxy_config.yaml
@@ -1,8 +1,7 @@
model_list:
- - model_name: groq/*
+ - model_name: anthropic/*
litellm_params:
- model: groq/*
- api_key: bad
+ model: anthropic/*
- model_name: openai/*
litellm_params:
model: openai/*
diff --git a/litellm/responses/litellm_completion_transformation/handler.py b/litellm/responses/litellm_completion_transformation/handler.py
index f960092f2bf..7dc182747df 100644
--- a/litellm/responses/litellm_completion_transformation/handler.py
+++ b/litellm/responses/litellm_completion_transformation/handler.py
@@ -56,6 +56,10 @@ class LiteLLMCompletionTransformationHandler:
responses_api_request=responses_api_request,
**kwargs,
)
+
+ completion_args = {}
+ completion_args.update(kwargs)
+ completion_args.update(litellm_completion_request)
litellm_completion_response: Union[
ModelResponse, litellm.CustomStreamWrapper
@@ -98,12 +102,15 @@ class LiteLLMCompletionTransformationHandler:
previous_response_id=previous_response_id,
litellm_completion_request=litellm_completion_request,
)
+
+ acompletion_args = {}
+ acompletion_args.update(kwargs)
+ acompletion_args.update(litellm_completion_request)
litellm_completion_response: Union[
ModelResponse, litellm.CustomStreamWrapper
] = await litellm.acompletion(
- **litellm_completion_request,
- **kwargs,
+ **acompletion_args,
)
if isinstance(litellm_completion_response, ModelResponse):
diff --git a/tests/llm_responses_api_testing/test_anthropic_responses_api.py b/tests/llm_responses_api_testing/test_anthropic_responses_api.py
index 3eabc0c15bc..1e24457145f 100644
--- a/tests/llm_responses_api_testing/test_anthropic_responses_api.py
+++ b/tests/llm_responses_api_testing/test_anthropic_responses_api.py
@@ -4,6 +4,10 @@ import pytest
import asyncio
from typing import Optional
from unittest.mock import patch, AsyncMock
+from litellm.responses.litellm_completion_transformation.handler import LiteLLMCompletionTransformationHandler
+from litellm.responses.litellm_completion_transformation.transformation import LiteLLMCompletionResponsesConfig
+from litellm.types.utils import ModelResponse
+
sys.path.insert(0, os.path.abspath("../.."))
import litellm
@@ -103,4 +107,33 @@ def test_multiturn_tool_calls():
print("follow_up_response=", follow_up_response)
-
\ No newline at end of file
+
+
+async def test_async_response_api_handler_merges_trace_id_without_error():
+ handler = LiteLLMCompletionTransformationHandler()
+
+ async def fake_session_handler(previous_response_id, litellm_completion_request):
+ litellm_completion_request["litellm_trace_id"] = "session-trace"
+ return litellm_completion_request
+
+ with patch.object(
+ LiteLLMCompletionResponsesConfig,
+ "async_responses_api_session_handler",
+ side_effect=fake_session_handler,
+ ):
+ with patch("litellm.acompletion", new_callable=AsyncMock) as mock_acompletion:
+ mock_acompletion.return_value = ModelResponse(
+ id="id", created=0, model="test", object="chat.completion", choices=[]
+ )
+ await handler.async_response_api_handler(
+ litellm_completion_request={"model": "test"},
+ request_input="hi",
+ responses_api_request={"previous_response_id": "123"},
+ litellm_trace_id="original-trace",
+ )
+ # ensure acompletion called once with merged trace_id
+ assert mock_acompletion.call_count == 1
+ assert (
+ mock_acompletion.call_args.kwargs["litellm_trace_id"] == "session-trace"
+ )
\ No newline at end of file
diff --git a/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py b/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py
index c2e17d3ef46..e637066d2f9 100644
--- a/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py
+++ b/tests/openai_endpoints_tests/test_e2e_openai_responses_api.py
@@ -119,3 +119,12 @@ def test_bad_request_bad_param_error():
client.responses.create(
model="gpt-4o", input="This should fail", temperature=2000
)
+
+def test_anthropic_with_responses_api():
+ client = get_test_client()
+ response = client.responses.create(
+ model="anthropic/claude-3-5-sonnet-20240620",
+ input="just respond with the word 'ping'",
+ previous_response_id="hi",
+ )
+ print("anthropic response=", response)