diff --git a/proxy/internal/llm/pricing/pricing.go b/proxy/internal/llm/pricing/pricing.go index daa6cc5d6..ce6e636cf 100644 --- a/proxy/internal/llm/pricing/pricing.go +++ b/proxy/internal/llm/pricing/pricing.go @@ -56,11 +56,8 @@ type Table struct { // finite, non-negative USD amount; a violation is returned as an error so // a corrupt config fails the chain build loudly instead of mispricing. // Management validates the same constraints at its API boundary, so this -// is defense-in-depth. Nil input yields nil output. +// is defense-in-depth. Nil input yields an empty (never-matching) map. func NewEntries(raw map[string]map[string]EntryJSON) (map[string]map[string]Entry, error) { - if raw == nil { - return nil, nil - } out := make(map[string]map[string]Entry, len(raw)) for outer, models := range raw { inner := make(map[string]Entry, len(models)) @@ -76,13 +73,9 @@ func NewEntries(raw map[string]map[string]EntryJSON) (map[string]map[string]Entr return nil, fmt.Errorf("pricing %s/%s: %s must be a finite, non-negative rate, got %v", outer, model, field, v) } } - inner[model] = Entry{ - InputPer1K: e.InputPer1K, - OutputPer1K: e.OutputPer1K, - CachedInputPer1K: e.CachedInputPer1K, - CacheReadPer1K: e.CacheReadPer1K, - CacheCreationPer1K: e.CacheCreationPer1K, - } + // EntryJSON and Entry are field-identical (tags aside), so a + // direct conversion carries all five rates. + inner[model] = Entry(e) } out[outer] = inner } @@ -96,9 +89,6 @@ func NewTable(raw map[string]map[string]EntryJSON) (*Table, error) { if err != nil { return nil, err } - if entries == nil { - entries = map[string]map[string]Entry{} - } return &Table{entries: entries}, nil } diff --git a/proxy/internal/llm/pricing/pricing_test.go b/proxy/internal/llm/pricing/pricing_test.go index 68b0fc34e..b946faa7f 100644 --- a/proxy/internal/llm/pricing/pricing_test.go +++ b/proxy/internal/llm/pricing/pricing_test.go @@ -173,5 +173,5 @@ func TestNewTable_NilAndEmpty(t *testing.T) { entries, err := NewEntries(nil) require.NoError(t, err) - assert.Nil(t, entries, "nil in, nil out for the per-record map") + assert.Empty(t, entries, "nil in, empty (never-matching) map out for the per-record map") }