package utils import ( "encoding/json" "fmt" "log" "time" "github.com/go-resty/resty/v2" "gophergate/internal/models" ) const ModelsDevURL = "https://models.dev/api.json" func FetchRegistry() (*models.ModelRegistry, error) { client := resty.New().SetTimeout(10 * time.Second) var lastErr error for attempt := 0; attempt < 3; attempt++ { if attempt > 0 { backoff := time.Duration(1< 0 { if cacheRead > promptTokens { uncachedTokens = 0 } else { uncachedTokens = promptTokens - cacheRead } } cost := (float64(uncachedTokens) * meta.Cost.Input / 1000000.0) + (float64(completionTokens) * meta.Cost.Output / 1000000.0) if meta.Cost.CacheRead != nil { cost += float64(cacheRead) * (*meta.Cost.CacheRead) / 1000000.0 } if meta.Cost.CacheWrite != nil { cost += float64(cacheWrite) * (*meta.Cost.CacheWrite) / 1000000.0 } // Apply promotional discounts (e.g. DeepSeek 75% off until 2026-05-31). if discount, ok := promoDiscounts[modelID]; ok { if time.Now().UTC().Before(discount.ExpiresAt) { cost *= discount.Factor } } return cost }