auth
Per-request authentication hooks for LLM HTTP clients.
[AuthProvider] runs before each request to set headers (and optionally
influence URL query parameters). Use [ApiKeyAuth] for standard
Authorization: Bearer endpoints (OpenAI, OpenRouter, many others).
Use [AnthropicApiKeyAuth] for Anthropic’s x-api-key header.
Use [AzureOpenAiAuth] for Azure OpenAI (api-key header or Entra bearer)
plus required api-version query parameter.
Traits
Section titled “Traits”AuthProvider
Section titled “AuthProvider”Called before each HTTP request to inject or refresh authorization.
Required / Provided Methods
fn authorize(&self, headers: &mut HashMap<String, String>) -> Result<(), LlmError>Mutate headers in place (add or replace auth-related entries).
fn query_params(&self) -> Vec<(String, String)>Optional query parameters appended to every request URL after the path.
Default: none. Azure OpenAI uses this for api-version.
Structs
Section titled “Structs”ApiKeyAuth
Section titled “ApiKeyAuth”Standard bearer token: Authorization: Bearer <key>.
Covers OpenAI, OpenRouter, Together, Fireworks, vLLM gateways, etc.
Methods
fn new<impl Into<String>>(key: impl Into) -> Selfinto_arc
Section titled “into_arc”fn into_arc(self) -> Arc<dyn AuthProvider>AnthropicApiKeyAuth
Section titled “AnthropicApiKeyAuth”Anthropic Messages API authentication (x-api-key + version header).
Methods
fn new<impl Into<String>>(key: impl Into) -> Selfwith_version
Section titled “with_version”fn with_version<impl Into<String>>(self, version: impl Into) -> Selfinto_arc
Section titled “into_arc”fn into_arc(self) -> Arc<dyn AuthProvider>AzureOpenAiAuth
Section titled “AzureOpenAiAuth”Azure OpenAI: correct auth header plus api-version on every request.
Methods
fn new<impl Into<String>>(api_version: impl Into, credential: AzureCredential) -> SelfAzureCredential
Section titled “AzureCredential”Azure OpenAI credential: static api-key header or Entra ID bearer token.
Variants
| Variant | Description |
|---|---|
ApiKey(String) | Sent as api-key: {key}. |
BearerToken(String) | Sent as Authorization: Bearer {token}. Refresh externally before expiry. |