# 31951: Stream - Protocol - Invalid Message

Log Type: APPLICATION

Log Level: WARNING

## Description

Twilio sends warning 31951 once per Stream when your WebSocket server sends a message that does not comply with the Media Streams protocol. For bidirectional Streams, Twilio only accepts the documented `media`, `mark`, and `clear` message types, and each message must include the expected fields for that event.

### Possible causes

* The message was not valid JSON.
* The message used an unsupported event type. Twilio only accepts `media`, `mark`, and `clear` messages from your server on a bidirectional Stream.
* The message was missing required fields, included unexpected fields, or used the wrong object structure for the selected event.
* The `streamSid` in the message did not match the active Stream.

### Possible solutions

* Serialize each outbound message as valid JSON before you send it over the WebSocket connection.
* If you need to send messages back to Twilio, use `<Connect><Stream>` and send only the supported `media`, `mark`, and `clear` events.
* Validate each message against the documented schema before sending it. Include `event`, `streamSid`, and the correct event payload object for that message type.
* Use the `streamSid` from Twilio's `start` message for the current Stream, and do not reuse a SID from another call or stream.

#### Additional resources

* [Media Streams overview](/docs/voice/media-streams)
* [Media Streams WebSocket messages](/docs/voice/media-streams/websocket-messages)
* [TwiML `<Stream>`](/docs/voice/twiml/stream)
