The Accept request header is set to text/html, text/event-stream on all htmx requests.
This tells the server that htmx accepts both HTML and SSE streams.
Example
Accept: text/html, text/event-stream
accept = request.headers.get('Accept') if 'text/event-stream' in accept: return stream_sse_events() else: return render_html()