Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidationError(err error) bool
- type Catalog
- type DuplicateSelectorError
- type MongoDBStore
- type Override
- type PostgreSQLStore
- type Pricing
- type PricingTier
- type Result
- type SQLiteStore
- type ScopeKind
- type Service
- func (s *Service) Delete(ctx context.Context, selector string) error
- func (s *Service) Get(selector string) (*Override, bool)
- func (s *Service) GetView(selector string) (*View, bool)
- func (s *Service) List() []Override
- func (s *Service) ListViews() []View
- func (s *Service) Refresh(ctx context.Context) error
- func (s *Service) ResolvePricing(model, providerName string) *core.ModelPricing
- func (s *Service) StartBackgroundRefresh(interval time.Duration) func()
- func (s *Service) Upsert(ctx context.Context, override Override) error
- type Store
- type ValidationError
- type View
Constants ¶
const CurrencyUSD = "USD"
Variables ¶
var ErrNotFound = errors.New("model pricing override not found")
ErrNotFound indicates a requested pricing override was not found.
Functions ¶
func IsValidationError ¶
IsValidationError reports whether err is a validation error.
Types ¶
type Catalog ¶
type Catalog = modelselectors.Catalog
Catalog is the minimal configured-provider surface needed for selector validation.
type DuplicateSelectorError ¶
DuplicateSelectorError reports two stored rows that normalize to one selector.
func (*DuplicateSelectorError) Error ¶
func (e *DuplicateSelectorError) Error() string
type MongoDBStore ¶
type MongoDBStore struct {
// contains filtered or unexported fields
}
MongoDBStore stores model pricing overrides in MongoDB.
func NewMongoDBStore ¶
func NewMongoDBStore(database *mongo.Database) (*MongoDBStore, error)
NewMongoDBStore creates collection indexes if needed.
func (*MongoDBStore) Close ¶
func (s *MongoDBStore) Close() error
type Override ¶
type Override struct {
Selector string `json:"selector" bson:"_id"`
ProviderName string `json:"provider_name,omitempty" bson:"provider_name,omitempty"`
Model string `json:"model,omitempty" bson:"model,omitempty"`
Pricing Pricing `json:"pricing" bson:"pricing"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
}
Override stores one persisted pricing override for a model selector.
type PostgreSQLStore ¶
type PostgreSQLStore struct {
// contains filtered or unexported fields
}
PostgreSQLStore stores model pricing overrides in PostgreSQL.
func NewPostgreSQLStore ¶
NewPostgreSQLStore creates the model_pricing_overrides table and indexes if needed.
func (*PostgreSQLStore) Close ¶
func (s *PostgreSQLStore) Close() error
func (*PostgreSQLStore) Delete ¶
func (s *PostgreSQLStore) Delete(ctx context.Context, selector string) error
type Pricing ¶
type Pricing struct {
InputPerMtok *float64 `json:"input_per_mtok,omitempty" bson:"input_per_mtok,omitempty"`
OutputPerMtok *float64 `json:"output_per_mtok,omitempty" bson:"output_per_mtok,omitempty"`
CachedInputPerMtok *float64 `json:"cached_input_per_mtok,omitempty" bson:"cached_input_per_mtok,omitempty"`
CacheWritePerMtok *float64 `json:"cache_write_per_mtok,omitempty" bson:"cache_write_per_mtok,omitempty"`
ReasoningOutputPerMtok *float64 `json:"reasoning_output_per_mtok,omitempty" bson:"reasoning_output_per_mtok,omitempty"`
BatchInputPerMtok *float64 `json:"batch_input_per_mtok,omitempty" bson:"batch_input_per_mtok,omitempty"`
BatchOutputPerMtok *float64 `json:"batch_output_per_mtok,omitempty" bson:"batch_output_per_mtok,omitempty"`
AudioInputPerMtok *float64 `json:"audio_input_per_mtok,omitempty" bson:"audio_input_per_mtok,omitempty"`
AudioOutputPerMtok *float64 `json:"audio_output_per_mtok,omitempty" bson:"audio_output_per_mtok,omitempty"`
PerImage *float64 `json:"per_image,omitempty" bson:"per_image,omitempty"`
InputPerImage *float64 `json:"input_per_image,omitempty" bson:"input_per_image,omitempty"`
PerSecondInput *float64 `json:"per_second_input,omitempty" bson:"per_second_input,omitempty"`
PerSecondOutput *float64 `json:"per_second_output,omitempty" bson:"per_second_output,omitempty"`
PerCharacterInput *float64 `json:"per_character_input,omitempty" bson:"per_character_input,omitempty"`
PerRequest *float64 `json:"per_request,omitempty" bson:"per_request,omitempty"`
PerPage *float64 `json:"per_page,omitempty" bson:"per_page,omitempty"`
Tiers []PricingTier `json:"tiers,omitempty" bson:"tiers,omitempty"`
}
Pricing stores operator-supplied pricing fields. Currency is intentionally omitted from persistence and API payloads; UI-managed pricing is USD-only.
type PricingTier ¶
type PricingTier struct {
UpToTokens *float64 `json:"up_to_tokens,omitempty" bson:"up_to_tokens,omitempty"`
UpToMtok *float64 `json:"up_to_mtok,omitempty" bson:"up_to_mtok,omitempty"`
InputPerMtok *float64 `json:"input_per_mtok,omitempty" bson:"input_per_mtok,omitempty"`
OutputPerMtok *float64 `json:"output_per_mtok,omitempty" bson:"output_per_mtok,omitempty"`
}
PricingTier stores future tiered pricing without changing the DB schema.
type Result ¶
type Result struct {
Service *Service
Store Store
Storage storage.Storage
// contains filtered or unexported fields
}
Result holds the initialized pricing override service and any owned resources.
func New ¶
func New(ctx context.Context, cfg *config.Config, catalog Catalog, base usage.PricingResolver) (*Result, error)
New creates a pricing override subsystem with its own storage connection.
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore stores model pricing overrides in SQLite.
func NewSQLiteStore ¶
func NewSQLiteStore(db *sql.DB) (*SQLiteStore, error)
NewSQLiteStore creates the model_pricing_overrides table and indexes if needed.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
type ScopeKind ¶
type ScopeKind = modelselectors.ScopeKind
ScopeKind identifies how broadly an override applies.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service keeps pricing overrides cached in memory and resolves effective pricing.
func NewService ¶
NewService creates a pricing override service backed by storage.
func (*Service) GetView ¶
GetView returns one cached override with scope metadata by normalized selector.
func (*Service) ResolvePricing ¶
func (s *Service) ResolvePricing(model, providerName string) *core.ModelPricing
ResolvePricing resolves base pricing and applies the most specific DB override.
func (*Service) StartBackgroundRefresh ¶
StartBackgroundRefresh periodically reloads pricing overrides from storage until stopped. Each s.Refresh call is capped by refreshTimeout, and shorter intervals are clamped to refreshTimeout.
type Store ¶
type Store interface {
List(ctx context.Context) ([]Override, error)
Upsert(ctx context.Context, override Override) error
Delete(ctx context.Context, selector string) error
Close() error
}
Store defines persistence operations for pricing overrides.
type ValidationError ¶
type ValidationError = modelselectors.ValidationError
ValidationError indicates invalid override input or invalid override state.