BerriAI/litellm · error · ValueError

Unexpected delta type: {delta_type}

Error message

Unexpected delta type: {delta_type}

What it means

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.

Source

Thrown at litellm/llms/gemini/realtime/transformation.py:173

            parts: Final = model_turn["parts"]
            if len(parts) != 1:
                verbose_logger.warning("Realtime: Expected 1 part, got %s for Gemini model turn event.", len(parts))
            part: Final = parts[0]
            if "text" in part:
                return OpenAIRealtimeEventTypes.RESPONSE_TEXT_DELTA
            elif "inlineData" in part:
                return OpenAIRealtimeEventTypes.RESPONSE_AUDIO_DELTA
            else:
                raise ValueError(f"Unexpected part type: {part}")
        raise ValueError(f"Unexpected model turn event, no 'parts' key: {model_turn}")

    def map_generation_complete_event(self, delta_type: ALL_DELTA_TYPES | None) -> OpenAIRealtimeEventTypes:
        if delta_type == "text":
            return OpenAIRealtimeEventTypes.RESPONSE_TEXT_DONE
        elif delta_type == "audio":
            return OpenAIRealtimeEventTypes.RESPONSE_AUDIO_DONE
        else:
            raise ValueError(f"Unexpected delta type: {delta_type}")

    def get_audio_mime_type(self, input_audio_format: str = "pcm16"):
        mime_types: Final = {
            "pcm16": "audio/pcm;rate=24000",
            "g711_ulaw": "audio/pcmu",
            "g711_alaw": "audio/pcma",
        }

        return mime_types.get(input_audio_format, "application/octet-stream")

    def _manual_turn_detection_enabled(self, session_configuration_request: str | None) -> bool:
        if not session_configuration_request:
            return False
        try:
            setup: Final = json.loads(session_configuration_request).get("setup", {})
            automatic_detection: Final = setup.get("realtimeInputConfig", {}).get("automaticActivityDetection", {})
            return isinstance(automatic_detection, dict) and automatic_detection.get("disabled") is True
        except (json.JSONDecodeError, TypeError, AttributeError):

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Ensure the realtime session modalities are limited to text and audio.
  2. Upgrade litellm — check the changelog for realtime delta-type handling fixes.
  3. If invoking the transformer directly, only pass 'text' or 'audio' as delta_type.

Example fix

# before
event = config.map_generation_complete_event(delta_type)

# after
if delta_type not in ('text', 'audio'):
    logger.warning('Unsupported delta_type %r; defaulting to text', delta_type)
    delta_type = 'text'
event = config.map_generation_complete_event(delta_type)
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_DELTA_TYPES = {"text", "audio"}

def normalize_delta_type(delta_type):
    return delta_type if delta_type in SUPPORTED_DELTA_TYPES else "text"

Type guard

def is_supported_delta_type(dt: object) -> bool:
    return dt in ("text", "audio")

Try / catch

try:
    event = config.map_generation_complete_event(delta_type)
except ValueError as e:
    if "Unexpected delta type" in str(e):
        event = config.map_generation_complete_event("text")
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: Manual/replay use of the transformation API; custom session configurations with experimental modalities; litellm internal bug where current_delta_type is left uninitialized (None).

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/a7c72b5ac563ff19. Report an issue: GitHub.