# `Gemini.Streaming.UnifiedManager`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L1)

Unified streaming manager that supports multiple authentication strategies.

This is the canonical streaming manager for the Gemini client, supporting concurrent
usage of both Gemini API and Vertex AI authentication strategies within the same
application.

Features:
- HTTP streaming with real-time event delivery
- Multi-authentication strategy support via MultiAuthCoordinator
- Per-stream authentication strategy selection
- Concurrent usage of multiple auth strategies
- Resource management and cleanup

# `auth_strategy`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L33)

```elixir
@type auth_strategy() :: :gemini | :vertex_ai | :governed_authority
```

# `manager_state`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L65)

```elixir
@type manager_state() :: %{
  streams: %{required(stream_id()) =&gt; stream_state()},
  stream_counter: non_neg_integer(),
  max_streams: pos_integer(),
  default_timeout: pos_integer()
}
```

# `stream_id`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L31)

```elixir
@type stream_id() :: String.t()
```

# `stream_state`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L49)

```elixir
@type stream_state() :: %{
  stream_id: stream_id(),
  stream_pid: pid() | nil,
  model: String.t(),
  request_body: map(),
  status: :starting | :active | :completed | :error | :stopped,
  error: term() | nil,
  started_at: DateTime.t(),
  subscribers: [subscriber_ref()],
  events_count: non_neg_integer(),
  last_event_at: DateTime.t() | nil,
  config: keyword(),
  auth_strategy: auth_strategy(),
  release_fn: nil | (atom(), map() | nil -&gt; :ok)
}
```

# `subscriber_ref`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L32)

```elixir
@type subscriber_ref() :: {pid(), reference()}
```

# `child_spec`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L17)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_stats`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L215)

```elixir
@spec get_stats() :: map()
```

Get manager statistics.

# `get_stream_info`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L207)

```elixir
@spec get_stream_info(stream_id()) :: {:ok, map()} | {:error, term()}
```

Get stream information.

# `list_streams`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L191)

```elixir
@spec list_streams() :: [stream_id()]
```

List all active streams.

# `start_link`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L78)

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start the unified streaming manager.

# `start_stream`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L114)

```elixir
@spec start_stream(String.t(), map(), keyword()) ::
  {:ok, stream_id()} | {:error, term()}
```

```elixir
@spec start_stream(term(), keyword(), pid()) :: {:ok, stream_id()} | {:error, term()}
```

Start a new stream.

## API Variants

### New API: start_stream(model, request_body, opts)
- `model`: The model to use for generation
- `request_body`: The request body for content generation
- `opts`: Options including auth strategy and other config

### Legacy API: start_stream(contents, opts, subscriber_pid)
- `contents`: Content to stream (string or list of Content structs)
- `opts`: Generation options (model, generation_config, etc.)
- `subscriber_pid`: Process to receive stream events

## Options
- `:auth`: Authentication strategy (`:gemini` or `:vertex_ai`)
- `:timeout`: Request timeout in milliseconds
- Other options passed to the streaming request

## Examples

    # New API with Gemini auth
    {:ok, stream_id} = UnifiedManager.start_stream(
      Gemini.Config.get_model(:flash_lite_latest),
      %{contents: [%{parts: [%{text: "Hello"}]}]},
      auth: :gemini
    )

    # Legacy API
    {:ok, stream_id} = UnifiedManager.start_stream("Hello", [model: Gemini.Config.get_model(:flash_lite_latest)], self())

# `stop_stream`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L175)

```elixir
@spec stop_stream(stream_id()) :: :ok | {:error, term()}
```

Stop a stream.

# `stream_status`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L183)

```elixir
@spec stream_status(stream_id()) :: {:ok, atom()} | {:error, term()}
```

Get the status of a stream.

# `subscribe`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L159)

```elixir
@spec subscribe(stream_id(), pid()) :: :ok | {:error, term()}
```

Subscribe to a stream to receive events.

# `subscribe_stream`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L199)

```elixir
@spec subscribe_stream(stream_id(), pid()) :: :ok | {:error, term()}
```

Subscribe to stream events.

# `unsubscribe`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.14.0/lib/gemini/streaming/unified_manager.ex#L167)

```elixir
@spec unsubscribe(stream_id(), pid()) :: :ok | {:error, term()}
```

Unsubscribe from a stream.

---

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