Skip to main content

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 the Provider interface to create custom authentication:
sdk/access/registry.go

Authentication Errors

Return AuthError to communicate authentication failures:
sdk/access/errors.go
Error semantics:
  • 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

The Manager coordinates multiple providers and evaluates them in order:
sdk/access/manager.go

Manager Behavior

The manager evaluates providers in order until:
  1. A provider returns a successful Result → authentication succeeds
  2. A provider returns an error other than NotHandled or NoCredentials → authentication fails
  3. All providers have been tried → authentication fails with appropriate error
Error priority:
  1. InvalidCredential (if any provider found invalid credentials)
  2. 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
This provider validates credentials from:
  • Authorization: Bearer <key> header
  • X-Goog-Api-Key header (Google format)
  • X-Api-Key header (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