# `Tinkex.API.Headers`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/api/headers.ex#L1)

HTTP header building and management for Tinkex API requests.

Handles:
- Standard headers (accept, content-type, user-agent, etc.)
- Authentication headers (API key)
- Stainless SDK headers
- Cloudflare Access headers
- Request-specific headers (idempotency, sampling, retry count)
- OpenTelemetry trace context propagation (opt-in)
- Header deduplication

# `build`

```elixir
@spec build(atom(), Tinkex.Config.t(), keyword(), timeout()) :: [
  {String.t(), String.t()}
]
```

Builds complete headers list for a request.

Combines headers from multiple sources in priority order:
1. Standard headers (accept, content-type, etc.)
2. Stainless SDK headers
3. Cloudflare Access headers
4. Config default headers
5. Request-specific headers
6. Method-specific headers (idempotency, sampling)
7. User-provided headers from opts
8. OpenTelemetry trace context (if enabled)

Lower priority headers are overridden by higher priority ones.

# `dedupe`

```elixir
@spec dedupe([{String.t(), String.t()}]) :: [{String.t(), String.t()}]
```

Deduplicates headers, keeping the last occurrence of each header name.

Comparison is case-insensitive, but the original case of the last
occurrence is preserved.

# `find_value`

```elixir
@spec find_value([{String.t(), String.t()}], String.t()) :: String.t() | nil
```

Finds a header value by name (case-insensitive).

Returns the original value (not lowercased) if found, nil otherwise.

# `get_normalized`

```elixir
@spec get_normalized([{String.t(), String.t()}], String.t()) :: String.t() | nil
```

Retrieves a header value by name (case-insensitive).

Returns the lowercased and trimmed value if found, nil otherwise.

# `put`

```elixir
@spec put([{String.t(), String.t()}], String.t(), String.t()) :: [
  {String.t(), String.t()}
]
```

Adds or replaces a header in the headers list.

Case-insensitive replacement - if a header with the same name exists
(regardless of case), it will be replaced.

# `put_retry_headers`

```elixir
@spec put_retry_headers(Finch.Request.t(), non_neg_integer(), timeout()) ::
  Finch.Request.t()
```

Adds or updates retry-related headers to a request.

Sets:
- x-stainless-retry-count: Current retry attempt number
- x-stainless-read-timeout: Request timeout (if not already set)

# `redact`

```elixir
@spec redact([{String.t(), String.t()}]) :: [{String.t(), String.t()}]
```

Redacts sensitive header values for logging.

Redacts:
- x-api-key
- cf-access-client-secret
- authorization
- proxy-authorization

# `to_map`

```elixir
@spec to_map([{String.t(), String.t()}]) :: map()
```

Converts a headers list to a map with lowercased keys.

---

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