Estimate: return a price per value when one required choice input is missing #450
Send to my agentProblem#
/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:
| input | values | rows | providers |
|---|---|---|---|
| target_resolution | 480p…4K | 25 | fal, replicate |
| model_variant | with_audio/without_audio, speed/precision, … | 15 | replicate |
| resolution | 480p…4k | 4 | byteplus, fal, grok |
| input_video | true/false | 4 | byteplus |
| pricing_period | off_peak/peak | 3 | byteplus |
| listen_mode | streaming/pre_recorded | 3 | deepgram |
| language_scope | monolingual/multilingual | 1 | deepgram |
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
defaultare 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 bothPOST /v1/estimateand MCPestimate_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
oneOfarm next to the single and range results. Add a discriminator if cheap: the reviewer on #433 flagged'min' in resultas 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_periodcard 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.
tombeckenham closed this
Sign in to join this conversation.