Documentation
¶
Index ¶
Constants ¶
const ( // DefaultMinSourceAgreement is the default minimum number of sources that must agree on a price. DefaultMinSourceAgreement = 2 // DefaultPriceTolerance is the default maximum allowed percentage difference between source prices. // 1% tolerance to account for rounding differences across sources. DefaultPriceTolerance = 0.01 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fetcher ¶
type Fetcher interface {
// Source returns the identifier for this data source.
Source() llmcost.PriceSource
// Fetch retrieves all current prices from the source.
Fetch(ctx context.Context) ([]llmcost.SourcePrice, error)
}
Fetcher retrieves raw price data from an external source.
func DefaultFetchers ¶
DefaultFetchers returns the built-in price fetchers.
func NewModelsDevFetcher ¶
type ModelIDNormalizer ¶
type ModelIDNormalizer interface {
Normalize(modelID string, provider string) (canonicalProvider string, canonicalModelID string)
}
ModelIDNormalizer maps model identifiers to a canonical form. Source-specific normalization should be done by each Fetcher before returning prices; the normalizer only applies generic transforms.
func NewDefaultNormalizer ¶
func NewDefaultNormalizer() ModelIDNormalizer
type PriceFilterFunc ¶
type PriceFilterFunc func(llmcost.SourcePrice) bool
PriceFilterFunc is called for each source price after normalization. Return true to include the price, false to exclude it.
type Reconciler ¶
type Reconciler struct {
// contains filtered or unexported fields
}
Reconciler groups source prices by (provider, model_id) and creates canonical global prices when multiple sources agree.
func NewReconciler ¶
func (*Reconciler) Reconcile ¶
func (r *Reconciler) Reconcile(ctx context.Context, prices []llmcost.SourcePrice) error
Reconcile groups prices by (provider, model_id), checks for multi-source agreement, and upserts reconciled global prices.
type SyncJob ¶
type SyncJob struct {
// contains filtered or unexported fields
}
SyncJob orchestrates fetching prices from external sources, normalizing model IDs, and reconciling into global prices.
func NewSyncJob ¶
func NewSyncJob(config SyncJobConfig) *SyncJob
NewSyncJob creates a new sync job with all configured fetchers.
type SyncJobConfig ¶
type SyncJobConfig struct {
HTTPClient *http.Client
Repo llmcost.Adapter
Logger *slog.Logger
// Fetchers is the list of price fetchers to use.
// If nil, the default built-in fetchers are used.
Fetchers []Fetcher
// MinSourceAgreement is the minimum number of sources that must agree on a price
// for it to be reconciled. Zero uses DefaultMinSourceAgreement.
MinSourceAgreement int
// PriceTolerance is the maximum allowed percentage difference (0.0–1.0) between
// source prices for them to be considered in agreement. Negative uses DefaultPriceTolerance.
PriceTolerance float64
// Filter is an optional function called for each source price after normalization.
// If set, only prices for which it returns true are included in reconciliation.
Filter PriceFilterFunc
}
SyncJobConfig contains the dependencies for creating a SyncJob.