# `H.Credentials`
[🔗](https://github.com/parlant/harness/blob/v0.3.0/lib/h/credentials.ex#L1)

In-memory credential resolver for LLM providers.

Credentials are resolved on demand from explicit options, environment
variables, H provider settings, or the Google Cloud CLI for ADC, and optionally
cached in memory with a TTL safety margin. Secrets are never persisted to disk
or included in inspected/sanitized error values.

# `anonymous_credentials`

```elixir
@type anonymous_credentials() :: %{auth_mode: :none}
```

# `api_key_credentials`

```elixir
@type api_key_credentials() :: %{api_key: String.t()}
```

# `codex_credentials`

```elixir
@type codex_credentials() :: %{access_token: String.t(), account_id: String.t() | nil}
```

# `credentials`

```elixir
@type credentials() ::
  vertex_credentials()
  | api_key_credentials()
  | anonymous_credentials()
  | codex_credentials()
```

# `vertex_credentials`

```elixir
@type vertex_credentials() :: %{
  access_token: String.t(),
  project_id: String.t(),
  region: String.t()
}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear_cache`

```elixir
@spec clear_cache(GenServer.server()) :: :ok
```

Clears all cached tokens from a running cache process.

# `configured?`

```elixir
@spec configured?(atom() | String.t(), keyword()) :: boolean()
```

Returns `true` if `provider` has credentials available in `opts` or the
environment without executing external token helpers.

# `configured_providers`

```elixir
@spec configured_providers(keyword()) :: [atom()]
```

Returns the list of providers that currently have credentials configured in
`opts` or the environment, ordered by `@provider_priority`.

# `resolve`

```elixir
@spec resolve(atom() | String.t(), keyword()) ::
  {:ok, credentials()} | {:error, term()}
```

Resolves in-memory credentials for `provider`.

Supported providers:
- `:google_vertex` / `"google_vertex"` / `"google-vertex"`
- `:openai_codex` / `"openai-codex"` (OAuth access token)
- `:anthropic` / `"anthropic"` (`ANTHROPIC_API_KEY`)
- `:openai` / `"openai"` (`OPENAI_API_KEY`)
- `:openrouter` / `"openrouter"` (`OPENROUTER_API_KEY`)
- `:deepseek` / `"deepseek"` (`DEEPSEEK_API_KEY`)
- `:google` / `"google"` (`GOOGLE_API_KEY`)
- `:ollama` / `"ollama"` (no key required; returns `%{auth_mode: :none}`)

Options:
- `:access_token` - Explicit bearer token for Vertex or Codex
- `:settings` - H-owned provider settings map (populated by the adapter)
- `:account_id` - Explicit Codex account ID; otherwise derived from the token
- `:project_id` - Override `GOOGLE_CLOUD_PROJECT`
- `:region` - Override `GOOGLE_CLOUD_REGION` (defaults to `"global"`)
- `:api_key` - Explicit API key override (Vertex uses Express Mode)
- `:credentials_path` - Override the Vertex ADC file path
- `:fetcher` - Injectable 0-arity or 1-arity callback for `:google_vertex`
- `:cache` - Cache server pid/name, or `false` to bypass cache
- `:env` - Optional `%{String.t() => String.t()}` map overriding `System.get_env/1`
- `:ttl_margin_ms` / `:default_ttl_ms` / `:now_fn` - Timing overrides when uncached or configuring cache

# `sanitize`

```elixir
@spec sanitize(term()) :: term()
```

Redacts secret values (`access_token`, `api_key`, `Bearer ...`, etc.) from maps,
lists, tuples, exceptions, and strings so credentials never leak into logs or errors.

# `start_link`

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

Starts an in-memory credential cache process.

Options:
- `:name` - Optional registered name (defaults to `nil`)
- `:ttl_margin_ms` - Safety margin subtracted from token expiration (default `60_000`)
- `:default_ttl_ms` - Fallback TTL when helper output omits expiration (default `3_600_000`)
- `:now_fn` - Zero-arity clock function returning monotonic/unix ms (default `&System.system_time(:millisecond)`)

---

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