{"record":{"id":"d7b893a166cd6888","repo":"BerriAI/litellm","slug":"model-model-info-key-does-not-have-input-cos","errorCode":null,"errorMessage":"Model {model_info['key']} does not have 'input_cost_per_character' or 'input_cost_per_token'","messagePattern":"Model (.+?) does not have 'input_cost_per_character' or 'input_cost_per_token'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/llm_cost_calc/utils.py","lineNumber":114,"sourceCode":"    Subtracts cached tokens from prompt tokens if applicable.\n    \"\"\"\n    details: Final = _parse_prompt_tokens_details(usage)\n    return usage.prompt_tokens - details[\"cache_hit_tokens\"]\n\n\ndef select_cost_metric_for_model(\n    model_info: ModelInfo,\n) -> Literal[\"cost_per_character\", \"cost_per_token\"]:\n    \"\"\"\n    Select 'cost_per_character' if model_info has 'input_cost_per_character'\n    Select 'cost_per_token' if model_info has 'input_cost_per_token'\n    \"\"\"\n    if model_info.get(\"input_cost_per_character\"):\n        return \"cost_per_character\"\n    elif model_info.get(\"input_cost_per_token\"):\n        return \"cost_per_token\"\n    else:\n        raise ValueError(\n            f\"Model {model_info['key']} does not have 'input_cost_per_character' or 'input_cost_per_token'\"\n        )\n\n\ndef _generic_cost_per_character(\n    model: str,\n    custom_llm_provider: str,\n    prompt_characters: float,\n    completion_characters: float,\n    custom_prompt_cost: float | None,\n    custom_completion_cost: float | None,\n) -> tuple[float | None, float | None]:\n    \"\"\"\n    Calculates cost per character for aspeech/speech calls.\n\n    Calculates the cost per character for a given model, input messages, and response object.\n\n    Input:","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/llm_cost_calc/utils.py#L96-L132","documentation":"select_cost_metric_for_model decides between character-based and token-based cost math by inspecting model_info; it requires at least one of 'input_cost_per_character' or 'input_cost_per_token'. When a model entry defines only other cost fields (e.g. only output costs, or only cost_per_second), the helper raises this ValueError because it cannot choose a metric for the input side.","triggerScenarios":"A cost calculation path that uses this selector (character/token cost utils) running against a model whose model_info — from model_prices_and_context_window.json, a custom pricing file, or config.yaml model_info — lacks both input_cost_per_character and input_cost_per_token (e.g. only output_cost_per_token set, or a free model declared with {} pricing).","commonSituations":"Hand-written custom pricing entries that forget input costs; free/community endpoints declared with no input cost; copy-paste of an output-only pricing block; older pricing entries missing the character fields used by character-billed models.","solutions":["Add input_cost_per_token (or input_cost_per_character for character-billed models) to the model's model_info in your config.yaml","If using a custom model_prices JSON, add the input cost fields (0.0 is valid for free models) and reload","Upgrade LiteLLM so the bundled pricing DB covers the model if it is a known public model","Verify with litellm.get_model_info(model) that the resolved entry actually has the fields you set (wildcard/deployment overrides can shadow it)"],"exampleFix":"# before (config.yaml)\nmodel_info:\n  output_cost_per_token: 0.00001   # missing input cost -> ValueError\n\n# after\nmodel_info:\n  input_cost_per_token: 0.0000025\n  output_cost_per_token: 0.00001","handlingStrategy":"validation","validationCode":"from litellm.litellm_core_utils.llm_cost_calc.utils import select_cost_metric_for_model\n\ndef pricing_complete(model_info: dict) -> bool:\n    return bool(model_info.get('input_cost_per_character') or model_info.get('input_cost_per_token'))\n\ninfo = litellm.get_model_info(model)\nassert pricing_complete(info), f\"model '{model}' lacks input_cost_per_token; cost calc will raise\"","typeGuard":"def has_input_cost(model_info: dict) -> bool:\n    return bool(model_info.get('input_cost_per_character') or model_info.get('input_cost_per_token'))","tryCatchPattern":null,"preventionTips":["Always set input_cost_per_token (0.0 for free models) in custom model_info entries","Lint your config.yaml / custom pricing JSON for missing input cost fields","Validate pricing completeness with litellm.get_model_info at startup, before first request"],"tags":["litellm","cost-calculation","pricing","model-info","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}