Documentation
¶
Index ¶
- type AllowAllPolicy
- type Authenticator
- type AuthenticatorFunc
- type Config
- type Credential
- type CredentialResolver
- type Engine
- type ModelInfo
- type PolicyGate
- type Principal
- type ProviderConfig
- type Resolution
- type RouteConfig
- type StaticCredentialResolver
- type Target
- type UsageHook
- type UsageHookFunc
- type UsageRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllowAllPolicy ¶
type AllowAllPolicy struct{}
AllowAllPolicy is a PolicyGate that permits all requests.
type Authenticator ¶
Authenticator authenticates an incoming HTTP request. If not configured, requests proceed as anonymous.
type AuthenticatorFunc ¶
AuthenticatorFunc is a functional adapter for Authenticator.
func (AuthenticatorFunc) Authenticate ¶
func (f AuthenticatorFunc) Authenticate(r *http.Request) (*Principal, error)
type Config ¶
type Config struct {
Providers map[string]ProviderConfig `json:"providers"`
Routes map[string]RouteConfig `json:"routes"`
DefaultRoute string `json:"default_route,omitempty"`
// Pluggable extension hooks
Authenticator Authenticator
PolicyGate PolicyGate
CredentialResolver CredentialResolver
UsageHook UsageHook
}
Config configures the core LLM Gateway engine.
type Credential ¶
type Credential struct {
APIKey string `json:"api_key,omitempty"`
Token string `json:"token,omitempty"`
ConnectionID string `json:"connection_id,omitempty"`
CredentialRevision int64 `json:"credential_revision,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
Credential contains authentication secrets for an upstream provider.
type CredentialResolver ¶
type CredentialResolver interface {
Resolve(ctx context.Context, principal *Principal, providerID string) (*Credential, error)
}
CredentialResolver resolves upstream credentials for a principal and provider.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the core LLM Gateway routing and proxy engine. It implements http.Handler and can be mounted directly on any router.
func (*Engine) RegisterProvider ¶
RegisterProvider registers an active provider backend.
type ModelInfo ¶
type ModelInfo struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
OwnedBy string `json:"owned_by"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
}
ModelInfo describes an available upstream model or alias.
type PolicyGate ¶
type PolicyGate interface {
Allows(ctx context.Context, principal *Principal, target Target) (bool, string)
}
PolicyGate controls whether a principal is authorized to access a given provider/model target.
type Principal ¶
type Principal struct {
ID string `json:"id"`
Type string `json:"type"` // "user", "api_key", "anonymous", "service"
Name string `json:"name,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
Principal represents the authenticated caller making a request.
type ProviderConfig ¶
type ProviderConfig struct {
Type string `json:"type"` // "openai_compatible", "anthropic", "googleai", "ollama", "github_copilot", "codex", "edgetts"
BaseURL string `json:"base_url,omitempty"` // Upstream base endpoint
APIKey string `json:"api_key,omitempty"` // Static API key or token
Timeout time.Duration `json:"timeout,omitempty"` // Request timeout
Headers map[string]string `json:"headers,omitempty"` // Extra HTTP headers
AllowedModels []string `json:"allowed_models,omitempty"` // Whitelist of models
Disabled bool `json:"disabled,omitempty"` // Disable provider
}
ProviderConfig configures a single upstream provider backend.
type Resolution ¶ added in v0.1.1
type Resolution struct {
Targets []Target `json:"targets"`
Category string `json:"category,omitempty"`
}
Resolution records both the resolved targets and the canonical category name, when the request addressed a category rather than a direct model.
type RouteConfig ¶
type RouteConfig struct {
Targets []Target `json:"targets"` // Ordered targets to try
Fallback bool `json:"fallback,omitempty"` // Fall back to subsequent targets on error
Description string `json:"description,omitempty"` // User-facing description
}
RouteConfig configures an alias (failover chain) across multiple provider targets.
type StaticCredentialResolver ¶
type StaticCredentialResolver struct {
Credentials map[string]Credential
}
StaticCredentialResolver returns pre-configured credentials from a map.
func (StaticCredentialResolver) Resolve ¶
func (s StaticCredentialResolver) Resolve(ctx context.Context, principal *Principal, providerID string) (*Credential, error)
type UsageHook ¶
type UsageHook interface {
RecordUsage(ctx context.Context, record UsageRecord)
}
UsageHook receives telemetry records after each completed request.
type UsageHookFunc ¶
type UsageHookFunc func(ctx context.Context, record UsageRecord)
UsageHookFunc is a functional adapter for UsageHook.
func (UsageHookFunc) RecordUsage ¶
func (f UsageHookFunc) RecordUsage(ctx context.Context, record UsageRecord)
type UsageRecord ¶
type UsageRecord struct {
RequestID string `json:"request_id"`
PrincipalID string `json:"principal_id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Provider string `json:"provider"`
Model string `json:"model"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
Duration time.Duration `json:"duration"`
Stream bool `json:"stream"`
StatusCode int `json:"status_code"`
Error string `json:"error,omitempty"`
}
UsageRecord holds metrics and token counts from a completed LLM call.