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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(realtime): post-tool-call function_response id omission (#30446)
Sameer Kankutee73cbfb02682
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.pyindex 790bd0519d7..129e15a0bf2 100644--- a/litellm/llms/custom_httpx/llm_http_handler.py+++ b/litellm/llms/custom_httpx/llm_http_handler.py@@ -5537,9 +5537,7 @@ class BaseLLMHTTPHandler:import websocketsfrom websockets.asyncio.client import ClientConnection- url = self._append_query_params(- provider_config.get_complete_url(api_base, model, api_key), query_params- )+ url = provider_config.get_complete_url(api_base, model, api_key)headers = provider_config.validate_environment(headers=headers,model=model,diff --git a/litellm/llms/gemini/realtime/transformation.py b/litellm/llms/gemini/realtime/transformation.pyindex 74f6cd4d831..e153d00e6ab 100644--- a/litellm/llms/gemini/realtime/transformation.py+++ b/litellm/llms/gemini/realtime/transformation.py@@ -103,6 +103,10 @@ class GeminiRealtimeConfig(BaseRealtimeConfig):# bypassing spend and budget accounting.self._pending_usage_metadata: Optional[dict] = None+ def _include_function_response_id(self) -> bool:+ """Google AI Studio Gemini 3.5+ accepts ``id`` on functionResponses; Vertex AI rejects it."""+ return True+@staticmethoddef _usage_detail_alias(details: Any, defaults: Dict[str, int]) -> Dict[str, Any]:if not isinstance(details, dict):@@ -604,10 +608,9 @@ class GeminiRealtimeConfig(BaseRealtimeConfig):)# Build Gemini toolResponse format- function_response = {- "id": call_id,- "response": output_dict,- }+ function_response: dict[str, Any] = {"response": output_dict}+ if self._include_function_response_id() and call_id:+ function_response["id"] = call_idif function_name:function_response["name"] = function_namediff --git a/litellm/llms/vertex_ai/realtime/transformation.py b/litellm/llms/vertex_ai/realtime/transformation.pyindex d6441db7856..1fe9f15c9f0 100644--- a/litellm/llms/vertex_ai/realtime/transformation.py+++ b/litellm/llms/vertex_ai/realtime/transformation.py@@ -32,6 +32,9 @@ class VertexAIRealtimeConfig(GeminiRealtimeConfig):self._project = projectself._location = location+ def _include_function_response_id(self) -> bool:+ return False+# ------------------------------------------------------------------# URL# ------------------------------------------------------------------diff --git a/tests/test_litellm/llms/vertex_ai/realtime/test_vertex_ai_realtime_transformation.py b/tests/test_litellm/llms/vertex_ai/realtime/test_vertex_ai_realtime_transformation.pyindex 1ebd704be34..1f171496cce 100644--- a/tests/test_litellm/llms/vertex_ai/realtime/test_vertex_ai_realtime_transformation.py+++ b/tests/test_litellm/llms/vertex_ai/realtime/test_vertex_ai_realtime_transformation.py@@ -346,3 +346,74 @@ def test_vertex_does_not_warn_when_dropping_non_guardrail_session_update(caplog)"Vertex AI Realtime" in record.message and "session.update" in record.messagefor record in caplog.records)+++async def test_async_realtime_does_not_forward_client_query_params_to_vertex_backend(+ monkeypatch,+):+ """Regression: forwarding client ?model=/?intent= to the Vertex Live WSS URL causes 1007 errors.++ Exercises ``async_realtime`` end-to-end so that re-adding ``_append_query_params``+ (the reverted bug) would push ``model=``/``intent=`` onto the backend URL and fail here.+ """+ import websockets++ from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler++ cfg = VertexAIRealtimeConfig(+ access_token="tok", project="my-proj", location="us-central1"+ )++ captured = {}++ def fake_connect(url, *args, **kwargs):+ captured["url"] = url+ raise RuntimeError("stop before establishing the backend connection")++ monkeypatch.setattr(websockets, "connect", fake_connect)++ await BaseLLMHTTPHandler().async_realtime(+ model="gemini-live-2.5-flash-native-audio",+ websocket=AsyncMock(),+ logging_obj=MagicMock(),+ provider_config=cfg,+ headers={},+ query_params={+ "model": "gemini-live-2.5-flash-native-audio",+ "intent": "chat",+ },+ )++ assert "?" not in captured["url"]+ assert "model=" not in captured["url"]+ assert "intent=" not in captured["url"]+++def test_vertex_function_call_output_omits_id():+ """Regression: Vertex Live rejects ``id`` on toolResponse.functionResponses (1007)."""+ cfg = VertexAIRealtimeConfig(+ access_token="tok", project="my-proj", location="us-central1"+ )+ cfg._tool_call_id_to_name["call_abc123"] = "terminate_call"++ messages = cfg.transform_realtime_request(+ json.dumps(+ {+ "type": "conversation.item.create",+ "item": {+ "type": "function_call_output",+ "call_id": "call_abc123",+ "output": '{"status": "ok"}',+ },+ }+ ),+ "gemini-live-2.5-flash-native-audio",+ session_configuration_request="existing",+ )++ assert len(messages) == 1+ payload = json.loads(messages[0])+ function_response = payload["toolResponse"]["functionResponses"][0]+ assert "id" not in function_response+ assert function_response["name"] == "terminate_call"+ assert function_response["response"] == {"status": "ok"}