BerriAI/litellm · error · Exception

Model not found in cost map. Tried checking {models_to_check

Error message

Model not found in cost map. Tried checking {models_to_check}

What it means

The default image-cost calculator tries several candidate names (base model, quality-suffixed, provider-stripped variants) against litellm.model_cost. If none of them is a key in the cost map, it raises this generic Exception listing every variant it tried — meaning the image model is unknown to LiteLLM's pricing data.

Source

Thrown at litellm/cost_calculator.py:2010

    model_with_quality_without_provider = f"{quality}/{model_without_provider}" if quality else model_without_provider

    # Try model with quality first, fall back to base model name
    cost_info: dict | None = None
    models_to_check: Final[list[str | None]] = [
        model_name_with_quality,
        base_model_name,
        model_name_with_v2_quality,
        model_with_quality_without_provider,
        model_without_provider,
        model,
        model_name_without_custom_llm_provider,
    ]
    for _model in models_to_check:
        if _model is not None and _model in litellm.model_cost:
            cost_info = litellm.model_cost[_model]
            break
    if cost_info is None:
        raise Exception(f"Model not found in cost map. Tried checking {models_to_check}")

    # Priority 1: Use per-image pricing if available (for gpt-image-1 and similar models)
    if "input_cost_per_image" in cost_info and cost_info["input_cost_per_image"] is not None:
        return cost_info["input_cost_per_image"] * n
    # Priority 2: Fall back to per-pixel pricing for backward compatibility
    elif "input_cost_per_pixel" in cost_info and cost_info["input_cost_per_pixel"] is not None:
        return cost_info["input_cost_per_pixel"] * height * width * n
    else:
        raise Exception(f"No pricing information found for model {model}. Tried checking {models_to_check}")


def default_video_cost_calculator(
    model: str,
    duration_seconds: float,
    custom_llm_provider: str | None = None,
    model_info: ModelInfo | None = None,
    video_resolution: str | None = None,
) -> float:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Update LiteLLM so the bundled cost map includes the model.
  2. Register pricing yourself: litellm.register_model({'model-id': {'input_cost_per_image': ...}}) before generating.
  3. Map custom deployment names to a known base model via the model_info in your router deployment.
  4. Catch the exception and skip/bill-zero for unmapped image models if that's acceptable.

Example fix

# before
cost = litellm.completion_cost(completion_response=resp, model="acme-image-v9")  # unknown

# after
litellm.register_model({"acme-image-v9": {"input_cost_per_image": 0.04}})
cost = litellm.completion_cost(completion_response=resp, model="acme-image-v9")
Defensive patterns

Strategy: validation

Validate before calling

import litellm

def image_model_priced(model: str) -> bool:
    candidates = {model, model.split("/")[-1]}
    return any(c in litellm.model_cost for c in candidates)

if not image_model_priced(model):
    litellm.register_model({model: {"input_cost_per_image": fallback}})

Type guard

def image_model_known(model: str) -> bool:
    base = model.split("/")[-1]
    return model in litellm.model_cost or base in litellm.model_cost

Try / catch

try:
    cost = litellm.completion_cost(completion_response=resp, model=model)
except Exception as e:
    if "Model not found in cost map" in str(e):
        litellm.register_model({model: {"input_cost_per_image": fallback_price}})
        cost = litellm.completion_cost(completion_response=resp, model=model)
    else:
        raise

Prevention

When it happens

Trigger: Calling image-generation cost calculation for a model absent from model_prices_and_context_window.json and not registered via litellm.register_model; unusual or private model names; provider-prefixed names whose stripped form is also unknown.

Common situations: New image models released after your LiteLLM version; custom deployment names (e.g. 'my-gpt-image') used as the model string; cost lookups after user-supplied model strings from an API endpoint.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/18f4143f52c1fb1e. Report an issue: GitHub.