microsoft/semantic-kernel · error · ContentException

Audio is required for InputAudioBufferAppendEvent

Error message

Audio is required for InputAudioBufferAppendEvent

What it means

The OpenAI Realtime API's input_audio_buffer.append event requires base64-encoded audio data in the 'audio' field. The event factory raises ContentException if 'audio' is not in kwargs when event_type is SendEvents.INPUT_AUDIO_BUFFER_APPEND.

Source

Thrown at python/semantic_kernel/connectors/ai/open_ai/services/_open_ai_realtime.py:182

        event_type = SendEvents(event_type)
    match event_type:
        case SendEvents.SESSION_UPDATE:
            if "session" not in kwargs:
                raise ContentException("Session is required for SessionUpdateEvent")
            session_dict = kwargs.pop("session")
            # Create proper RealtimeSessionCreateRequest with required type field for SDK validation
            # The OpenAI SDK will handle the proper serialization for the API
            from openai.types.realtime import RealtimeSessionCreateRequest

            session_request = RealtimeSessionCreateRequest(type="realtime", **session_dict)
            return SessionUpdateEvent(
                type=event_type.value,
                session=session_request,
                **kwargs,
            )
        case SendEvents.INPUT_AUDIO_BUFFER_APPEND:
            if "audio" not in kwargs:
                raise ContentException("Audio is required for InputAudioBufferAppendEvent")
            return InputAudioBufferAppendEvent(
                type=event_type.value,
                **kwargs,
            )
        case SendEvents.INPUT_AUDIO_BUFFER_COMMIT:
            return InputAudioBufferCommitEvent(
                type=event_type.value,
                **kwargs,
            )
        case SendEvents.INPUT_AUDIO_BUFFER_CLEAR:
            return InputAudioBufferClearEvent(
                type=event_type.value,
                **kwargs,
            )
        case SendEvents.CONVERSATION_ITEM_CREATE:
            if "item" not in kwargs:
                raise ContentException("Item is required for ConversationItemCreateEvent")
            kwargs["type"] = event_type.value

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Always pass base64-encoded audio: send(SendEvents.INPUT_AUDIO_BUFFER_APPEND, audio=base64.b64encode(raw_pcm).decode()).
  2. Add a guard in your audio stream loop: skip the send if the audio chunk is empty or None.
  3. Verify the key name is exactly 'audio' — not 'data', 'payload', or 'bytes'.

Example fix

// before
await service.send(SendEvents.INPUT_AUDIO_BUFFER_APPEND)
// after
import base64
await service.send(SendEvents.INPUT_AUDIO_BUFFER_APPEND, audio=base64.b64encode(pcm_chunk).decode('utf-8'))
Defensive patterns

Strategy: validation

Validate before calling

import base64

def validate_audio_append_kwargs(kwargs: dict) -> None:
    if 'audio' not in kwargs:
        raise ValueError('INPUT_AUDIO_BUFFER_APPEND requires an audio kwarg')
    if not isinstance(kwargs['audio'], str):
        raise TypeError('audio must be a base64-encoded string')

Type guard

def has_valid_audio_kwarg(kwargs: dict) -> bool:
    return 'audio' in kwargs and isinstance(kwargs['audio'], str) and len(kwargs['audio']) > 0

Try / catch

from semantic_kernel.exceptions import ContentException

async def safe_send_audio(service, pcm_chunk):
    if pcm_chunk is None or len(pcm_chunk) == 0:
        return  # skip empty chunks
    audio_b64 = base64.b64encode(pcm_chunk).decode('utf-8')
    try:
        await service.send(SendEvents.INPUT_AUDIO_BUFFER_APPEND, audio=audio_b64)
    except ContentException:
        pass  # malformed, skip

Prevention

When it happens

Trigger: Calling send(SendEvents.INPUT_AUDIO_BUFFER_APPEND) without an 'audio' kwarg — e.g. forgetting to encode and pass the audio chunk, or passing it under a different key name like 'data' or 'payload'.

Common situations: Streaming audio pipeline where an empty buffer is accidentally sent on init; renaming the audio key during a refactor; a microphone capture callback that yields None on the first tick.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/0dd652edada4622c. Report an issue: GitHub.