@@ -245,6 +245,9 @@ var entrySchema = map[string]any{
245245// fingerprint.
246246type Client struct {
247247 BaseURL string
248+ // APIKey is sent as a bearer token when non-empty. Keep credentials
249+ // outside BaseURL so redacted endpoint logs stay useful.
250+ APIKey string
248251 Model string
249252 // RetryBackoff seeds the exponential wait between transient retries;
250253 // zero means 500ms. It shapes latency, not output, so it stays outside
@@ -408,6 +411,9 @@ func (c *Client) distill(
408411 return nil , Usage {}, fmt .Errorf ("building distill request: %w" , err )
409412 }
410413 request .Header .Set ("Content-Type" , "application/json" )
414+ if c .APIKey != "" {
415+ request .Header .Set ("Authorization" , "Bearer " + c .APIKey )
416+ }
411417
412418 response , err := c .httpClient ().Do (request )
413419 if err != nil {
@@ -609,14 +615,17 @@ func (c *Client) distill(
609615 return entries , parsed .Usage , nil
610616}
611617
612- // credentialedEndpoint reports whether the configured endpoint URL
613- // carries credential material: userinfo, or any raw query segment whose
614- // key is not the api-version surface selector (mirroring the config
615- // redactor's fail-closed allowlist). Raw wire segments, no parser:
618+ // credentialedEndpoint reports whether the configured request carries
619+ // credential material: a bearer token, URL userinfo, or any raw query
620+ // segment whose key is not the api-version surface selector (mirroring
621+ // the config redactor's fail-closed allowlist). Raw wire segments, no parser:
616622// url.ParseQuery would reject exactly the malformed queries that still
617623// travel verbatim, and a rejection must not fail open. An unparseable URL
618624// counts as credentialed for the same reason.
619625func (c * Client ) credentialedEndpoint () bool {
626+ if c .APIKey != "" {
627+ return true
628+ }
620629 endpoint , err := url .Parse (c .BaseURL )
621630 if err != nil {
622631 return true
0 commit comments