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
[Feat] Interactions API - allow using all litellm providers (interactions -> responses api bridge) (#18373)
Ishaan Jaff0f63cbea5932
diff --git a/docs/my-website/docs/interactions.md b/docs/my-website/docs/interactions.mdindex 5458a4463f5..1cd0f7be867 100644--- a/docs/my-website/docs/interactions.md+++ b/docs/my-website/docs/interactions.md@@ -8,7 +8,7 @@ import TabItem from '@theme/TabItem';| Logging | ✅ | Works across all integrations || Streaming | ✅ | || Loadbalancing | ✅ | Between supported models |-| Supported Providers | `gemini` | [Google Interactions API](https://ai.google.dev/gemini-api/docs/interactions) |+| Supported LLM providers | **All LiteLLM supported providers** | `openai`, `anthropic`, `bedrock`, `vertex_ai`, `gemini`, `azure`, `azure_ai` etc. |## **LiteLLM Python SDK Usage**@@ -207,8 +207,63 @@ for chunk in client.interactions.create_stream(}```+## **Calling non-Interactions API endpoints (`/interactions` to `/responses` Bridge)**++LiteLLM allows you to call non-Interactions API models via a bridge to LiteLLM's `/responses` endpoint. This is useful for calling OpenAI, Anthropic, and other providers that don't natively support the Interactions API.++#### Python SDK Usage++```python showLineNumbers title="SDK Usage"+import litellm+import os++# Set API key+os.environ["OPENAI_API_KEY"] = "your-openai-api-key"++# Non-streaming interaction+response = litellm.interactions.create(+ model="gpt-4o",+ input="Tell me a short joke about programming."+)++print(response.outputs[-1].text)+```++#### LiteLLM Proxy Usage++**Setup Config:**++```yaml showLineNumbers title="Example Configuration"+model_list:+- model_name: openai-model+ litellm_params:+ model: gpt-4o+ api_key: os.environ/OPENAI_API_KEY+```++**Start Proxy:**++```bash showLineNumbers title="Start LiteLLM Proxy"+litellm --config /path/to/config.yaml++# RUNNING on http://0.0.0.0:4000+```++**Make Request:**++```bash showLineNumbers title="non-Interactions API Model Request"+curl http://localhost:4000/v1beta/interactions \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer sk-1234" \+ -d '{+ "model": "openai-model",+ "input": "Tell me a short joke about programming."+ }'+```+## **Supported Providers**| Provider | Link to Usage ||----------|---------------|| Google AI Studio | [Usage](#quick-start) |+| All other LiteLLM providers | [Bridge Usage](#calling-non-interactions-api-endpoints-interactions-to-responses-bridge) |diff --git a/litellm/interactions/litellm_responses_transformation/__init__.py b/litellm/interactions/litellm_responses_transformation/__init__.pynew file mode 100644index 00000000000..2450a9f3d20--- /dev/null+++ b/litellm/interactions/litellm_responses_transformation/__init__.py@@ -0,0 +1,16 @@+"""+Bridge module for connecting Interactions API to Responses API via litellm.responses().+"""++from litellm.interactions.litellm_responses_transformation.handler import (+ LiteLLMResponsesInteractionsHandler,+)+from litellm.interactions.litellm_responses_transformation.transformation import (+ LiteLLMResponsesInteractionsConfig,+)++__all__ = [+ "LiteLLMResponsesInteractionsHandler",+ "LiteLLMResponsesInteractionsConfig", # Transformation config class (not BaseInteractionsAPIConfig)+]+diff --git a/litellm/interactions/litellm_responses_transformation/handler.py b/litellm/interactions/litellm_responses_transformation/handler.pynew file mode 100644index 00000000000..c2df8f96eff--- /dev/null+++ b/litellm/interactions/litellm_responses_transformation/handler.py@@ -0,0 +1,156 @@+"""+Handler for transforming interactions API requests to litellm.responses requests.+"""++from typing import (+ Any,+ AsyncIterator,+ Coroutine,+ Dict,+ Iterator,+ Optional,+ Union,+ cast,+)++import litellm+from litellm.interactions.litellm_responses_transformation.streaming_iterator import (+ LiteLLMResponsesInteractionsStreamingIterator,+)+from litellm.interactions.litellm_responses_transformation.transformation import (+ LiteLLMResponsesInteractionsConfig,+)+from litellm.responses.streaming_iterator import BaseResponsesAPIStreamingIterator+from litellm.types.interactions import (+ InteractionInput,+ InteractionsAPIOptionalRequestParams,+ InteractionsAPIResponse,+ InteractionsAPIStreamingResponse,+)+from litellm.types.llms.openai import ResponsesAPIResponse+++class LiteLLMResponsesInteractionsHandler:+ """Handler for bridging Interactions API to Responses API via litellm.responses()."""++ def interactions_api_handler(+ self,+ model: str,+ input: Optional[InteractionInput],+ optional_params: InteractionsAPIOptionalRequestParams,+ custom_llm_provider: Optional[str] = None,+ _is_async: bool = False,+ stream: Optional[bool] = None,+ **kwargs,+ ) -> Union[+ InteractionsAPIResponse,+ Iterator[InteractionsAPIStreamingResponse],+ Coroutine[+ Any,+ Any,+ Union[+ InteractionsAPIResponse,+ AsyncIterator[InteractionsAPIStreamingResponse],+ ],+ ],+ ]:+ """+ Handle Interactions API request by calling litellm.responses().++ Args:+ model: The model to use+ input: The input content+ optional_params: Optional parameters for the request+ custom_llm_provider: Override LLM provider+ _is_async: Whether this is an async call+ stream: Whether to stream the response+ **kwargs: Additional parameters++ Returns:+ InteractionsAPIResponse or streaming iterator+ """+ # Transform interactions request to responses request+ responses_request = (+ LiteLLMResponsesInteractionsConfig.transform_interactions_request_to_responses_request(+ model=model,+ input=input,+ optional_params=optional_params,+ custom_llm_provider=custom_llm_provider,+ stream=stream,+ **kwargs,+ )+ )++ if _is_async:+ return self.async_interactions_api_handler(+ responses_request=responses_request,+ model=model,+ input=input,+ optional_params=optional_params,+ **kwargs,+ )++ # Call litellm.responses()+ # Note: litellm.responses() returns Union[ResponsesAPIResponse, BaseResponsesAPIStreamingIterator]+ # but the type checker may see it as a coroutine in some contexts+ responses_response = litellm.responses(+ **responses_request,+ )++ # Handle streaming response+ if isinstance(responses_response, BaseResponsesAPIStreamingIterator):+ return LiteLLMResponsesInteractionsStreamingIterator(+ model=model,+ litellm_custom_stream_wrapper=responses_response,+ request_input=input,+ optional_params=optional_params,+ custom_llm_provider=custom_llm_provider,+ litellm_metadata=kwargs.get("litellm_metadata", {}),+ )++ # At this point, responses_response must be ResponsesAPIResponse (not streaming)+ # Cast to satisfy type checker since we've already checked it's not a streaming iterator+ responses_api_response = cast(ResponsesAPIResponse, responses_response)++ # Transform responses response to interactions response+ return LiteLLMResponsesInteractionsConfig.transform_responses_response_to_interactions_response(+ responses_response=responses_api_response,+ model=model,+ )++ async def async_interactions_api_handler(+ self,+ responses_request: Dict[str, Any],+ model: str,+ input: Optional[InteractionInput],+ optional_params: InteractionsAPIOptionalRequestParams,+ **kwargs,+ ) -> Union[InteractionsAPIResponse, AsyncIterator[InteractionsAPIStreamingResponse]]:+ """Async handler for interactions API requests."""+ # Call litellm.aresponses()+ # Note: litellm.aresponses() returns Union[ResponsesAPIResponse, BaseResponsesAPIStreamingIterator]+ responses_response = await litellm.aresponses(+ **responses_request,+ )++ # Handle streaming response+ if isinstance(responses_response, BaseResponsesAPIStreamingIterator):+ return LiteLLMResponsesInteractionsStreamingIterator(+ model=model,+ litellm_custom_stream_wrapper=responses_response,+ request_input=input,+ optional_params=optional_params,+ custom_llm_provider=responses_request.get("custom_llm_provider"),+ litellm_metadata=kwargs.get("litellm_metadata", {}),+ )++ # At this point, responses_response must be ResponsesAPIResponse (not streaming)+ # Cast to satisfy type checker since we've already checked it's not a streaming iterator+ responses_api_response = cast(ResponsesAPIResponse, responses_response)++ # Transform responses response to interactions response+ return LiteLLMResponsesInteractionsConfig.transform_responses_response_to_interactions_response(+ responses_response=responses_api_response,+ model=model,+ )+diff --git a/litellm/interactions/litellm_responses_transformation/streaming_iterator.py b/litellm/interactions/litellm_responses_transformation/streaming_iterator.pynew file mode 100644index 00000000000..511b69e83b2--- /dev/null+++ b/litellm/interactions/litellm_responses_transformation/streaming_iterator.py@@ -0,0 +1,260 @@+"""+Streaming iterator for transforming Responses API stream to Interactions API stream.+"""++from typing import Any, AsyncIterator, Dict, Iterator, Optional, cast++from litellm.responses.streaming_iterator import (+ BaseResponsesAPIStreamingIterator,+ ResponsesAPIStreamingIterator,+ SyncResponsesAPIStreamingIterator,+)+from litellm.types.interactions import (+ InteractionInput,+ InteractionsAPIOptionalRequestParams,+ InteractionsAPIStreamingResponse,+)+from litellm.types.llms.openai import (+ OutputTextDeltaEvent,+ ResponseCompletedEvent,+ ResponseCreatedEvent,+ ResponseInProgressEvent,+ ResponsesAPIStreamingResponse,+)+++class LiteLLMResponsesInteractionsStreamingIterator:+ """+ Iterator that wraps Responses API streaming and transforms chunks to Interactions API format.++ This class handles both sync and async iteration, transforming Responses API+ streaming events (output.text.delta, response.completed, etc.) to Interactions+ API streaming events (content.delta, interaction.complete, etc.).+ """++ def __init__(+ self,+ model: str,+ litellm_custom_stream_wrapper: BaseResponsesAPIStreamingIterator,+ request_input: Optional[InteractionInput],+ optional_params: InteractionsAPIOptionalRequestParams,+ custom_llm_provider: Optional[str] = None,+ litellm_metadata: Optional[Dict[str, Any]] = None,+ ):+ self.model = model+ self.responses_stream_iterator = litellm_custom_stream_wrapper+ self.request_input = request_input+ self.optional_params = optional_params+ self.custom_llm_provider = custom_llm_provider+ self.litellm_metadata = litellm_metadata or {}+ self.finished = False+ self.collected_text = ""+ self.sent_interaction_start = False+ self.sent_content_start = False++ def _transform_responses_chunk_to_interactions_chunk(+ self,+ responses_chunk: ResponsesAPIStreamingResponse,+ ) -> Optional[InteractionsAPIStreamingResponse]:+ """+ Transform a Responses API streaming chunk to an Interactions API streaming chunk.++ Responses API events:+ - output.text.delta -> content.delta+ - response.completed -> interaction.complete++ Interactions API events:+ - interaction.start+ - content.start+ - content.delta+ - content.stop+ - interaction.complete+ """+ if not responses_chunk:+ return None++ # Handle OutputTextDeltaEvent -> content.delta+ if isinstance(responses_chunk, OutputTextDeltaEvent):+ delta_text = responses_chunk.delta if isinstance(responses_chunk.delta, str) else ""+ self.collected_text += delta_text++ # Send interaction.start if not sent+ if not self.sent_interaction_start:+ self.sent_interaction_start = True+ return InteractionsAPIStreamingResponse(+ event_type="interaction.start",+ id=getattr(responses_chunk, "item_id", None) or f"interaction_{id(self)}",+ object="interaction",+ status="in_progress",+ model=self.model,+ )++ # Send content.start if not sent+ if not self.sent_content_start:+ self.sent_content_start = True+ return InteractionsAPIStreamingResponse(+ event_type="content.start",+ id=getattr(responses_chunk, "item_id", None),+ object="content",+ delta={"type": "text", "text": ""},+ )++ # Send content.delta+ return InteractionsAPIStreamingResponse(+ event_type="content.delta",+ id=getattr(responses_chunk, "item_id", None),+ object="content",+ delta={"text": delta_text},+ )++ # Handle ResponseCreatedEvent or ResponseInProgressEvent -> interaction.start+ if isinstance(responses_chunk, (ResponseCreatedEvent, ResponseInProgressEvent)):+ if not self.sent_interaction_start:+ self.sent_interaction_start = True+ response_id = getattr(responses_chunk.response, "id", None) if hasattr(responses_chunk, "response") else None+ return InteractionsAPIStreamingResponse(+ event_type="interaction.start",+ id=response_id or f"interaction_{id(self)}",+ object="interaction",+ status="in_progress",+ model=self.model,+ )++ # Handle ResponseCompletedEvent -> interaction.complete+ if isinstance(responses_chunk, ResponseCompletedEvent):+ self.finished = True+ response = responses_chunk.response++ # Send content.stop first if content was started+ if self.sent_content_start:+ # Note: We'll send this in the iterator, not here+ pass++ # Send interaction.complete+ return InteractionsAPIStreamingResponse(+ event_type="interaction.complete",+ id=getattr(response, "id", None) or f"interaction_{id(self)}",+ object="interaction",+ status="completed",+ model=self.model,+ outputs=[+ {+ "type": "text",+ "text": self.collected_text,+ }+ ],+ )++ # For other event types, return None (skip)+ return None++ def __iter__(self) -> Iterator[InteractionsAPIStreamingResponse]:+ """Sync iterator implementation."""+ return self++ def __next__(self) -> InteractionsAPIStreamingResponse:+ """Get next chunk in sync mode."""+ if self.finished:+ raise StopIteration++ # Check if we have a pending interaction.complete to send+ if hasattr(self, "_pending_interaction_complete"):+ pending: InteractionsAPIStreamingResponse = getattr(self, "_pending_interaction_complete")+ delattr(self, "_pending_interaction_complete")+ return pending++ # Use a loop instead of recursion to avoid stack overflow+ sync_iterator = cast(SyncResponsesAPIStreamingIterator, self.responses_stream_iterator)+ while True:+ try:+ # Get next chunk from responses API stream+ chunk = next(sync_iterator)++ # Transform chunk (chunk is already a ResponsesAPIStreamingResponse)+ transformed = self._transform_responses_chunk_to_interactions_chunk(chunk)++ if transformed:+ # If we finished and content was started, send content.stop before interaction.complete+ if self.finished and self.sent_content_start and transformed.event_type == "interaction.complete":+ # Send content.stop first+ content_stop = InteractionsAPIStreamingResponse(+ event_type="content.stop",+ id=transformed.id,+ object="content",+ delta={"type": "text", "text": self.collected_text},+ )+ # Store the interaction.complete to send next+ self._pending_interaction_complete = transformed+ return content_stop+ return transformed++ # If no transformation, continue to next chunk (loop continues)++ except StopIteration:+ self.finished = True++ # Send final events if needed+ if self.sent_content_start:+ return InteractionsAPIStreamingResponse(+ event_type="content.stop",+ object="content",+ delta={"type": "text", "text": self.collected_text},+ )++ raise StopIteration++ def __aiter__(self) -> AsyncIterator[InteractionsAPIStreamingResponse]:+ """Async iterator implementation."""+ return self++ async def __anext__(self) -> InteractionsAPIStreamingResponse:+ """Get next chunk in async mode."""+ if self.finished:+ raise StopAsyncIteration++ # Check if we have a pending interaction.complete to send+ if hasattr(self, "_pending_interaction_complete"):+ pending: InteractionsAPIStreamingResponse = getattr(self, "_pending_interaction_complete")+ delattr(self, "_pending_interaction_complete")+ return pending++ # Use a loop instead of recursion to avoid stack overflow+ async_iterator = cast(ResponsesAPIStreamingIterator, self.responses_stream_iterator)+ while True:+ try:+ # Get next chunk from responses API stream+ chunk = await async_iterator.__anext__()++ # Transform chunk (chunk is already a ResponsesAPIStreamingResponse)+ transformed = self._transform_responses_chunk_to_interactions_chunk(chunk)++ if transformed:+ # If we finished and content was started, send content.stop before interaction.complete+ if self.finished and self.sent_content_start and transformed.event_type == "interaction.complete":+ # Send content.stop first+ content_stop = InteractionsAPIStreamingResponse(+ event_type="content.stop",+ id=transformed.id,+ object="content",+ delta={"type": "text", "text": self.collected_text},+ )+ # Store the interaction.complete to send next+ self._pending_interaction_complete = transformed+ return content_stop+ return transformed++ # If no transformation, continue to next chunk (loop continues)++ except StopAsyncIteration:+ self.finished = True++ # Send final events if needed+ if self.sent_content_start:+ return InteractionsAPIStreamingResponse(+ event_type="content.stop",+ object="content",+ delta={"type": "text", "text": self.collected_text},+ )++ raise StopAsyncIteration+diff --git a/litellm/interactions/litellm_responses_transformation/transformation.py b/litellm/interactions/litellm_responses_transformation/transformation.pynew file mode 100644index 00000000000..24b2c5dbde7--- /dev/null+++ b/litellm/interactions/litellm_responses_transformation/transformation.py@@ -0,0 +1,277 @@+"""+Transformation utilities for bridging Interactions API to Responses API.++This module handles transforming between:+- Interactions API format (Google's format with Turn[], system_instruction, etc.)+- Responses API format (OpenAI's format with input[], instructions, etc.)+"""++from typing import Any, Dict, List, Optional, cast++from litellm.types.interactions import (+ InteractionInput,+ InteractionsAPIOptionalRequestParams,+ InteractionsAPIResponse,+ Turn,+)+from litellm.types.llms.openai import (+ ResponseInputParam,+ ResponsesAPIResponse,+)+++class LiteLLMResponsesInteractionsConfig:+ """Configuration class for transforming between Interactions API and Responses API."""++ @staticmethod+ def transform_interactions_request_to_responses_request(+ model: str,+ input: Optional[InteractionInput],+ optional_params: InteractionsAPIOptionalRequestParams,+ **kwargs,+ ) -> Dict[str, Any]:+ """+ Transform an Interactions API request to a Responses API request.++ Key transformations:+ - system_instruction -> instructions+ - input (string | Turn[]) -> input (ResponseInputParam)+ - tools -> tools (similar format)+ - generation_config -> temperature, top_p, etc.+ """+ responses_request: Dict[str, Any] = {+ "model": model,+ }++ # Transform input+ if input is not None:+ responses_request["input"] = (+ LiteLLMResponsesInteractionsConfig._transform_interactions_input_to_responses_input(+ input+ )+ )++ # Transform system_instruction -> instructions+ if optional_params.get("system_instruction"):+ responses_request["instructions"] = optional_params["system_instruction"]++ # Transform tools (similar format, pass through for now)+ if optional_params.get("tools"):+ responses_request["tools"] = optional_params["tools"]++ # Transform generation_config to temperature, top_p, etc.+ generation_config = optional_params.get("generation_config")+ if generation_config:+ if isinstance(generation_config, dict):+ if "temperature" in generation_config:+ responses_request["temperature"] = generation_config["temperature"]+ if "top_p" in generation_config:+ responses_request["top_p"] = generation_config["top_p"]+ if "top_k" in generation_config:+ # Responses API doesn't have top_k, skip it+ pass+ if "max_output_tokens" in generation_config:+ responses_request["max_output_tokens"] = generation_config["max_output_tokens"]++ # Pass through other optional params that match+ passthrough_params = ["stream", "store", "metadata", "user"]+ for param in passthrough_params:+ if param in optional_params and optional_params[param] is not None:+ responses_request[param] = optional_params[param]++ # Add any extra kwargs+ responses_request.update(kwargs)++ return responses_request++ @staticmethod+ def _transform_interactions_input_to_responses_input(+ input: InteractionInput,+ ) -> ResponseInputParam:+ """+ Transform Interactions API input to Responses API input format.++ Interactions API input can be:+ - string: "Hello"+ - Turn[]: [{"role": "user", "content": [...]}]+ - Content object++ Responses API input is:+ - string: "Hello"+ - Message[]: [{"role": "user", "content": [...]}]+ """+ if isinstance(input, str):+ # ResponseInputParam accepts str+ return cast(ResponseInputParam, input)++ if isinstance(input, list):+ # Turn[] format - convert to Responses API Message[] format+ messages = []+ for turn in input:+ if isinstance(turn, dict):+ role = turn.get("role", "user")+ content = turn.get("content", [])++ # Transform content array+ transformed_content = (+ LiteLLMResponsesInteractionsConfig._transform_content_array(content)+ )++ messages.append({+ "role": role,+ "content": transformed_content,+ })+ elif isinstance(turn, Turn):+ # Pydantic model+ role = turn.role if hasattr(turn, "role") else "user"+ content = turn.content if hasattr(turn, "content") else []++ # Ensure content is a list for _transform_content_array+ # Cast to List[Any] to handle various content types+ if isinstance(content, list):+ content_list: List[Any] = list(content)+ elif content is not None:+ content_list = [content]+ else:+ content_list = []++ transformed_content = (+ LiteLLMResponsesInteractionsConfig._transform_content_array(content_list)+ )++ messages.append({+ "role": role,+ "content": transformed_content,+ })++ return cast(ResponseInputParam, messages)++ # Single content object - wrap in message+ if isinstance(input, dict):+ return cast(ResponseInputParam, [{+ "role": "user",+ "content": LiteLLMResponsesInteractionsConfig._transform_content_array(+ input.get("content", []) if isinstance(input.get("content"), list) else [input]+ ),+ }])++ # Fallback: convert to string+ return cast(ResponseInputParam, str(input))++ @staticmethod+ def _transform_content_array(content: List[Any]) -> List[Dict[str, Any]]:+ """Transform Interactions API content array to Responses API format."""+ if not isinstance(content, list):+ # Single content item - wrap in array+ content = [content]++ transformed: List[Dict[str, Any]] = []+ for item in content:+ if isinstance(item, dict):+ # Already in dict format, pass through+ transformed.append(item)+ elif isinstance(item, str):+ # Plain string - wrap in text format+ transformed.append({"type": "text", "text": item})+ else:+ # Pydantic model or other - convert to dict+ if hasattr(item, "model_dump"):+ dumped = item.model_dump()+ if isinstance(dumped, dict):+ transformed.append(dumped)+ else:+ # Fallback: wrap in text format+ transformed.append({"type": "text", "text": str(dumped)})+ elif hasattr(item, "dict"):+ dumped = item.dict()+ if isinstance(dumped, dict):+ transformed.append(dumped)+ else:+ # Fallback: wrap in text format+ transformed.append({"type": "text", "text": str(dumped)})+ else:+ # Fallback: wrap in text format+ transformed.append({"type": "text", "text": str(item)})++ return transformed++ @staticmethod+ def transform_responses_response_to_interactions_response(+ responses_response: ResponsesAPIResponse,+ model: Optional[str] = None,+ ) -> InteractionsAPIResponse:+ """+ Transform a Responses API response to an Interactions API response.++ Key transformations:+ - Extract text from output[].content[].text+ - Convert created_at (int) to created (ISO string)+ - Map status+ - Extract usage+ """+ # Extract text from outputs+ outputs = []+ if hasattr(responses_response, "output") and responses_response.output:+ for output_item in responses_response.output:+ # Use getattr with None default to safely access content+ content = getattr(output_item, "content", None)+ if content is not None:+ content_items = content if isinstance(content, list) else [content]+ for content_item in content_items:+ # Check if content_item has text attribute+ text = getattr(content_item, "text", None)+ if text is not None:+ outputs.append({+ "type": "text",+ "text": text,+ })+ elif isinstance(content_item, dict) and content_item.get("type") == "text":+ outputs.append(content_item)++ # Convert created_at to ISO string+ created_at = getattr(responses_response, "created_at", None)+ if isinstance(created_at, int):+ from datetime import datetime+ created = datetime.fromtimestamp(created_at).isoformat()+ elif created_at is not None and hasattr(created_at, "isoformat"):+ created = created_at.isoformat()+ else:+ created = None++ # Map status+ status = getattr(responses_response, "status", "completed")+ if status == "completed":+ interactions_status = "completed"+ elif status == "in_progress":+ interactions_status = "in_progress"+ else:+ interactions_status = status++ # Build interactions response+ interactions_response_dict: Dict[str, Any] = {+ "id": getattr(responses_response, "id", ""),+ "object": "interaction",+ "status": interactions_status,+ "outputs": outputs,+ "model": model or getattr(responses_response, "model", ""),+ "created": created,+ }++ # Add usage if available+ # Map Responses API usage (input_tokens, output_tokens) to Interactions API spec format+ # (total_input_tokens, total_output_tokens)+ usage = getattr(responses_response, "usage", None)+ if usage:+ interactions_response_dict["usage"] = {+ "total_input_tokens": getattr(usage, "input_tokens", 0),+ "total_output_tokens": getattr(usage, "output_tokens", 0),+ }++ # Add role+ interactions_response_dict["role"] = "model"++ # Add updated (same as created for now)+ interactions_response_dict["updated"] = created++ return InteractionsAPIResponse(**interactions_response_dict)+diff --git a/litellm/interactions/main.py b/litellm/interactions/main.pyindex 9fb58fc73d6..fb811b25b2f 100644--- a/litellm/interactions/main.py+++ b/litellm/interactions/main.py@@ -272,18 +272,30 @@ def create(model=model,)- if interactions_api_config is None:- raise ValueError(- f"Interactions API is not supported for provider: {custom_llm_provider}. "- "Currently only 'gemini' is supported."- )-# Get optional params using utility (similar to responses API pattern)local_vars.update(kwargs)optional_params = InteractionsAPIRequestUtils.get_requested_interactions_api_optional_params(local_vars)+ # Check if this is a bridge provider (litellm_responses) - similar to responses API+ # Either provider is explicitly "litellm_responses" or no config found (bridge to responses)+ if custom_llm_provider == "litellm_responses" or interactions_api_config is None:+ # Bridge to litellm.responses() for non-native providers+ from litellm.interactions.litellm_responses_transformation.handler import (+ LiteLLMResponsesInteractionsHandler,+ )+ handler = LiteLLMResponsesInteractionsHandler()+ return handler.interactions_api_handler(+ model=model or "",+ input=input,+ optional_params=optional_params,+ custom_llm_provider=custom_llm_provider,+ _is_async=_is_async,+ stream=stream,+ **kwargs,+ )+litellm_logging_obj.update_environment_variables(model=model,optional_params=dict(optional_params),diff --git a/provider_endpoints_support.json b/provider_endpoints_support.jsonindex 82b48b67195..45ee47c01bc 100644--- a/provider_endpoints_support.json+++ b/provider_endpoints_support.json@@ -47,7 +47,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"ai21": {@@ -64,7 +65,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"ai21_chat": {@@ -81,7 +83,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"amazon_nova": {@@ -98,7 +101,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"anthropic": {@@ -116,7 +120,8 @@"batches": true,"rerank": false,"skills": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"anthropic_text": {@@ -134,7 +139,8 @@"batches": true,"rerank": false,"skills": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"apertis": {@@ -167,7 +173,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"auto_router": {@@ -184,7 +191,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"bedrock": {@@ -201,7 +209,8 @@"moderations": false,"batches": false,"rerank": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"sagemaker": {@@ -218,7 +227,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"aws_polly": {@@ -251,7 +261,8 @@"moderations": true,"batches": true,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"azure_ai": {@@ -269,7 +280,8 @@"batches": true,"rerank": false,"ocr": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"azure_ai/doc-intelligence": {@@ -303,7 +315,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"azure_text": {@@ -320,7 +333,8 @@"moderations": true,"batches": true,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"baseten": {@@ -337,7 +351,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"bytez": {@@ -354,7 +369,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"cerebras": {@@ -371,7 +387,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"chutes": {@@ -404,7 +421,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"cloudflare": {@@ -421,7 +439,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"codestral": {@@ -438,7 +457,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"cohere": {@@ -455,7 +475,8 @@"moderations": false,"batches": false,"rerank": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"cohere_chat": {@@ -472,7 +493,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"cometapi": {@@ -489,7 +511,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"compactifai": {@@ -506,7 +529,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"custom": {@@ -523,7 +547,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"custom_openai": {@@ -540,7 +565,8 @@"moderations": true,"batches": true,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"dashscope": {@@ -557,7 +583,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"databricks": {@@ -574,7 +601,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"dataforseo": {@@ -608,7 +636,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"deepgram": {@@ -625,7 +654,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"deepinfra": {@@ -642,7 +672,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"deepseek": {@@ -659,7 +690,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"elevenlabs": {@@ -676,7 +708,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"exa_ai": {@@ -710,7 +743,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"fal_ai": {@@ -727,7 +761,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"featherless_ai": {@@ -744,7 +779,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"fireworks_ai": {@@ -761,7 +797,8 @@"moderations": false,"batches": false,"rerank": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"firecrawl": {@@ -812,7 +849,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"galadriel": {@@ -829,7 +867,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"github_copilot": {@@ -846,7 +885,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"github": {@@ -863,7 +903,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"vertex_ai": {@@ -881,7 +922,8 @@"batches": false,"rerank": false,"ocr": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"vertex_ai/chirp": {@@ -932,7 +974,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"groq": {@@ -949,7 +992,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"heroku": {@@ -966,7 +1010,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"hosted_vllm": {@@ -984,7 +1029,8 @@"batches": true,"files": true,"rerank": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"huggingface": {@@ -1001,7 +1047,8 @@"moderations": false,"batches": false,"rerank": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"hyperbolic": {@@ -1018,7 +1065,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"watsonx": {@@ -1035,7 +1083,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"infinity": {@@ -1084,7 +1133,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"lemonade": {@@ -1101,7 +1151,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"litellm_proxy": {@@ -1118,7 +1169,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"llamafile": {@@ -1135,7 +1187,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"lm_studio": {@@ -1152,7 +1205,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"maritalk": {@@ -1169,7 +1223,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"meta_llama": {@@ -1186,7 +1241,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"mistral": {@@ -1204,7 +1260,8 @@"batches": false,"rerank": false,"ocr": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"moonshot": {@@ -1221,7 +1278,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"docker_model_runner": {@@ -1238,7 +1296,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"morph": {@@ -1255,7 +1314,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"nanogpt": {@@ -1288,7 +1348,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"nlp_cloud": {@@ -1305,7 +1366,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"novita": {@@ -1322,7 +1384,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"nscale": {@@ -1339,7 +1402,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"nvidia_nim": {@@ -1356,7 +1420,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"oci": {@@ -1373,7 +1438,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"ollama": {@@ -1390,7 +1456,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"ollama_chat": {@@ -1407,7 +1474,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"oobabooga": {@@ -1424,7 +1492,8 @@"moderations": true,"batches": true,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"openai": {@@ -1450,7 +1519,8 @@"retrieve_container_file": true,"retrieve_container_file_content": true,"delete_container_file": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"openai_like": {@@ -1483,7 +1553,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"ovhcloud": {@@ -1500,7 +1571,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"parallel_ai": {@@ -1535,7 +1607,8 @@"batches": false,"rerank": false,"search": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"petals": {@@ -1552,7 +1625,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"poe": {@@ -1585,7 +1659,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"predibase": {@@ -1602,7 +1677,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"recraft": {@@ -1635,7 +1711,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"runwayml": {@@ -1669,7 +1746,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"searxng": {@@ -1703,7 +1781,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"sap": {@@ -1720,7 +1799,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"snowflake": {@@ -1737,7 +1817,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"synthetic": {@@ -1770,7 +1851,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"text-completion-openai": {@@ -1787,7 +1869,8 @@"moderations": true,"batches": true,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"together_ai": {@@ -1804,7 +1887,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"topaz": {@@ -1821,7 +1905,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"tavily": {@@ -1855,7 +1940,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"v0": {@@ -1872,7 +1958,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"vercel_ai_gateway": {@@ -1889,7 +1976,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"vllm": {@@ -1907,7 +1995,8 @@"batches": true,"files": true,"rerank": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"volcengine": {@@ -1924,7 +2013,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"voyage": {@@ -1957,7 +2047,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"watsonx_text": {@@ -1974,7 +2065,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"xai": {@@ -1991,7 +2083,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"xinference": {@@ -2024,7 +2117,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"ragflow": {@@ -2042,7 +2136,8 @@"batches": false,"rerank": false,"vector_stores": true,- "a2a": true+ "a2a": true,+ "interactions": true}},"cursor": {@@ -2059,7 +2154,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"langgraph": {@@ -2076,7 +2172,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"vertex_ai/agent_engine": {@@ -2093,7 +2190,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}},"pydantic_ai_agents": {@@ -2144,7 +2242,8 @@"moderations": false,"batches": false,"rerank": false,- "a2a": true+ "a2a": true,+ "interactions": true}}}diff --git a/tests/test_litellm/interactions/base_interactions_test.py b/tests/test_litellm/interactions/base_interactions_test.pynew file mode 100644index 00000000000..b7748a45f32--- /dev/null+++ b/tests/test_litellm/interactions/base_interactions_test.py@@ -0,0 +1,111 @@+"""+Abstract base class for Interactions API tests.++This class provides common test cases that can be inherited by provider-specific+test classes. Subclasses must implement get_model() and get_api_key().+"""++import os+from abc import ABC, abstractmethod++import pytest++import litellm.interactions as interactions+++class BaseInteractionsTest(ABC):+ """Abstract base class for interactions API tests.++ Subclasses must implement get_model() and get_api_key().+ All test methods are inherited and run against the specific provider.+ """++ @abstractmethod+ def get_model(self) -> str:+ """Return the model string for this provider."""+ pass++ @abstractmethod+ def get_api_key(self) -> str:+ """Return the API key for this provider."""+ pass++ def test_create_simple_string_input(self):+ """Test creating an interaction with a simple string input."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response = interactions.create(+ model=self.get_model(),+ input="Hello, what is 2 + 2?",+ api_key=api_key,+ )+ assert response is not None+ assert response.id is not None or response.status is not None++ # Check outputs per OpenAPI spec+ if response.outputs:+ assert len(response.outputs) > 0++ # Check usage per OpenAPI spec+ if response.usage:+ # Usage is a dict in InteractionsAPIResponse+ if isinstance(response.usage, dict):+ assert response.usage.get("input_tokens") is not None or response.usage.get("output_tokens") is not None+ else:+ # If it's an object, check attributes+ assert hasattr(response.usage, "input_tokens") or hasattr(response.usage, "output_tokens")++ def test_create_with_system_instruction(self):+ """Test creating an interaction with system_instruction."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response = interactions.create(+ model=self.get_model(),+ input="What are you?",+ system_instruction="You are a helpful pirate assistant. Always respond like a pirate.",+ api_key=api_key,+ )+ assert response is not None+ # Verify the response reflects the system instruction+ if response.outputs:+ assert len(response.outputs) > 0++ def test_create_streaming(self):+ """Test creating a streaming interaction."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response_stream = interactions.create(+ model=self.get_model(),+ input="Count from 1 to 3.",+ stream=True,+ api_key=api_key,+ )++ # Collect all chunks+ chunks = []+ for chunk in response_stream:+ chunks.append(chunk)++ assert len(chunks) > 0++ @pytest.mark.asyncio+ async def test_acreate_simple(self):+ """Test async interaction creation."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response = await interactions.acreate(+ model=self.get_model(),+ input="What is the speed of light?",+ api_key=api_key,+ )+ assert response is not None+ assert response.id is not None or response.status is not None+diff --git a/tests/test_litellm/interactions/test_gemini_interactions.py b/tests/test_litellm/interactions/test_gemini_interactions.pynew file mode 100644index 00000000000..c75e1d8a860--- /dev/null+++ b/tests/test_litellm/interactions/test_gemini_interactions.py@@ -0,0 +1,24 @@+"""+Tests for Gemini Interactions API.++Inherits from BaseInteractionsTest to run the same test suite against Gemini.+"""++import os++from tests.test_litellm.interactions.base_interactions_test import (+ BaseInteractionsTest,+)+++class TestGeminiInteractions(BaseInteractionsTest):+ """Test Gemini Interactions API using the base test suite."""++ def get_model(self) -> str:+ """Return the Gemini model string."""+ return "gemini/gemini-2.5-flash"++ def get_api_key(self) -> str:+ """Return the Gemini API key from environment."""+ return os.getenv("GEMINI_API_KEY", "")+diff --git a/tests/test_litellm/interactions/test_litellm_responses_bridge.py b/tests/test_litellm/interactions/test_litellm_responses_bridge.pynew file mode 100644index 00000000000..f99090f8363--- /dev/null+++ b/tests/test_litellm/interactions/test_litellm_responses_bridge.py@@ -0,0 +1,29 @@+"""+Tests for LiteLLM Responses bridge provider.++Inherits from BaseInteractionsTest to run the same test suite against+the litellm_responses bridge provider, which calls litellm.responses() internally.+"""++import os++from tests.test_litellm.interactions.base_interactions_test import (+ BaseInteractionsTest,+)+++class TestLiteLLMResponsesBridge(BaseInteractionsTest):+ """Test LiteLLM Responses bridge using the base test suite."""++ def get_model(self) -> str:+ """Return the model string for the bridge provider.++ The bridge provider uses litellm.responses() internally, so we can+ use any model that litellm.responses() supports (e.g., gpt-4o).+ """+ return "gpt-4o"++ def get_api_key(self) -> str:+ """Return the OpenAI API key from environment."""+ return os.getenv("OPENAI_API_KEY", "")+diff --git a/tests/unified_google_tests/base_interactions_test.py b/tests/unified_google_tests/base_interactions_test.pynew file mode 100644index 00000000000..0a07fe87fa5--- /dev/null+++ b/tests/unified_google_tests/base_interactions_test.py@@ -0,0 +1,113 @@+"""+Abstract base class for Interactions API tests.++This class provides common test cases that can be inherited by provider-specific+test classes. Subclasses must implement get_model() and get_api_key().+"""++import os+from abc import ABC, abstractmethod++import pytest+import litellm+import litellm.interactions as interactions+++class BaseInteractionsTest(ABC):+ """Abstract base class for interactions API tests.++ Subclasses must implement get_model() and get_api_key().+ All test methods are inherited and run against the specific provider.+ """++ @abstractmethod+ def get_model(self) -> str:+ """Return the model string for this provider."""+ pass++ @abstractmethod+ def get_api_key(self) -> str:+ """Return the API key for this provider."""+ pass++ def test_create_simple_string_input(self):+ """Test creating an interaction with a simple string input."""+ litellm._turn_on_debug()+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response = interactions.create(+ model=self.get_model(),+ input="Hello, what is 2 + 2?",+ api_key=api_key,+ )+ assert response is not None+ assert response.id is not None or response.status is not None++ # Check outputs per OpenAPI spec+ if response.outputs:+ assert len(response.outputs) > 0++ # Check usage per OpenAPI spec+ # The spec defines: total_input_tokens, total_output_tokens+ if response.usage:+ # Usage is a dict in InteractionsAPIResponse+ if isinstance(response.usage, dict):+ assert response.usage.get("total_input_tokens") is not None or response.usage.get("total_output_tokens") is not None+ else:+ # If it's an object, check attributes+ assert hasattr(response.usage, "total_input_tokens") or hasattr(response.usage, "total_output_tokens")++ def test_create_with_system_instruction(self):+ """Test creating an interaction with system_instruction."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response = interactions.create(+ model=self.get_model(),+ input="What are you?",+ system_instruction="You are a helpful pirate assistant. Always respond like a pirate.",+ api_key=api_key,+ )+ assert response is not None+ # Verify the response reflects the system instruction+ if response.outputs:+ assert len(response.outputs) > 0++ def test_create_streaming(self):+ """Test creating a streaming interaction."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response_stream = interactions.create(+ model=self.get_model(),+ input="Count from 1 to 3.",+ stream=True,+ api_key=api_key,+ )++ # Collect all chunks+ chunks = []+ for chunk in response_stream:+ chunks.append(chunk)++ assert len(chunks) > 0++ @pytest.mark.asyncio+ async def test_acreate_simple(self):+ """Test async interaction creation."""+ api_key = self.get_api_key()+ if not api_key:+ pytest.skip(f"API key not set for {self.__class__.__name__}")++ response = await interactions.acreate(+ model=self.get_model(),+ input="What is the speed of light?",+ api_key=api_key,+ )+ assert response is not None+ assert response.id is not None or response.status is not None+diff --git a/tests/unified_google_tests/test_gemini_interactions.py b/tests/unified_google_tests/test_gemini_interactions.pynew file mode 100644index 00000000000..eb1e104d80f--- /dev/null+++ b/tests/unified_google_tests/test_gemini_interactions.py@@ -0,0 +1,24 @@+"""+Tests for Gemini Interactions API.++Inherits from BaseInteractionsTest to run the same test suite against Gemini.+"""++import os++from tests.unified_google_tests.base_interactions_test import (+ BaseInteractionsTest,+)+++class TestGeminiInteractions(BaseInteractionsTest):+ """Test Gemini Interactions API using the base test suite."""++ def get_model(self) -> str:+ """Return the Gemini model string."""+ return "gemini/gemini-2.5-flash"++ def get_api_key(self) -> str:+ """Return the Gemini API key from environment."""+ return os.getenv("GEMINI_API_KEY", "")+diff --git a/tests/unified_google_tests/test_litellm_responses_bridge.py b/tests/unified_google_tests/test_litellm_responses_bridge.pynew file mode 100644index 00000000000..3c1342f650c--- /dev/null+++ b/tests/unified_google_tests/test_litellm_responses_bridge.py@@ -0,0 +1,29 @@+"""+Tests for LiteLLM Responses bridge provider.++Inherits from BaseInteractionsTest to run the same test suite against+the litellm_responses bridge provider, which calls litellm.responses() internally.+"""++import os++from tests.unified_google_tests.base_interactions_test import (+ BaseInteractionsTest,+)+++class TestLiteLLMResponsesBridge(BaseInteractionsTest):+ """Test LiteLLM Responses bridge using the base test suite."""++ def get_model(self) -> str:+ """Return the model string for the bridge provider.++ The bridge provider uses litellm.responses() internally, so we can+ use any model that litellm.responses() supports (e.g., gpt-4o).+ """+ return "gpt-4o"++ def get_api_key(self) -> str:+ """Return the OpenAI API key from environment."""+ return os.getenv("OPENAI_API_KEY", "")+