Skip to content
Source
Sign inSign up
TanStack/schemas

Estimate: return a price per value when one required choice input is missing #450

Send to my agent
Closedtombeckenham opened this issue 0 comments
tombeckenhamcommented

Problem

/v1/estimate (and MCP estimate_cost) refuses when a card's required input is missing. For choice inputs (enum or boolean, no default), the caller usually doesn't know the input exists. The list endpoint shows the card's inputs only with ?pricing=1. Examples: BytePlus DeepSeek's pricing_period: off_peak | peak, and #449 adds the same lever to native DeepSeek.

Live catalog survey (2026-10-23, 4,331 priced rows). Required choice inputs:

inputvaluesrowsproviders
target_resolution480p…4K25fal, replicate
model_variantwith_audio/without_audio, speed/precision, …15replicate
resolution480p…4k4byteplus, fal, grok
input_videotrue/false4byteplus
pricing_periodoff_peak/peak3byteplus
listen_modestreaming/pre_recorded3deepgram
language_scopemonolingual/multilingual1deepgram

Every other required input is a quantity (tokens, seconds, images, …). Those can't be enumerated and are out of scope.

Design

When exactly one required choice input is missing, and every other required input is supplied, price the call once per allowed value and return all of them, labelled:

{
  "currency": "USD",
  "byInput": {
    "input": "pricing_period",
    "values": {
      "off_peak": { "amount": 0.62, "cardSource": "...", "estimated": false, "defaulted": [], "ignored": [] },
      "peak":     { "amount": 1.24, ... }
    }
  }
}
  • The value set comes from the card's own values (enum) or [true, false] (boolean). Nothing is invented and nothing is picked.
  • Supplying the input returns today's single result, unchanged.
  • Two or more missing choice inputs: refuse as today, naming every missing input and its values (no combinatorial expansion).
  • A missing quantity input: refuse as today, even if a choice is also missing.
  • If any one value fails to price (RateCardError), refuse the whole estimate and name the value. No partial results.
  • Inputs with a default are unaffected: the default applies.
  • Range estimates (#406, pricingRange): if routes hit this case, refuse with a clear error for now rather than nesting the two shapes. Note it in the PR.

Do

  • Implement in the shared estimate path (src/server/ estimate service, used by both POST /v1/estimate and MCP estimate_cost). Fix it once there, not per caller.
  • Make the evaluator's missing-input error name the input, so the estimate path can tell choice from quantity without parsing message text. Add a typed field if needed (@modelschemas/rate-card).
  • Response is a third oneOf arm next to the single and range results. Add a discriminator if cheap: the reviewer on #433 flagged 'min' in result as weak.
  • Regenerate: src/server/openapi.ts → bun run openapi:emit, bun run generate:client, bun scripts/emit-skill.ts. Update the MCP tool description. Add a client changeset and a README note (shape change, no back-compat needed).
  • Tests: a BytePlus pricing_period card with the lever missing (two values), supplied (single result), two choices missing (refuse naming both), a quantity missing (refuse), and one value erroring (refuse). Add a case to the shared estimate fixtures (packages/rate-card/src/fixtures/estimate-cases.ts) if the package evaluator changes.

Not this

  • No inferring a value from defaults elsewhere, the clock, or "cheapest".
  • No change to how cards are stored.
  1. tombeckenham closed this

Sign in to join this conversation.