# `OpenrouterSdk.SSE`
[🔗](https://github.com/zmzlois/openrouter_sdk/blob/v0.1.0/lib/openrouter_sdk/sse.ex#L1)

incremental server-sent-events parser.

pure functional: `feed(state, bytes) -> {events, new_state}`. the
caller pumps bytes in (typically arriving from finch), and gets back
whatever fully-formed events the parser could complete from the
combined buffer. partial lines stay in `state.buffer`.

understands:
  * `data:`, `event:`, `id:`, `retry:`
  * comment lines starting with `:`
  * crlf and lf line endings
  * multi-line `data:` (joined with `\n`)
  * the openai-style `[DONE]` terminator (emitted as `:done`)

# `emitted`

```elixir
@type emitted() :: OpenrouterSdk.SSE.Event.t() | :done
```

# `state`

```elixir
@type state() :: %{
  buffer: binary(),
  event: String.t() | nil,
  id: String.t() | nil,
  data: [String.t()],
  retry: non_neg_integer() | nil
}
```

# `feed`

```elixir
@spec feed(state(), binary()) :: {[emitted()], state()}
```

feed bytes into the parser. returns `{events, new_state}` where
`events` is the (possibly empty) list of newly completed events in
arrival order.

# `init`

```elixir
@spec init() :: state()
```

fresh parser state

---

*Consult [api-reference.md](api-reference.md) for complete listing*
