Skip to main content

Function: estimateMaxCallCostUSD()

estimateMaxCallCostUSD(providerId, modelId, req): number | undefined

Defined in: packages/agentos/src/api/runtime/modelPricing.ts:428

An upper bound, in US dollars, on what a call to modelId on providerId can cost, or undefined where it cannot be bounded; a host reserves it before the call and settles to the actual cost after.

  • Prompt tokens: maxInputTokens. The bound holds where the typical estimate does not: four characters a token undercounts CJK text, emoji and base64, which the providers' counting endpoints bill at up to 0.94 tokens a byte (the fixtures beside this module's tests).
  • Input rate: the highest the request can reach. The long-context card's where the token bound passes its threshold, and the higher of that and the highest cache-write rate the card names where the request asks for caching (cacheMarkers, or a cache_control or prompt_cache_breakpoint key in its text) or the model writes the cache by default (OpenAI on GPT-5.6 and later).
  • Output: the output cap as the request sends it, at the highest output rate the request can reach. A ceiling below the cap is not applied: a table's ceiling can trail the provider's (an OpenRouter variant of a model writes more than the model's own ceiling), and a request above the real one is refused unbilled.

Undefined, so a host refuses the call, when the model has no price row (modelPricing), when the request names no finite output cap or asks for more than one completion (n), carries a content part that is not text or replays an earlier audio answer, names a tool the provider defines or runs, or asks for a priority or fast tier or for regional processing, each of which bills by a measure or at a rate the text and the table do not show.

Parameters​

providerId​

string

modelId​

string

req​

MaxCostRequest

Returns​

number | undefined