BerriAI/litellm · error · ValueError

Model does not have 'input_cost_per_character' or…

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 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.

Solutions

  1. 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
  2. Inspect what actually resolved: litellm.get_model_info(model) and confirm the key exists and is truthy
  3. For character-priced models (Gemini-style), set input_cost_per_character instead
  4. On the proxy, fix the model_info / custom_pricing block and restart

Example fix

# before
litellm.register_model({
    "my-ft-model": {"max_tokens": 8192, "output_cost_per_token": 0.000002}
})
# request -> ValueError: Model my-ft-model does not have 'input_cost_per_character' or 'input_cost_per_token'

# after
litellm.register_model({
    "my-ft-model": {
        "max_tokens": 8192,
        "input_cost_per_token": 0.000001,
        "output_cost_per_token": 0.000002,
    }
})
Defensive patterns

Strategy: validation

Validate before calling

import litellm

info = litellm.get_model_info(model="my-ft-model") or {}
if not (info.get("input_cost_per_character") or info.get("input_cost_per_token")):
    litellm.register_model({
        "my-ft-model": {
            "max_tokens": 8192,
            "input_cost_per_token": 0.000001,
            "output_cost_per_token": 0.000002,
        }
    })

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/d7b893a166cd6888. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/llm_cost_calc/utils.py:118

    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 77b7c6c40c)