BerriAI/litellm · error · ValueError
Model {model_info['key']} does not have 'input_cost_per_char
Error message
Model {model_info['key']} does not have 'input_cost_per_character' or 'input_cost_per_token' What it means
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.
Source
Thrown at litellm/litellm_core_utils/llm_cost_calc/utils.py:114
Subtracts cached tokens from prompt tokens if applicable.
"""
details: Final = _parse_prompt_tokens_details(usage)
return usage.prompt_tokens - details["cache_hit_tokens"]
def select_cost_metric_for_model(
model_info: ModelInfo,
) -> Literal["cost_per_character", "cost_per_token"]:
"""
Select 'cost_per_character' if model_info has 'input_cost_per_character'
Select 'cost_per_token' if model_info has 'input_cost_per_token'
"""
if model_info.get("input_cost_per_character"):
return "cost_per_character"
elif model_info.get("input_cost_per_token"):
return "cost_per_token"
else:
raise ValueError(
f"Model {model_info['key']} does not have 'input_cost_per_character' or 'input_cost_per_token'"
)
def _generic_cost_per_character(
model: str,
custom_llm_provider: str,
prompt_characters: float,
completion_characters: float,
custom_prompt_cost: float | None,
custom_completion_cost: float | None,
) -> tuple[float | None, float | None]:
"""
Calculates cost per character for aspeech/speech calls.
Calculates the cost per character for a given model, input messages, and response object.
Input:View on GitHub (pinned to 6c2dcb801b)
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)
Example fix
# before (config.yaml) model_info: output_cost_per_token: 0.00001 # missing input cost -> ValueError # after model_info: input_cost_per_token: 0.0000025 output_cost_per_token: 0.00001
Defensive patterns
Strategy: validation
Validate before calling
from litellm.litellm_core_utils.llm_cost_calc.utils import select_cost_metric_for_model
def pricing_complete(model_info: dict) -> bool:
return bool(model_info.get('input_cost_per_character') or model_info.get('input_cost_per_token'))
info = litellm.get_model_info(model)
assert pricing_complete(info), f"model '{model}' lacks input_cost_per_token; cost calc will raise" Type guard
def has_input_cost(model_info: dict) -> bool:
return bool(model_info.get('input_cost_per_character') or model_info.get('input_cost_per_token')) Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- [Non-Blocking] LiteLLM.Success_Call Error: {e}
- Error: {response.status_code} - {response.text}
- Missing Authorization header
- Invalid bearer token
- Invalid API key
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/d7b893a166cd6888.
Report an issue: GitHub.