{"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":118,"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":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/llm_cost_calc/utils.py#L100-L136","documentation":"select_cost_metric_for_model() decides whether a model is priced per character or per token by looking for input_cost_per_character then input_cost_per_token on the resolved ModelInfo; if neither is present it raises ValueError naming the model key. Because the checks are truthiness-based (model_info.get(...)), an input_cost_per_token of 0 also fails - a quirk that bites free-input models.","triggerScenarios":"Registering a custom model or overriding pricing (litellm.register_model / litellm.modify_pricing / proxy custom pricing) with an entry that has only output costs, per-second costs, or per-request costs, then making a request whose cost calculation routes through the generic cost calculator.","commonSituations":"Fine-tuned or internal models added to the pricing map with incomplete fields; typos in cost key names; entries defining only input_cost_per_token_batch or per-second audio pricing; input_cost_per_token: 0 for free-input models silently failing the truthiness check.","solutions":["Add input_cost_per_token (non-zero float) or input_cost_per_character to the model's entry via litellm.register_model / custom pricing yaml - note 0 will NOT pass the truthiness check","Inspect what actually resolved: litellm.get_model_info(model) and confirm the key exists and is truthy","For character-priced models (Gemini-style), set input_cost_per_character instead","On the proxy, fix the model_info / custom_pricing block and restart"],"exampleFix":"# before\nlitellm.register_model({\n    \"my-ft-model\": {\"max_tokens\": 8192, \"output_cost_per_token\": 0.000002}\n})\n# request -> ValueError: Model my-ft-model does not have 'input_cost_per_character' or 'input_cost_per_token'\n\n# after\nlitellm.register_model({\n    \"my-ft-model\": {\n        \"max_tokens\": 8192,\n        \"input_cost_per_token\": 0.000001,\n        \"output_cost_per_token\": 0.000002,\n    }\n})","handlingStrategy":"validation","validationCode":"import litellm\n\ninfo = litellm.get_model_info(model=\"my-ft-model\") or {}\nif not (info.get(\"input_cost_per_character\") or info.get(\"input_cost_per_token\")):\n    litellm.register_model({\n        \"my-ft-model\": {\n            \"max_tokens\": 8192,\n            \"input_cost_per_token\": 0.000001,\n            \"output_cost_per_token\": 0.000002,\n        }\n    })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always define both input and output cost keys when registering custom models","Remember the check is truthiness-based: input_cost_per_token of 0 still fails","Validate pricing entries in CI with a script that walks your model map and asserts required keys"],"tags":["litellm","pricing","cost-calculation","configuration"],"backgroundTag":"missing-pricing-config","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}