core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountConfig

type AccountConfig struct {
	ID         string            `json:"id"`
	Provider   string            `json:"provider"`
	Auth       string            `json:"auth,omitempty"`        // "api_key", "oauth", "cli", "local", "token"
	APIKeyEnv  string            `json:"api_key_env,omitempty"` // env var name holding the API key
	ProbeModel string            `json:"probe_model,omitempty"` // model to use for probe requests
	Binary     string            `json:"binary,omitempty"`      // path to CLI binary
	BaseURL    string            `json:"base_url,omitempty"`    // custom API base URL (e.g. for OpenRouter)
	Token      string            `json:"-"`                     // runtime-only: access token (never persisted)
	ExtraData  map[string]string `json:"-"`                     // runtime-only: extra detection data
}

func (AccountConfig) ResolveAPIKey

func (c AccountConfig) ResolveAPIKey() string

type Engine

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

func NewEngine

func NewEngine(interval time.Duration) *Engine

func (*Engine) OnUpdate

func (e *Engine) OnUpdate(fn func(map[string]QuotaSnapshot))

func (*Engine) RefreshAll

func (e *Engine) RefreshAll(ctx context.Context)

func (*Engine) RegisterProvider

func (e *Engine) RegisterProvider(p QuotaProvider)

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

func (*Engine) SetAccounts

func (e *Engine) SetAccounts(accounts []AccountConfig)

func (*Engine) Snapshots

func (e *Engine) Snapshots() map[string]QuotaSnapshot

type Metric

type Metric struct {
	Limit     *float64 `json:"limit,omitempty"`
	Remaining *float64 `json:"remaining,omitempty"`
	Used      *float64 `json:"used,omitempty"`
	Unit      string   `json:"unit"`   // "requests", "tokens", "USD", "credits"
	Window    string   `json:"window"` // "1m", "1d", "month", "rolling-5h", etc.
}

func (Metric) Percent

func (m Metric) Percent() float64

type ProviderInfo

type ProviderInfo struct {
	Name         string   // e.g. "OpenAI", "Anthropic"
	Capabilities []string // "headers", "cli_stats", "usage_endpoint", "credits_endpoint"
	DocURL       string   // link to vendor's rate-limit documentation
}

type QuotaProvider

type QuotaProvider interface {
	ID() string

	Describe() ProviderInfo

	Fetch(ctx context.Context, acct AccountConfig) (QuotaSnapshot, error)
}

type QuotaSnapshot

type QuotaSnapshot struct {
	ProviderID  string                 `json:"provider_id"`
	AccountID   string                 `json:"account_id"`
	Timestamp   time.Time              `json:"timestamp"`
	Status      Status                 `json:"status"`
	Metrics     map[string]Metric      `json:"metrics"`                // keys like "rpm", "tpm", "rpd"
	Resets      map[string]time.Time   `json:"resets,omitempty"`       // e.g. "rpm_reset"
	Raw         map[string]string      `json:"raw,omitempty"`          // redacted header dump / CLI lines
	DailySeries map[string][]TimePoint `json:"daily_series,omitempty"` // time-indexed data (e.g. "messages", "cost", "tokens_<model>")
	Message     string                 `json:"message,omitempty"`      // human-readable summary
}

func (QuotaSnapshot) WorstPercent

func (s QuotaSnapshot) WorstPercent() float64

type Status

type Status string
const (
	StatusOK          Status = "OK"
	StatusNearLimit   Status = "NEAR_LIMIT"
	StatusLimited     Status = "LIMITED"
	StatusAuth        Status = "AUTH_REQUIRED"
	StatusUnsupported Status = "UNSUPPORTED"
	StatusError       Status = "ERROR"
	StatusUnknown     Status = "UNKNOWN"
)

type TimePoint

type TimePoint struct {
	Date  string  `json:"date"`  // "2025-01-15"
	Value float64 `json:"value"` // metric value at that date
}

Jump to

Keyboard shortcuts

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