# `Gemini.Client.HTTPStreaming`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/client/http_streaming.ex#L1)

HTTP client for streaming Server-Sent Events (SSE) from Gemini API.

Provides proper streaming support with:
- Incremental SSE parsing
- Connection management
- Error handling and retries
- Backpressure support

# `stream_callback`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/client/http_streaming.ex#L29)

```elixir
@type stream_callback() :: (stream_event() -&gt; :ok | :stop)
```

# `stream_event`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/client/http_streaming.ex#L23)

```elixir
@type stream_event() :: %{
  type: :data | :error | :complete,
  data: map() | nil,
  error: term() | nil
}
```

# `stream_sse`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/client/http_streaming.ex#L69)

```elixir
@spec stream_sse(
  String.t(),
  [{String.t(), String.t()}],
  map() | nil,
  stream_callback(),
  keyword()
) :: {:ok, :completed} | {:error, term()}
```

Start an SSE stream with a callback function.

## Parameters
- `url` - Full URL for the streaming endpoint
- `headers` - HTTP headers including authentication
- `body` - Request body (will be JSON encoded)
- `callback` - Function called for each event
- `opts` - Options including timeout, retry settings
  - `:timeout` - Receive timeout per attempt (default: `Gemini.Config.timeout/0`)
  - `:max_retries` - Number of retry attempts (default: 3)
  - `:max_backoff_ms` - Max backoff between retries (default: 10_000)
  - `:connect_timeout` - Finch connect timeout (default: 5_000)

## Examples

    callback = fn
      %{type: :data, data: data} ->
        IO.puts("Received data")
        :ok
      %{type: :complete} ->
        IO.puts("Stream complete")
        :ok
      %{type: :error, error: _error} ->
        IO.puts("Stream error")
        :stop
    end

    HTTPStreaming.stream_sse(url, headers, body, callback)

# `stream_to_process`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/client/http_streaming.ex#L154)

```elixir
@spec stream_to_process(
  String.t(),
  [{String.t(), String.t()}],
  map(),
  String.t(),
  pid(),
  keyword()
) :: {:ok, pid()} | {:error, term()}
```

Start an SSE stream that sends events to a GenServer process.

Events are sent as messages: {:stream_event, stream_id, event}

---

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