# `Gemini.Auth`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L1)

Authentication strategy behavior and implementations for Gemini and Vertex AI.

This module provides a unified interface for different authentication methods:
- Gemini API: Simple API key authentication
- Vertex AI: OAuth2/Service Account authentication

# `auth_type`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L10)

```elixir
@type auth_type() :: :gemini | :vertex_ai
```

# `credentials`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L11)

```elixir
@type credentials() ::
  %{api_key: String.t()}
  | %{access_token: String.t(), project_id: String.t(), location: String.t()}
```

# `build_headers`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L54)

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

Build authenticated headers for the given strategy and credentials.

Returns `{:ok, headers}` on success, or `{:error, reason}` if authentication fails
(e.g., service account token generation failure).

# `build_path`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L72)

```elixir
@spec build_path(auth_type(), String.t(), String.t(), map()) :: String.t()
```

Build the full path for an API endpoint.

# `get_base_url`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L63)

```elixir
@spec get_base_url(auth_type(), map()) :: String.t() | {:error, term()}
```

Get the base URL for the given strategy and credentials.

# `get_strategy`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L37)

```elixir
@spec get_strategy(auth_type()) :: module()
```

Get the appropriate authentication strategy based on configuration.

# `refresh_credentials`
[🔗](https://github.com/nshkrdotcom/gemini_ex/blob/v0.11.0/lib/gemini/auth.ex#L81)

```elixir
@spec refresh_credentials(auth_type(), map()) :: {:ok, map()} | {:error, term()}
```

Refresh credentials if needed (mainly for Vertex AI OAuth tokens).

---

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