BerriAI/litellm · warning · HTTPException

Could not calculate cost for model '{request.model}' (resolv

Error message

Could not calculate cost for model '{request.model}' (resolved to '{resolved_model}'): {e}

What it means

HTTP 404 from POST /cost/estimate: the endpoint resolved the requested model (possibly a router alias, via llm_router.get_model_list, base_model, or litellm_params.model) and then called litellm.cost_calculator.completion_cost on a mock response; completion_cost raised, almost always because the resolved model has no known pricing (not in LiteLLM's cost map) and the deployment carries no custom input_cost_per_token/output_cost_per_token. The message echoes both the requested and resolved model names plus the underlying error.

Source

Thrown at litellm/proxy/management_endpoints/cost_tracking_settings.py:522

        messages=[],
        stream=False,
        call_type="completion",
        start_time=None,
        litellm_call_id="cost-estimate",
        function_id="cost-estimate",
    )

    # Use completion_cost which handles all the logic including margins/discounts
    try:
        cost_per_request: Final = completion_cost(
            completion_response=mock_response,
            model=resolved_model,
            custom_llm_provider=resolved_provider,
            custom_cost_per_token=resolved.custom_cost_per_token,
            litellm_logging_obj=litellm_logging_obj,
        )
    except Exception as e:
        raise HTTPException(
            status_code=404,
            detail={
                "error": f"Could not calculate cost for model '{request.model}' (resolved to '{resolved_model}'): {e}"
            },
        )

    # Get cost breakdown from the logging object
    cost_breakdown: Final = litellm_logging_obj.cost_breakdown

    input_cost: Final = cost_breakdown.get("input_cost", 0.0) if cost_breakdown else 0.0
    output_cost: Final = cost_breakdown.get("output_cost", 0.0) if cost_breakdown else 0.0
    margin_cost: Final = cost_breakdown.get("margin_total_amount", 0.0) if cost_breakdown else 0.0

    model_info: Final = _lookup_model_info(resolved_model)
    mapped_input_price: Final = model_info.get("input_cost_per_token") if model_info is not None else None
    mapped_output_price: Final = model_info.get("output_cost_per_token") if model_info is not None else None
    mapped_provider: Final = model_info.get("litellm_provider") if model_info is not None else None

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Add explicit pricing to the deployment: input_cost_per_token / output_cost_per_token under litellm_params or model_info in the model's config entry — the estimator picks these up as custom_cost_per_token.
  2. For Azure-style custom deployment names, set base_model to a known model so resolution maps to priced pricing.
  3. Upgrade LiteLLM so the model exists in the current cost map.
  4. Check the resolved name in the error message: if resolution produced the wrong/unpriced name, fix the deployment's model/base_model fields.

Example fix

# before
model_list:
  - model_name: my-llama
    litellm_params:
      model: ollama/llama3
      api_base: http://ollama:11434
# POST /cost/estimate {"model": "my-llama", ...} -> 404

# after
model_list:
  - model_name: my-llama
    litellm_params:
      model: ollama/llama3
      api_base: http://ollama:11434
      input_cost_per_token: 0.0000002
      output_cost_per_token: 0.0000005
Defensive patterns

Strategy: try-catch

Validate before calling

import litellm, requests

def model_priced(model: str) -> bool:
    try:
        info = litellm.get_model_info(model)
        return info is not None
    except Exception:
        return False

if not model_priced(request_model) and not deployment_has_custom_pricing(request_model):
    raise ValueError(f"No pricing for '{request_model}'; add input/output_cost_per_token or base_model")

Try / catch

try:
    r = requests.post(f"{PROXY_URL}/cost/estimate", json={"model": "my-llama", "input_tokens": 1000, "output_tokens": 500}, headers=HDRS)
    r.raise_for_status()
except requests.HTTPError as e:
    if e.response.status_code == 404 and "Could not calculate cost" in e.response.text:
        # unpriced model: add per-token pricing to the deployment, then retry once
        add_custom_pricing_to_deployment("my-llama")
        r = requests.post(f"{PROXY_URL}/cost/estimate", json=payload, headers=HDRS)
        r.raise_for_status()
    else:
        raise

Prevention

When it happens

Trigger: POST /cost/estimate with a model absent from the public cost map (self-hosted/OSS models like 'ollama/llama3' or private fine-tunes) whose deployment has no input_cost_per_token/output_cost_per_token in litellm_params or model_info; a typo'd model name that resolves to nothing; router aliases whose underlying deployment name is unmapped.

Common situations: Estimating costs for on-prem or custom-deployment models (Azure custom names without base_model set); using an alias where the deployment's 'model' field is an internal name LiteLLM can't price; new/unreleased models on an older LiteLLM version whose cost map lacks them.

Related errors


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