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(interactions): bill only interaction creation, not GET polls
mateo-berrif1a5054a16a5
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 0f6e0ccf9c1..94ee595a169 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -1895,7 +1895,7 @@ class Logging(LiteLLMLoggingBaseClass):or isinstance(logging_result, FineTuningJob)or isinstance(logging_result, LiteLLMBatch)or isinstance(logging_result, ResponsesAPIResponse)- or isinstance(logging_result, InteractionsAPIResponse)+ or (isinstance(logging_result, InteractionsAPIResponse) and self._is_interactions_create_call_type())or isinstance(logging_result, OpenAIFileObject)or isinstance(logging_result, LiteLLMRealtimeStreamLoggingObject)or isinstance(logging_result, OpenAIModerationResponse)@@ -1913,6 +1913,22 @@ class Logging(LiteLLMLoggingBaseClass):return Truereturn False+ def _is_interactions_create_call_type(self) -> bool:+ """+ Only interaction creation is billable. GET polls, deletes, and cancels+ also return an ``InteractionsAPIResponse`` (with usage once completed),+ so recognizing those would write spend on every poll of a background+ interaction. The proxy sets ``call_type`` from its route_type+ (``create_interaction``/``acreate_interaction``); the SDK sets it from+ the decorated function name (``create``/``acreate``).+ """+ return self.call_type in (+ CallTypes.create_interaction.value,+ CallTypes.acreate_interaction.value,+ "create",+ "acreate",+ )+def _flush_passthrough_collected_chunks_helper(self,raw_bytes: List[bytes],diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 90ea99ceb23..0fafd4a27fe 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -396,6 +396,12 @@ class CallTypes(str, Enum):vector_store_search = "vector_store_search"avector_store_search = "avector_store_search"+ #########################################################+ # Google Interactions API Call Types+ #########################################################+ create_interaction = "create_interaction"+ acreate_interaction = "acreate_interaction"+########################################################## Container Call Types#########################################################diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.pyindex 3769c656b0c..2bf9f54d7c9 100644--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py@@ -3787,12 +3787,12 @@ INTERACTIONS_USAGE_BLOCK = {}-def _interactions_logging_obj(stream: bool):+def _interactions_logging_obj(stream: bool, call_type: str = "acreate"):logging_obj = LitellmLogging(model="gemini-2.5-flash",messages=[],stream=stream,- call_type="acreate",+ call_type=call_type,start_time=time.time(),litellm_call_id="interactions-call-id",function_id="interactions-fn-id",@@ -3807,14 +3807,46 @@ def _interactions_logging_obj(stream: bool):return logging_obj-def test_interactions_response_is_recognized_for_logging():[email protected]("call_type", ["create", "acreate", "create_interaction", "acreate_interaction"])+def test_interactions_response_is_recognized_for_logging(call_type):from litellm.types.interactions import InteractionsAPIResponse- logging_obj = _interactions_logging_obj(stream=False)+ logging_obj = _interactions_logging_obj(stream=False, call_type=call_type)response = InteractionsAPIResponse(id="interactions/abc", model="gemini-2.5-flash", status="completed")assert logging_obj._is_recognized_call_type_for_logging(logging_result=response) is True+ "call_type",+ ["aget", "get", "aget_interaction", "adelete_interaction", "acancel_interaction"],+)+def test_interactions_get_poll_is_not_billed(call_type):+ import datetime as dt++ from litellm.types.interactions import InteractionsAPIResponse++ logging_obj = _interactions_logging_obj(stream=False, call_type=call_type)+ response = InteractionsAPIResponse(+ id="interactions/abc",+ model="gemini-2.5-flash",+ status="completed",+ steps=[],+ usage=dict(INTERACTIONS_USAGE_BLOCK),+ )++ assert logging_obj._is_recognized_call_type_for_logging(logging_result=response) is False++ logging_obj._success_handler_helper_fn(+ result=response,+ start_time=dt.datetime.now(),+ end_time=dt.datetime.now(),+ cache_hit=False,+ )++ assert logging_obj.model_call_details.get("response_cost") is None+ assert logging_obj.model_call_details.get("standard_logging_object") is None++def test_non_streaming_interactions_success_sets_response_cost_and_usage():import datetime as dtdiff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.tsindex 5629cd6c8d4..59c0532ccbe 100644--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts@@ -21685,7 +21685,7 @@ export interface components {* CallTypes* @enum {string}*/- CallTypes: "embedding" | "aembedding" | "completion" | "acompletion" | "atext_completion" | "text_completion" | "image_generation" | "aimage_generation" | "image_edit" | "aimage_edit" | "moderation" | "amoderation" | "atranscription" | "transcription" | "aspeech" | "speech" | "rerank" | "arerank" | "search" | "asearch" | "_arealtime" | "_aresponses_websocket" | "create_batch" | "acreate_batch" | "aretrieve_batch" | "retrieve_batch" | "acancel_batch" | "cancel_batch" | "pass_through_endpoint" | "anthropic_messages" | "get_assistants" | "aget_assistants" | "create_assistants" | "acreate_assistants" | "delete_assistant" | "adelete_assistant" | "acreate_thread" | "create_thread" | "aget_thread" | "get_thread" | "a_add_message" | "add_message" | "aget_messages" | "get_messages" | "arun_thread" | "run_thread" | "arun_thread_stream" | "run_thread_stream" | "afile_retrieve" | "file_retrieve" | "afile_delete" | "file_delete" | "afile_list" | "file_list" | "acreate_file" | "create_file" | "afile_content" | "file_content" | "create_fine_tuning_job" | "acreate_fine_tuning_job" | "create_video" | "acreate_video" | "avideo_retrieve" | "video_retrieve" | "avideo_content" | "video_content" | "video_remix" | "avideo_remix" | "video_list" | "avideo_list" | "video_retrieve_job" | "avideo_retrieve_job" | "video_delete" | "avideo_delete" | "video_create_character" | "avideo_create_character" | "video_get_character" | "avideo_get_character" | "video_edit" | "avideo_edit" | "video_extension" | "avideo_extension" | "vector_store_file_create" | "avector_store_file_create" | "vector_store_file_list" | "avector_store_file_list" | "vector_store_file_retrieve" | "avector_store_file_retrieve" | "vector_store_file_content" | "avector_store_file_content" | "vector_store_file_update" | "avector_store_file_update" | "vector_store_file_delete" | "avector_store_file_delete" | "vector_store_create" | "avector_store_create" | "vector_store_search" | "avector_store_search" | "create_container" | "acreate_container" | "list_containers" | "alist_containers" | "retrieve_container" | "aretrieve_container" | "delete_container" | "adelete_container" | "list_container_files" | "alist_container_files" | "upload_container_file" | "aupload_container_file" | "create_sandbox" | "acreate_sandbox" | "delete_sandbox" | "adelete_sandbox" | "run_code" | "arun_code" | "code_interpreter_tool" | "acode_interpreter_tool" | "acancel_fine_tuning_job" | "cancel_fine_tuning_job" | "alist_fine_tuning_jobs" | "list_fine_tuning_jobs" | "aretrieve_fine_tuning_job" | "retrieve_fine_tuning_job" | "responses" | "aresponses" | "alist_input_items" | "llm_passthrough_route" | "allm_passthrough_route" | "generate_content" | "agenerate_content" | "generate_content_stream" | "agenerate_content_stream" | "ocr" | "aocr" | "call_mcp_tool" | "list_mcp_tools" | "asend_message" | "send_message" | "acreate_skill";+ CallTypes: "embedding" | "aembedding" | "completion" | "acompletion" | "atext_completion" | "text_completion" | "image_generation" | "aimage_generation" | "image_edit" | "aimage_edit" | "moderation" | "amoderation" | "atranscription" | "transcription" | "aspeech" | "speech" | "rerank" | "arerank" | "search" | "asearch" | "_arealtime" | "_aresponses_websocket" | "create_batch" | "acreate_batch" | "aretrieve_batch" | "retrieve_batch" | "acancel_batch" | "cancel_batch" | "pass_through_endpoint" | "anthropic_messages" | "get_assistants" | "aget_assistants" | "create_assistants" | "acreate_assistants" | "delete_assistant" | "adelete_assistant" | "acreate_thread" | "create_thread" | "aget_thread" | "get_thread" | "a_add_message" | "add_message" | "aget_messages" | "get_messages" | "arun_thread" | "run_thread" | "arun_thread_stream" | "run_thread_stream" | "afile_retrieve" | "file_retrieve" | "afile_delete" | "file_delete" | "afile_list" | "file_list" | "acreate_file" | "create_file" | "afile_content" | "file_content" | "create_fine_tuning_job" | "acreate_fine_tuning_job" | "create_video" | "acreate_video" | "avideo_retrieve" | "video_retrieve" | "avideo_content" | "video_content" | "video_remix" | "avideo_remix" | "video_list" | "avideo_list" | "video_retrieve_job" | "avideo_retrieve_job" | "video_delete" | "avideo_delete" | "video_create_character" | "avideo_create_character" | "video_get_character" | "avideo_get_character" | "video_edit" | "avideo_edit" | "video_extension" | "avideo_extension" | "vector_store_file_create" | "avector_store_file_create" | "vector_store_file_list" | "avector_store_file_list" | "vector_store_file_retrieve" | "avector_store_file_retrieve" | "vector_store_file_content" | "avector_store_file_content" | "vector_store_file_update" | "avector_store_file_update" | "vector_store_file_delete" | "avector_store_file_delete" | "vector_store_create" | "avector_store_create" | "vector_store_search" | "avector_store_search" | "create_interaction" | "acreate_interaction" | "create_container" | "acreate_container" | "list_containers" | "alist_containers" | "retrieve_container" | "aretrieve_container" | "delete_container" | "adelete_container" | "list_container_files" | "alist_container_files" | "upload_container_file" | "aupload_container_file" | "create_sandbox" | "acreate_sandbox" | "delete_sandbox" | "adelete_sandbox" | "run_code" | "arun_code" | "code_interpreter_tool" | "acode_interpreter_tool" | "acancel_fine_tuning_job" | "cancel_fine_tuning_job" | "alist_fine_tuning_jobs" | "list_fine_tuning_jobs" | "aretrieve_fine_tuning_job" | "retrieve_fine_tuning_job" | "responses" | "aresponses" | "alist_input_items" | "llm_passthrough_route" | "allm_passthrough_route" | "generate_content" | "agenerate_content" | "generate_content_stream" | "agenerate_content_stream" | "ocr" | "aocr" | "call_mcp_tool" | "list_mcp_tools" | "asend_message" | "send_message" | "acreate_skill";/** CallbackDelete */CallbackDelete: {/** Callback Name */