pricing

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWindowTokens

func ContextWindowTokens(modelID string) int64

ContextWindowTokens returns the known context window size in tokens for modelID, or 0 if the model is unknown. Uses the same qualified→bare lookup chain as CostUSD.

func CostUSD

func CostUSD(qualifiedID string, input, output int64) float64

CostUSD returns the estimated USD cost for a completed run.

qualifiedID should be the OpenRouter-style "provider/model" key (e.g. "anthropic/claude-sonnet-4-6"). Native adapters pass their provider prefix; OpenRouter adapters pass the model ID as-is.

Returns 0 for unknown models — the UI omits the cost field in that case.

func LoadPricing

func LoadPricing(cacheFile string)

LoadPricing populates the dynamic pricing table at startup using OpenRouter's public model listing as the data source.

Fallback chain:

fresh local cache (< 24 h) → OpenRouter fetch + update cache →
stale local cache → hardcoded pricingTable

Blocking with a 5-second HTTP timeout. Safe to call before any goroutines start.

func PricingFor

func PricingFor(qualifiedID string) (inputPMT, outputPMT float64, ok bool)

PricingFor returns the per-million-token USD rates for a model. qualifiedID follows the same "provider/model" convention as CostUSD (e.g. "anthropic/claude-sonnet-4-6"). Returns ok=false for unknown models.

func ProviderQualifiedID

func ProviderQualifiedID(provider, modelID string) string

CostUSD returns the estimated USD cost for a completed run.

qualifiedID should be the OpenRouter-style "provider/model" key (e.g. "anthropic/claude-sonnet-4-6"). Native adapters pass their provider prefix; OpenRouter adapters pass the model ID as-is.

Lookup order:

  1. qualifiedID in dynamic pricing (OpenRouter data)
  2. qualifiedID in hardcoded table
  3. bare portion after the first "/" in both tables (for native-adapter fallback)

Returns 0 for unknown models — the UI omits the cost field in that case. ProviderQualifiedID returns the OpenRouter-style "provider/model" key for a model ID from a given provider. For OpenRouter and LiteLLM the model ID already carries the required prefix and is returned as-is.

Types

This section is empty.

Jump to

Keyboard shortcuts

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