{"record":{"id":"30dd4b305519156f","repo":"microsoft/semantic-kernel","slug":"session-is-required-for-sessionupdateevent","errorCode":null,"errorMessage":"Session is required for SessionUpdateEvent","messagePattern":"Session is required for SessionUpdateEvent","errorType":"exception","errorClass":"ContentException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/_open_ai_realtime.py","lineNumber":168,"sourceCode":"    SESSION_UPDATE = \"session.update\"\n    INPUT_AUDIO_BUFFER_APPEND = \"input_audio_buffer.append\"\n    INPUT_AUDIO_BUFFER_COMMIT = \"input_audio_buffer.commit\"\n    INPUT_AUDIO_BUFFER_CLEAR = \"input_audio_buffer.clear\"\n    CONVERSATION_ITEM_CREATE = \"conversation.item.create\"\n    CONVERSATION_ITEM_TRUNCATE = \"conversation.item.truncate\"\n    CONVERSATION_ITEM_DELETE = \"conversation.item.delete\"\n    RESPONSE_CREATE = \"response.create\"\n    RESPONSE_CANCEL = \"response.cancel\"\n\n\ndef _create_openai_realtime_client_event(event_type: SendEvents | str, **kwargs: Any) -> RealtimeClientEvent:\n    \"\"\"Create an OpenAI Realtime client event from a event type and kwargs.\"\"\"\n    if isinstance(event_type, str):\n        event_type = SendEvents(event_type)\n    match event_type:\n        case SendEvents.SESSION_UPDATE:\n            if \"session\" not in kwargs:\n                raise ContentException(\"Session is required for SessionUpdateEvent\")\n            session_dict = kwargs.pop(\"session\")\n            # Create proper RealtimeSessionCreateRequest with required type field for SDK validation\n            # The OpenAI SDK will handle the proper serialization for the API\n            from openai.types.realtime import RealtimeSessionCreateRequest\n\n            session_request = RealtimeSessionCreateRequest(type=\"realtime\", **session_dict)\n            return SessionUpdateEvent(\n                type=event_type.value,\n                session=session_request,\n                **kwargs,\n            )\n        case SendEvents.INPUT_AUDIO_BUFFER_APPEND:\n            if \"audio\" not in kwargs:\n                raise ContentException(\"Audio is required for InputAudioBufferAppendEvent\")\n            return InputAudioBufferAppendEvent(\n                type=event_type.value,\n                **kwargs,\n            )","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/_open_ai_realtime.py#L150-L186","documentation":"The OpenAI Realtime API's session.update event requires a 'session' object describing the session configuration (modalities, voice, turn detection, etc.). The _create_openai_realtime_client_event factory function raises ContentException if 'session' is not present in kwargs when event_type is SendEvents.SESSION_UPDATE.","triggerScenarios":"Calling the realtime service's send/event API with SendEvents.SESSION_UPDATE (or the string 'session.update') without providing a session kwarg — e.g. service.send(RealtimeClientEvent('session.update')) with no session dict.","commonSituations":"Building events dynamically from user input or config where the session key was dropped; calling update_session() before session config is ready; misunderstanding the event API and thinking session is optional.","solutions":["Always include a session dict when sending SESSION_UPDATE: send(event_type='session.update', session={'modalities': ['text'], 'voice': 'alloy'}).","Use the high-level update_session() method which constructs the session dict for you.","Validate kwargs presence before constructing the event."],"exampleFix":"// before\nawait service.send(SendEvents.SESSION_UPDATE)\n// after\nawait service.send(SendEvents.SESSION_UPDATE, session={'modalities': ['text', 'audio'], 'voice': 'alloy'})","handlingStrategy":"validation","validationCode":"def validate_session_update_kwargs(kwargs: dict) -> None:\n    if 'session' not in kwargs:\n        raise ValueError('SESSION_UPDATE event requires a session kwarg')\n    if not isinstance(kwargs['session'], dict):\n        raise TypeError(f'session must be a dict, got {type(kwargs[\"session\"]).__name__}')","typeGuard":"def has_valid_session_kwarg(kwargs: dict) -> bool:\n    return 'session' in kwargs and isinstance(kwargs['session'], dict)","tryCatchPattern":"from semantic_kernel.exceptions import ContentException\n\ntry:\n    event = _create_openai_realtime_client_event(SendEvents.SESSION_UPDATE, **kwargs)\nexcept ContentException as e:\n    kwargs['session'] = default_session_config\n    event = _create_openai_realtime_client_event(SendEvents.SESSION_UPDATE, **kwargs)","preventionTips":["Use the high-level update_session() method instead of constructing events manually.","Always include a session dict when building SESSION_UPDATE events.","Centralize session config in a builder that guarantees the key is present."],"tags":["openai","realtime","webrtc","session","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}