The modelsdev package provides model pricing lookup backed by the public models.dev catalog.
This package downloads and parses https://models.dev/catalog.json, normalizes provider/model identifiers, and exposes per-token pricing for callers that need cost-aware behavior.
The catalog is loaded once per process via a singleton cache (syncutil.OnceLoader) to avoid repeated network fetches.
import "github.com/github/gh-aw/pkg/modelsdev"
pricing, ok := modelsdev.FindPricing(ctx, "github", "gpt-4.1")
if !ok {
// pricing unavailable
return
}
inputUSD := pricing["input"] // per token
outputUSD := pricing["output"] // per token
_ = inputUSD
_ = outputUSDInternal:
github.com/github/gh-aw/pkg/logger— debug logginggithub.com/github/gh-aw/pkg/syncutil— one-time catalog load/cache primitive
- Provider aliases such as
github,copilot, andgithub_modelsare normalized togithub-copilot. - Comparable model matching normalizes separators (
.and_to-) to improve lookup robustness. - Numeric catalog costs are interpreted as per-million-token values and converted to per-token units.
- String catalog costs are treated as already normalized per-token values.
- Network or parsing failures degrade gracefully to an empty cache so callers can continue without pricing data.
Reviewed against recent source updates on 2026-07-17; no additional public-contract deltas were identified beyond the sections above.
This specification is automatically maintained by the spec-extractor workflow.
