pub struct Auth {
pub anthropic_key: Option<String>,
pub openai_key: Option<String>,
pub anthropic_bearer: Option<String>,
pub anthropic_beta: Option<String>,
pub anthropic_version: Option<String>,
pub gemini_key: Option<String>,
}Expand description
BYOK credentials for one request, extracted from headers with env-var fallback.
Never logged or persisted — std::fmt::Debug redacts all credential fields.
Fields§
§anthropic_key: Option<String>Anthropic API key from the request’s x-api-key header only.
Never populated from env or from a Bearer token — the env fallback is handled by
AnthropicProvider::complete at lowest priority after anthropic_bearer.
openai_key: Option<String>OpenAI (or OpenAI-compatible) API key from Authorization: Bearer … on OpenAI-dialect
requests, or OPENAI_API_KEY env. Never populated on Anthropic-dialect requests so
the server’s OPENAI_API_KEY cannot accidentally be forwarded to api.anthropic.com, and
a Claude Code OAuth token arriving on /v1/messages cannot be sent to an OpenAI rung.
anthropic_bearer: Option<String>Bearer token from Authorization: Bearer … on Anthropic-dialect requests only (/v1/messages,
count-tokens). Used by AnthropicProvider as the OAuth/subscription fallback when
anthropic_key is absent (Claude Code with a Claude account). Never populated from env
vars — only from the inbound request header on the Anthropic path.
anthropic_beta: Option<String>anthropic-beta header value, forwarded verbatim to the Anthropic endpoint.
anthropic_version: Option<String>anthropic-version header value. When set, overrides the default 2023-06-01.
gemini_key: Option<String>Google Gemini API key from the inbound request’s x-goog-api-key header, only on
Gemini-dialect requests (/v1beta/models/{model}:generateContent).
Never populated from env. A Gemini rung that must work for non-Gemini callers (a mixed
ladder) needs api_key_env on its [[provider]] block; there is no ambient fallback.
Never set on Anthropic/OpenAI paths — scoping prevents the Google key from reaching
other providers.
Implementations§
Source§impl Auth
impl Auth
Sourcepub fn from_headers(headers: &HeaderMap, dialect: Dialect) -> Self
pub fn from_headers(headers: &HeaderMap, dialect: Dialect) -> Self
Extract BYOK credentials from request headers, scoped to dialect so credentials
cannot leak across provider boundaries.
-
On Anthropic-dialect requests (
/v1/messages, count-tokens): an inboundAuthorization: Bearertoken goes intoanthropic_beareronly — it is the OAuth/subscription credential for Claude accounts and must NOT be forwarded to OpenAI rungs.openai_keyis populated only from theOPENAI_API_KEYenv var (no inbound Bearer on this path). -
On OpenAI-dialect requests (
/v1/chat/completions,/v1/responses): an inboundAuthorization: Bearertoken goes intoopenai_keyonly — it is the caller’s OpenAI key and must NOT be forwarded to Anthropic rungs.anthropic_beareris alwaysNoneon this path.
This scoping ensures OPENAI_API_KEY is never sent to api.anthropic.com and a Claude
OAuth token is never sent to an OpenAI-compatible endpoint.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Auth
impl RefUnwindSafe for Auth
impl Send for Auth
impl Sync for Auth
impl Unpin for Auth
impl UnsafeUnpin for Auth
impl UnwindSafe for Auth
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more