pricing

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseLLMURL   = "https://basellm.github.io/llm-metadata/api/newapi/ratio_config-v1-base.json"
	ModelsDevURL = "https://models.dev/api.json"
)

Variables

This section is empty.

Functions

func ConvertModelsDevMetadata added in v0.0.15

func ConvertModelsDevMetadata(data []byte) map[string]models.ModelMetadata

ConvertModelsDevMetadata normalizes the approved marketplace fields. When a model ID appears under multiple providers, the lexicographically first provider key wins; this makes the one-model-to-one-metadata collapse stable without inventing a provider priority policy.

func Fetch

func Fetch(targetURL string, proxyURL string) ([]byte, error)

Fetch retrieves data from the given URL with 1-hour in-memory caching. If proxyURL is non-empty, it is used as the HTTP proxy; otherwise the standard HTTP_PROXY/HTTPS_PROXY environment variables apply.

func ValidateModelsDevMetadata added in v0.0.15

func ValidateModelsDevMetadata(data []byte) error

ValidateModelsDevMetadata distinguishes a valid models.dev payload from syntactically valid JSON with an incompatible shape. ConvertModelsDevMetadata keeps its map-only contract, while sync uses this validation error for its metadata_source_error response.

Types

type ModelPricing

type ModelPricing struct {
	InputPrice      float64
	OutputPrice     float64
	CacheReadPrice  *float64
	CacheWritePrice *float64
}

type PriceCandidate added in v0.0.6

type PriceCandidate struct {
	Source      string // "basellm" | "models.dev"
	Provider    string // models.dev 的 provider id;basellm 为 ""
	MatchType   string // "exact" | "fuzzy"
	MatchedName string
	Pricing     ModelPricing
}

type Recommendation added in v0.0.6

type Recommendation struct {
	Price         ResolvedPrice
	Provenance    string // "models.dev (anthropic)" / "basellm"
	Confidence    string // "high" | "needs_review"
	ReviewReasons []string
}

func ResolvePrice added in v0.0.6

func ResolvePrice(candidates []PriceCandidate, cfg ResolveConfig) Recommendation

ResolvePrice 把某模型的全部源×provider 候选收敛成唯一推荐价。

type ResolveConfig added in v0.0.6

type ResolveConfig struct {
	SourcePriority        []string
	DisagreementThreshold float64
}

type ResolvedPrice added in v0.0.6

type ResolvedPrice struct {
	InputPrice, OutputPrice, CacheReadPrice, CacheWritePrice float64
}

ResolvedPrice 用裸 float64(cache 缺失记 0),与 DB/apply 语义一致。

type SourceData added in v0.0.6

type SourceData map[string][]SourceModelPrice

SourceData: modelID -> 该 modelID 在各 provider 下的全部候选。 basellm 每个 modelID 一条;models.dev 每个 modelID 可能多条(多 provider 托管)。

func ConvertBaseLLM

func ConvertBaseLLM(data []byte) (SourceData, error)

func ConvertModelsDev

func ConvertModelsDev(data []byte) (SourceData, error)

type SourceModelPrice added in v0.0.6

type SourceModelPrice struct {
	Provider string
	Pricing  ModelPricing
}

SourceModelPrice 是某个 modelID 在某个 provider 下的一条候选价。 basellm 没有 provider 概念,Provider 留空。

func MatchAll added in v0.0.6

func MatchAll(modelName string, source SourceData) (matchType, matchedName string, prices []SourceModelPrice, ok bool)

MatchAll 在 source 中匹配 modelName,返回命中名下的全部 provider 候选。 先精确、再模糊(normalize 后取最短、字母序最早的源端名)。

Jump to

Keyboard shortcuts

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