Overview
Access providers handle request authentication before proxying to upstream AI services. They validate credentials from incoming HTTP requests and determine whether to allow or reject access. The SDK provides:- A built-in API key provider for inline configuration
- A registry for custom providers
- A manager that evaluates providers in order
- Full control over authentication logic
Access Provider Interface
Implement theProvider interface to create custom authentication:
sdk/access/registry.go
Authentication Errors
ReturnAuthError to communicate authentication failures:
sdk/access/errors.go
AuthErrorCodeNotHandled- Provider doesn’t apply to this request (continues to next provider)AuthErrorCodeNoCredentials- Request is missing credentials (continues to next provider)AuthErrorCodeInvalidCredential- Credentials are present but invalid (authentication fails)AuthErrorCodeInternal- Server error during authentication (authentication fails)
Creating Custom Providers
Basic Example
Here’s a custom provider that validates API keys from a database:Multi-Header Provider
Support multiple authentication methods:JWT Provider
Validate JSON Web Tokens:Provider Registration
Register providers globally for use by the access manager:sdk/access/registry.go
Registration Example
Access Manager
TheManager coordinates multiple providers and evaluates them in order:
sdk/access/manager.go
Manager Behavior
The manager evaluates providers in order until:- A provider returns a successful
Result→ authentication succeeds - A provider returns an error other than
NotHandledorNoCredentials→ authentication fails - All providers have been tried → authentication fails with appropriate error
InvalidCredential(if any provider found invalid credentials)NoCredentials(if no credentials were found)
Integration Example
Built-in Provider
The SDK includes a built-in provider for inline API keys:sdk/access/types.go
Authorization: Bearer <key>headerX-Goog-Api-Keyheader (Google format)X-Api-Keyheader (Anthropic format)?key=<key>query parameter?auth_token=<token>query parameter
Configuration
config.yaml
Provider Configuration
Define custom providers in configuration:sdk/access/types.go
Example Configuration
config.yaml
Testing Providers
Test authentication logic without a full server:Best Practices
1. Return NotHandled for Non-Applicable Requests
2. Include Useful Metadata
3. Handle Context Cancellation
4. Order Providers by Specificity
Next Steps
File Watching
Monitor config and auth file changes
Service Builder
Configure and build the proxy service
Advanced Features
Custom executors and translators
Examples
Complete working examples