feat: expose cost and reasoning levels in /v1/models (#65)

Discovery clients only saw reasoning: true, so harnesses such as OpenClaw
offered just off and max. Reasoning models now list the levels the gateway
forwards in reasoning_efforts and compat.supportedReasoningEfforts, capped
at the probed ceiling for auto, and report a forced or probed level as
default_reasoning_effort. Models with published pricing carry a cost
object, including cache read and write prices now decoded from models.dev.

Closes #65.
This commit is contained in:
Jason Xu committed 2026-10-15 08:14:11 +08:00
1 parent d04a9c750d
commit d434794866
6 files changed
+67

No files matched your search

+3
View File
@@ -515,6 +515,9 @@ func (c *Catalog) MetadataForTier(model string, tier config.Tier) Metadata {
if md.MaxOutput == 0 {
md.MaxOutput = price.MaxOutput
}
if price.Input != nil || price.Output != nil {
md.Cost = &Cost{Input: price.Input, Output: price.Output, CacheRead: price.CacheRead, CacheWrite: price.CacheWrite}
}
return md
}
+11
View File
@@ -73,6 +73,17 @@ type Metadata struct {
StructuredOutput bool `json:"structured_output,omitempty"`
InputModalities []string `json:"input_modalities,omitempty"`
OutputModalities []string `json:"output_modalities,omitempty"`
// Cost is filled from models.dev at read time, in USD per million tokens.
Cost *Cost `json:"cost,omitempty"`
}
// Cost is the published per-million-token price of a model. A nil field means
// the metadata did not state it.
type Cost struct {
Input *float64 `json:"input,omitempty"`
Output *float64 `json:"output,omitempty"`
CacheRead *float64 `json:"cache_read,omitempty"`
CacheWrite *float64 `json:"cache_write,omitempty"`
}
func (m *capabilityModel) metadata() Metadata {
+3
View File
@@ -30,6 +30,8 @@ type Price struct {
ID string `json:"id"`
Input *float64 `json:"input_cost,omitempty"`
Output *float64 `json:"output_cost,omitempty"`
CacheRead *float64 `json:"cache_read_cost,omitempty"`
CacheWrite *float64 `json:"cache_write_cost,omitempty"`
ContextWindow int `json:"context_window,omitempty"`
MaxInput int `json:"max_input,omitempty"`
MaxOutput int `json:"max_output,omitempty"`
@@ -326,6 +328,7 @@ func decodeModelsDev(data []byte) (map[string]Price, error) {
limit := jsonutil.MapAt(model, "limit")
result[modelID] = Price{
ID: modelID, Input: numberPointer(cost, "input"), Output: numberPointer(cost, "output"),
CacheRead: numberPointer(cost, "cache_read"), CacheWrite: numberPointer(cost, "cache_write"),
ContextWindow: jsonutil.IntAt(limit, "context"), MaxInput: jsonutil.IntAt(limit, "input"), MaxOutput: jsonutil.IntAt(limit, "output"),
Deprecated: metadataDeprecated(model),
}