proxy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

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

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) Begin

func (m *Metrics) Begin(method, path string) *RequestRecord

func (*Metrics) Finish

func (m *Metrics) Finish(record *RequestRecord)

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() Snapshot

type ModelStats

type ModelStats struct {
	Requests       int64
	InputTokens    int64
	OutputTokens   int64
	ThinkingTokens int64
	CachedTokens   int64
	TotalTokens    int64
}

type Options

type Options struct {
	Config        *config.Config
	TokenProvider auth.TokenProvider // optional global override
	Metrics       *Metrics
	HTTPClient    *http.Client
	UpstreamBase  string // optional global override
	Verbose       bool
	LogOutput     io.Writer
}

Options configures a Proxy. TokenProvider and UpstreamBase are optional global overrides (used in tests). When not set, per-backend auth and URLs from Config.Backends are used.

type Proxy

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

func New

func New(ctx context.Context, opts Options) (*Proxy, error)

New creates a Proxy and initialises an auth provider for each configured backend. If Options.TokenProvider and/or Options.UpstreamBase are set they act as global overrides for all backends (used in tests).

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RequestRecord

type RequestRecord struct {
	Method     string
	Path       string
	Model      string
	StatusCode int
	Duration   time.Duration
	Error      string
	Usage      usage.TokenUsage
	StartedAt  time.Time
}

type Snapshot

type Snapshot struct {
	TotalRequests  int64
	Active         int64
	Successes      int64
	Failures       int64
	InputTokens    int64
	OutputTokens   int64
	ThinkingTokens int64
	CachedTokens   int64
	TotalTokens    int64
	StatusCodes    map[int]int64
	Models         map[string]ModelStats
	Recent         []RequestRecord
}

func (Snapshot) SortedModelNames

func (s Snapshot) SortedModelNames() []string

type StaticTokenProvider

type StaticTokenProvider string

func (StaticTokenProvider) Token

Jump to

Keyboard shortcuts

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