Skip to main content

SSE

Source file: examples/sse_protocol.hen

What It Demonstrates

  • protocol = sse
  • named stream sessions
  • ordinary HTTP opening requests, including POST plus a body for streaming APIs
  • receive steps with within
  • sse.event and sse.id captures

Key Pattern

protocol = sse
session = prices
GET {{ SSE_ORIGIN }}/prices/stream

---

session = prices
receive
within = 5s

& sse.id -> $EVENT_ID
^ & sse.event == "price"
^ & body.price === NUMBER

The first step still uses the normal HTTP request surface, so if your provider opens the stream with something like POST /chat/completions plus a JSON body, you can author that directly under protocol = sse.

Run It

hen verify ./examples/sse_protocol.hen
hen run ./examples/sse_protocol.hen all --non-interactive --input sse_origin=https://your-sse-fixture.example

What To Notice

  • The first step opens and holds the stream session.
  • That opening step can be a normal GET, POST, or other HTTP request shape.
  • The second step consumes the next queued event for that session.
  • The receive step is session-only, so it does not send a new body or form payload.
  • When the event payload is JSON, ordinary body... selectors keep working.

Related reference: Protocols