API Reference¶
This section provides comprehensive API documentation for all public classes, functions, and modules in litestar-api-auth.
Note
All storage backends implement the APIKeyBackend protocol,
ensuring consistent behavior across different providers.
Quick Navigation¶
Plugin & Configuration
APIAuthPlugin- Litestar plugin for API key authenticationAPIAuthConfig- Plugin configuration
Guards
require_api_key()- Basic authentication guardrequire_scope()- Single scope authorization guardrequire_scopes()- Multiple scopes authorization guardget_api_key_info()- Retrieve API key info from request
Types
APIKeyInfo- API key metadata containerAPIKeyState- Key state enumeration (active, expired, revoked)
Schemas (msgspec)
CreateAPIKeyRequest- Key creation requestUpdateAPIKeyRequest- Key update requestAPIKeyResponse- Key response (without raw key)APIKeyCreatedResponse- Key creation response (with raw key)APIKeyListResponse- Paginated key list response
Storage Backends
APIKeyBackend- Backend protocolAPIKeyInfo- Backend key infoMemoryBackend- In-memory (testing/development)SQLAlchemyBackend- SQLAlchemy backendAPIKeyModel- SQLAlchemy ORM model (Advanced Alchemy)APIKeyRepository- Async repository (Advanced Alchemy)APIKeyService- Async service (Advanced Alchemy)RedisBackend- Redis backend
Service Functions
generate_api_key()- Generate a new API keyhash_api_key()- Hash an API key for storageverify_api_key()- Verify a key against its hashextract_key_id()- Extract key ID from raw key
Exceptions
APIAuthError- Base exceptionInvalidAPIKeyError- Invalid key errorAPIKeyExpiredError- Expired key errorAPIKeyRevokedError- Revoked key errorAPIKeyNotFoundError- Key not found errorInsufficientScopesError- Missing scope errorConfigurationError- Configuration error
Middleware & Controllers
APIKeyMiddleware- X-API-Key extraction middlewareAPIKeyController- REST controller for key management