Skip to main content

Module auth

Module auth 

Source
Expand description

Authentication filters for the bitrouter gateway.

Implements a LiteLLM-style key model:

  • A master key (configured in bitrouter.yaml) grants Scope::Admin access — it can call API endpoints and manage accounts/keys.
  • Virtual keys (created via the /key/generate endpoint using the master key) grant Scope::Api access — they can call API endpoints only.

Credentials are extracted from the protocol-appropriate header:

ProtocolHeader
OpenAIAuthorization: Bearer <key>
Anthropicx-api-key: <key>
ManagementAuthorization: Bearer <key>

When no master_key is configured, auth is disabled and all requests are allowed through (open proxy mode).

Structs§

AuthContext
Shared auth state passed into filters.
Unauthorized

Functions§

anthropic_auth
Build an auth filter for Anthropic-protocol routes (x-api-key).
any_credential
Warp filter: extract credential from either Authorization: Bearer or x-api-key (Anthropic-style). Bearer takes precedence.
bearer_credential
Warp filter: extract credential from Authorization: Bearer header.
hash_key
SHA-256 hash a key string, returning hex-encoded digest.
management_auth
Build an auth filter for management routes. Accepts both Bearer and x-api-key.
openai_auth
Build an auth filter for OpenAI-protocol routes (Authorization: Bearer).
x_api_key_credential
Warp filter: extract credential from x-api-key header.