Gemini.Client.HTTPStreaming (GeminiEx v0.0.2)
View SourceHTTP 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
Summary
Functions
Start an SSE stream with a callback function.
Start an SSE stream that sends events to a GenServer process.
Types
@type stream_callback() :: (stream_event() -> :ok | :stop)
Functions
@spec stream_sse( String.t(), [{String.t(), String.t()}], map(), stream_callback(), keyword() ) :: {:ok, :completed} | {:error, term()}
Start an SSE stream with a callback function.
Parameters
url
- Full URL for the streaming endpointheaders
- HTTP headers including authenticationbody
- Request body (will be JSON encoded)callback
- Function called for each eventopts
- Options including timeout, retry settings
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)
@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}