axum-impl-sse

Fix Axum SSE handler compile errors and connection drops with correct stream typing and KeepAlive.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-sse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: axum-impl-sse
Source: https://github.com/Impertio-Studio/Axum-Claude-Skill-Package/tree/main/skills/source/axum-impl/axum-impl-sse
Command: npx skills add https://github.com/Impertio-Studio/Axum-Claude-Skill-Package --skill axum-impl-sse

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Axum SSE handlers often fail to compile or misbehave in production because the stream item types, keep-alive behavior, and Event builder rules are easy to get subtly wrong.

Core Features & Use Cases

  • Correct SSE handler types: Ensures you return Sse with a stream that yields Result<Event, E> (including the required .map(Ok) for infallible streams).
  • Production-stable long-lived streaming: Prevents dropped connections and “quiet stream goes dead” issues by applying KeepAlive.
  • Safe, panic-free Event construction: Avoids runtime panics caused by calling single-use Event builder methods more than once, or placing newlines/CR/LF where they are forbidden.
  • SSE vs WebSockets decisioning: Guides you to choose SSE for receive-only browser clients using EventSource.

Quick Start

Implement an Axum route that returns Sse<impl Stream<Item = Result<Event, Infallible>>>, builds each message with Event::default().data(...), lifts the stream with .map(Ok), and attaches .keep_alive(KeepAlive::default()) for long-lived updates.

Frequently Asked Questions about axum-impl-sse

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Axum SSE handler compile errors when returning a stream?

To fix Axum SSE handler compile errors, ensure you return `Sse` over a stream yielding `Result<Event, E>`. Infallible streams require lifting items with `.map(Ok)` to match the expected `TryStream<Ok = Event>` signature.

Why does my Axum Server-Sent Events connection drop or go quiet in production?

Axum Server-Sent Events connections drop in production without KeepAlive. Attaching `.keep_alive(KeepAlive::default())` to your `Sse` response prevents idle proxies from closing long-lived streams.

Should I use Server-Sent Events or WebSockets for my Rust web streaming endpoint?

Use Server-Sent Events for receive-only browser clients using `EventSource`, such as log tails or LLM token feeds. Choose WebSockets when you need bidirectional communication instead of push-only HTTP streaming.

What causes runtime panics when building SSE Event objects in Axum?

Runtime panics in Axum SSE Event construction occur when calling single-use `Event` builder methods multiple times or placing newline/CR/LF characters in forbidden fields. Respect single-use and newline constraints to prevent crashes.

How do I stream LLM token feeds to an EventSource using Axum and tokio-stream?

Stream LLM token feeds by returning `Sse<impl Stream<Item = Result<Event, Infallible>>>` from your Axum route. Build messages with `Event::default().data(...)` and attach `KeepAlive` for stable browser EventSource consumption.