{"record":{"id":"a7c72b5ac563ff19","repo":"BerriAI/litellm","slug":"unexpected-delta-type-delta-type","errorCode":null,"errorMessage":"Unexpected delta type: {delta_type}","messagePattern":"Unexpected delta type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/realtime/transformation.py","lineNumber":173,"sourceCode":"            parts: Final = model_turn[\"parts\"]\n            if len(parts) != 1:\n                verbose_logger.warning(\"Realtime: Expected 1 part, got %s for Gemini model turn event.\", len(parts))\n            part: Final = parts[0]\n            if \"text\" in part:\n                return OpenAIRealtimeEventTypes.RESPONSE_TEXT_DELTA\n            elif \"inlineData\" in part:\n                return OpenAIRealtimeEventTypes.RESPONSE_AUDIO_DELTA\n            else:\n                raise ValueError(f\"Unexpected part type: {part}\")\n        raise ValueError(f\"Unexpected model turn event, no 'parts' key: {model_turn}\")\n\n    def map_generation_complete_event(self, delta_type: ALL_DELTA_TYPES | None) -> OpenAIRealtimeEventTypes:\n        if delta_type == \"text\":\n            return OpenAIRealtimeEventTypes.RESPONSE_TEXT_DONE\n        elif delta_type == \"audio\":\n            return OpenAIRealtimeEventTypes.RESPONSE_AUDIO_DONE\n        else:\n            raise ValueError(f\"Unexpected delta type: {delta_type}\")\n\n    def get_audio_mime_type(self, input_audio_format: str = \"pcm16\"):\n        mime_types: Final = {\n            \"pcm16\": \"audio/pcm;rate=24000\",\n            \"g711_ulaw\": \"audio/pcmu\",\n            \"g711_alaw\": \"audio/pcma\",\n        }\n\n        return mime_types.get(input_audio_format, \"application/octet-stream\")\n\n    def _manual_turn_detection_enabled(self, session_configuration_request: str | None) -> bool:\n        if not session_configuration_request:\n            return False\n        try:\n            setup: Final = json.loads(session_configuration_request).get(\"setup\", {})\n            automatic_detection: Final = setup.get(\"realtimeInputConfig\", {}).get(\"automaticActivityDetection\", {})\n            return isinstance(automatic_detection, dict) and automatic_detection.get(\"disabled\") is True\n        except (json.JSONDecodeError, TypeError, AttributeError):","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/gemini/realtime/transformation.py#L155-L191","documentation":"Raised in map_generation_complete_event when the delta_type passed in is neither 'text' nor 'audio'. The generation-complete mapper only understands those two delta kinds; anything else (None, 'tool', new modality) is a ValueError. This is an internal/programming error in the event pipeline rather than something the server triggers directly.","triggerScenarios":"The realtime transform pipeline calls map_generation_complete_event with a delta_type derived from the session that is None or an unsupported value — e.g. sessions configured with a non-text/audio modality, or a caller invoking the transformer manually with an arbitrary string.","commonSituations":"Manual/replay use of the transformation API; custom session configurations with experimental modalities; litellm internal bug where current_delta_type is left uninitialized (None).","solutions":["Ensure the realtime session modalities are limited to text and audio.","Upgrade litellm — check the changelog for realtime delta-type handling fixes.","If invoking the transformer directly, only pass 'text' or 'audio' as delta_type."],"exampleFix":"# before\nevent = config.map_generation_complete_event(delta_type)\n\n# after\nif delta_type not in ('text', 'audio'):\n    logger.warning('Unsupported delta_type %r; defaulting to text', delta_type)\n    delta_type = 'text'\nevent = config.map_generation_complete_event(delta_type)\n","handlingStrategy":"validation","validationCode":"SUPPORTED_DELTA_TYPES = {\"text\", \"audio\"}\n\ndef normalize_delta_type(delta_type):\n    return delta_type if delta_type in SUPPORTED_DELTA_TYPES else \"text\"","typeGuard":"def is_supported_delta_type(dt: object) -> bool:\n    return dt in (\"text\", \"audio\")","tryCatchPattern":"try:\n    event = config.map_generation_complete_event(delta_type)\nexcept ValueError as e:\n    if \"Unexpected delta type\" in str(e):\n        event = config.map_generation_complete_event(\"text\")\n    else:\n        raise","preventionTips":["Only pass 'text' or 'audio' as delta_type when calling transformers directly.","Limit session modalities to text and audio.","Unit-test your realtime pipeline against both delta types."],"tags":["gemini","realtime","event-mapping","internal","modality"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}