proxy

package
v0.0.0-...-1d1c723 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 54 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsProviderAuthError

func IsProviderAuthError(err error) bool

func IsProviderBlocked

func IsProviderBlocked(err error) bool

func IsProviderRateLimited

func IsProviderRateLimited(err error) bool

func NewProviderClient

func NewProviderClient(p config.ProviderConfig) *provider.Client

Types

type AdminHandler

type AdminHandler struct {
	// contains filtered or unexported fields
}

func NewAdminHandler

func NewAdminHandler(store *config.ServerConfigStore, stats *StatsStore, resolver *ProviderResolver, pricingMgr *pricing.Manager, healthChecker *ProviderHealthChecker, instanceID string) *AdminHandler

func (*AdminHandler) NotifyLogChanged

func (h *AdminHandler) NotifyLogChanged()

func (*AdminHandler) NotifyStatsChanged

func (h *AdminHandler) NotifyStatsChanged()

func (*AdminHandler) RecordConversation

func (h *AdminHandler) RecordConversation(in conversations.CaptureInput) bool

func (*AdminHandler) RecordQuotaFromResponse

func (h *AdminHandler) RecordQuotaFromResponse(p config.ProviderConfig, header http.Header)

func (*AdminHandler) RegisterRoutes

func (h *AdminHandler) RegisterRoutes(r chi.Router)

func (*AdminHandler) SetAccessTokenCleanup

func (h *AdminHandler) SetAccessTokenCleanup(run func())

func (*AdminHandler) SetNetworkListenerControl

func (h *AdminHandler) SetNetworkListenerControl(add func(string) error, remove func(string) error, list func() []string)

type ModelCard

type ModelCard = provider.ModelCard

type ProviderHTTPError

type ProviderHTTPError = provider.HTTPError

type ProviderHealth

type ProviderHealth struct {
	Status     string
	ResponseMS int64
	ModelCount int
	CheckedAt  time.Time
}

type ProviderHealthChecker

type ProviderHealthChecker struct {
	// contains filtered or unexported fields
}

func NewProviderHealthChecker

func NewProviderHealthChecker(resolver *ProviderResolver, interval time.Duration) *ProviderHealthChecker

func (*ProviderHealthChecker) AvailabilitySummary

func (c *ProviderHealthChecker) AvailabilitySummary(providers []string) (available int, online int)

func (*ProviderHealthChecker) RecordProxyResult

func (c *ProviderHealthChecker) RecordProxyResult(provider string, latency time.Duration, statusCode int, reqErr error)

func (*ProviderHealthChecker) Run

func (*ProviderHealthChecker) Snapshot

func (c *ProviderHealthChecker) Snapshot(name string) (ProviderHealth, bool)

func (*ProviderHealthChecker) Trigger

func (c *ProviderHealthChecker) Trigger()

type ProviderQuotaMetric

type ProviderQuotaMetric struct {
	Key            string  `json:"key,omitempty"`
	MeteredFeature string  `json:"metered_feature,omitempty"`
	Window         string  `json:"window,omitempty"`
	WindowSeconds  int64   `json:"window_seconds,omitempty"`
	LeftPercent    float64 `json:"left_percent"`
	UsedValue      float64 `json:"used_value"`
	RemainingValue float64 `json:"remaining_value"`
	LimitValue     float64 `json:"limit_value"`
	Unit           string  `json:"unit,omitempty"`
	ResetAt        string  `json:"reset_at,omitempty"`
}

type ProviderQuotaSnapshot

type ProviderQuotaSnapshot struct {
	Provider     string                `json:"provider"`
	ProviderType string                `json:"provider_type,omitempty"`
	DisplayName  string                `json:"display_name,omitempty"`
	Reader       string                `json:"reader,omitempty"`
	PlanType     string                `json:"plan_type,omitempty"`
	LeftPercent  float64               `json:"left_percent,omitempty"`
	ResetAt      string                `json:"reset_at,omitempty"`
	Metrics      []ProviderQuotaMetric `json:"metrics,omitempty"`
	CheckedAt    string                `json:"checked_at,omitempty"`
	Status       string                `json:"status"`
	Error        string                `json:"error,omitempty"`
}

type ProviderResolver

type ProviderResolver struct {
	// contains filtered or unexported fields
}

func NewProviderResolver

func NewProviderResolver(store *config.ServerConfigStore) *ProviderResolver

func (*ProviderResolver) DiscoverModels

func (r *ProviderResolver) DiscoverModels(ctx context.Context) ([]ModelCard, error)

func (*ProviderResolver) GetProviderByName

func (r *ProviderResolver) GetProviderByName(name string) (config.ProviderConfig, bool)

func (*ProviderResolver) ListProviders

func (r *ProviderResolver) ListProviders() []config.ProviderConfig

func (*ProviderResolver) Resolve

func (r *ProviderResolver) Resolve(model string) (config.ProviderConfig, string, error)

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(configPath string, cfg *config.ServerConfig) (*Server, error)

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

type StatsStore

type StatsStore struct {
	// contains filtered or unexported fields
}

func NewPersistentStatsStore

func NewPersistentStatsStore(_ int, path string) *StatsStore

func NewStatsStore

func NewStatsStore(_ int) *StatsStore

func (*StatsStore) Add

func (s *StatsStore) Add(evt UsageEvent)

func (*StatsStore) Flush

func (s *StatsStore) Flush()

func (*StatsStore) Summary

func (s *StatsStore) Summary(period time.Duration) StatsSummary

type StatsSummary

type StatsSummary struct {
	PeriodSeconds         int64                            `json:"period_seconds"`
	Requests              int                              `json:"requests"`
	FailedRequests        int                              `json:"failed_requests,omitempty"`
	PromptTokens          int                              `json:"prompt_tokens"`
	PromptCachedTokens    int                              `json:"prompt_cached_tokens,omitempty"`
	CompletionTokens      int                              `json:"completion_tokens"`
	TotalTokens           int                              `json:"total_tokens"`
	AvgLatencyMS          float64                          `json:"avg_latency_ms"`
	AvgPromptTPS          float64                          `json:"avg_prompt_tps"`
	AvgGenerationTPS      float64                          `json:"avg_generation_tps"`
	ProvidersAvailable    int                              `json:"providers_available,omitempty"`
	ProvidersOnline       int                              `json:"providers_online,omitempty"`
	ProviderQuotas        map[string]ProviderQuotaSnapshot `json:"provider_quotas,omitempty"`
	RequestsPerProvider   map[string]int                   `json:"requests_per_provider"`
	RequestsPerModel      map[string]int                   `json:"requests_per_model"`
	RequestsPerClientType map[string]int                   `json:"requests_per_client_type,omitempty"`
	RequestsPerUserAgent  map[string]int                   `json:"requests_per_user_agent,omitempty"`
	RequestsPerClientIP   map[string]int                   `json:"requests_per_client_ip,omitempty"`
	RequestsPerAPIKeyName map[string]int                   `json:"requests_per_api_key_name,omitempty"`
	Buckets               []UsageBucket                    `json:"buckets,omitempty"`
}

type UsageBucket

type UsageBucket struct {
	StartAt          time.Time `json:"start_at"`
	SlotSeconds      int       `json:"slot_seconds,omitempty"`
	Provider         string    `json:"provider"`
	Model            string    `json:"model"`
	ClientType       string    `json:"client_type,omitempty"`
	UserAgent        string    `json:"user_agent,omitempty"`
	ClientIP         string    `json:"client_ip,omitempty"`
	APIKeyName       string    `json:"api_key_name,omitempty"`
	Requests         int       `json:"requests"`
	FailedRequests   int       `json:"failed_requests,omitempty"`
	PromptTokens     int       `json:"prompt_tokens"`
	PromptCached     int       `json:"prompt_cached_tokens,omitempty"`
	CompletionTokens int       `json:"completion_tokens"`
	TotalTokens      int       `json:"total_tokens"`
	LatencyMSSum     int64     `json:"latency_ms_sum"`
	PromptTPSSum     float64   `json:"prompt_tps_sum"`
	GenerationTPSSum float64   `json:"generation_tps_sum"`
}

type UsageEvent

type UsageEvent struct {
	Timestamp      time.Time `json:"timestamp"`
	Provider       string    `json:"provider"`
	Model          string    `json:"model"`
	ClientType     string    `json:"client_type,omitempty"`
	UserAgent      string    `json:"user_agent,omitempty"`
	ClientIP       string    `json:"client_ip,omitempty"`
	APIKeyName     string    `json:"api_key_name,omitempty"`
	StatusCode     int       `json:"status_code,omitempty"`
	PromptTokens   int       `json:"prompt_tokens"`
	PromptCached   int       `json:"prompt_cached_tokens,omitempty"`
	CompletionToks int       `json:"completion_tokens"`
	TotalTokens    int       `json:"total_tokens"`
	LatencyMS      int64     `json:"latency_ms"`
	PromptTPS      float64   `json:"prompt_tps"`
	GenTPS         float64   `json:"gen_tps"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL