proxy

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStatsPath added in v0.5.2

func GetStatsPath() (string, error)

GetStatsPath returns the stats file path

Types

type APIResponse

type APIResponse struct {
	Usage Usage `json:"usage"`
}

APIResponse represents the structure of API responses to extract usage

type EndpointStats

type EndpointStats struct {
	Requests     int       `json:"requests"`
	Errors       int       `json:"errors"`
	InputTokens  int       `json:"inputTokens"`
	OutputTokens int       `json:"outputTokens"`
	LastUsed     time.Time `json:"lastUsed"`
}

EndpointStats represents statistics for a single endpoint

type Proxy

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

Proxy represents the proxy server

func New

func New(cfg *config.Config) *Proxy

New creates a new Proxy instance

func (*Proxy) GetStats

func (p *Proxy) GetStats() *Stats

GetStats returns current statistics

func (*Proxy) Start

func (p *Proxy) Start() error

Start starts the proxy server

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop stops the proxy server

func (*Proxy) UpdateConfig

func (p *Proxy) UpdateConfig(cfg *config.Config) error

UpdateConfig updates the proxy configuration

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
}

SSEEvent represents a Server-Sent Event

type Stats

type Stats struct {
	TotalRequests int                       `json:"totalRequests"`
	EndpointStats map[string]*EndpointStats `json:"endpointStats"`
	// contains filtered or unexported fields
}

Stats represents overall proxy statistics

func NewStats

func NewStats() *Stats

NewStats creates a new Stats instance

func (*Stats) GetStats

func (s *Stats) GetStats() (int, map[string]*EndpointStats)

GetStats returns a copy of current statistics (thread-safe)

func (*Stats) Load added in v0.5.2

func (s *Stats) Load() error

Load loads statistics from file

func (*Stats) RecordError

func (s *Stats) RecordError(endpointName string)

RecordError records an error for an endpoint

func (*Stats) RecordRequest

func (s *Stats) RecordRequest(endpointName string)

RecordRequest records a request for an endpoint

func (*Stats) RecordTokens

func (s *Stats) RecordTokens(endpointName string, inputTokens, outputTokens int)

RecordTokens records token usage for an endpoint

func (*Stats) Reset

func (s *Stats) Reset()

Reset resets all statistics

func (*Stats) Save added in v0.5.2

func (s *Stats) Save() error

Save saves statistics to file

func (*Stats) SetStatsPath added in v0.5.2

func (s *Stats) SetStatsPath(path string)

SetStatsPath sets the path for stats persistence

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

Usage represents token usage information from API response

Jump to

Keyboard shortcuts

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