BerriAI/litellm · error · Exception

Model not found in cost map. Tried checking

Error message

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

What it means

litellm computes image-generation cost by looking the model up in the global litellm.model_cost map (loaded from model_prices_and_context_window.json). default_image_cost_calculator (litellm/cost_calculator.py:1951) tries seven key variants — "{quality}/{size}/{model}", "{size}/{model}", "high/{size}/{model}", "{size}/{model-without-provider}", the raw model, and the provider-stripped model — and if none is a key in litellm.model_cost it raises this generic Exception. The image API call itself has already succeeded; only cost calculation/logging fails, and the exception propagates through the response handling path.

Solutions

  1. Upgrade litellm to the latest release (pip install -U litellm) so the bundled model_prices_and_context_window.json includes pricing for the image model.
  2. Register custom pricing at startup before the call: litellm.register_model({"<your-model>": {"input_cost_per_image": 0.02, "mode": "image_generation"}}).
  3. On LiteLLM proxy, add the model to config.yaml/DB model_info with input_cost_per_image so the cost map lookup succeeds.
  4. Match one of the exact keys the calculator probes — "{quality}/{size}/{model}", "{size}/{model}", "high/{size}/{model}", "{size}/{model-without-provider}", or the bare model name — when naming your registered entry.

Example fix

# before: model has no pricing entry, cost lookup raises
result = litellm.image(model="my-custom-image-model", prompt="a cat", size="1024x1024")

# after: register pricing first (key format "{size}/{model}" is one of the probed variants)
litellm.register_model({
    "1024-x-1024/my-custom-image-model": {
        "input_cost_per_image": 0.02,
        "mode": "image_generation",
    }
})
result = litellm.image(model="my-custom-image-model", prompt="a cat", size="1024x1024")
Defensive patterns

Strategy: validation

Validate before calling

import litellm

def ensure_image_pricing(model: str, size: str = "1024-x-1024", quality: str | None = None) -> None:
    """Raise before the API call if the image model has no pricing entry."""
    size_str = size.replace("x", "-x-") if "x" in size and "-x-" not in size else size
    candidates = [
        f"{quality}/{size_str}/{model}" if quality else None,
        f"{size_str}/{model}",
        f"{size_str}/{model.split('/')[-1]}",
        model,
        model.split("/")[-1],
    ]
    if not any(c and c in litellm.model_cost for c in candidates):
        raise ValueError(
            f"No pricing for {model!r}; register it first: "
            "litellm.register_model({model: {'input_cost_per_image': ..., 'mode': 'image_generation'}})"
        )

Prevention

When it happens

Trigger: Calling litellm.image() (or POST /v1/images/generations on the proxy) with a model that has no entry in litellm.model_cost: a newly released image model on an older litellm install, a custom/self-hosted model name, or a size/quality combination whose "{quality}/{size}/{model}" key was never added to the pricing file. Also triggered when the proxy DB overrides litellm.model_cost with a partial map that lacks the image model.

Common situations: Running an older pinned litellm version behind a proxy when a new image model (e.g. a new gpt-image-1 or dall-e variant) ships; using internal model aliases that differ from the canonical pricing keys; passing a nonstandard size string (e.g. "1792x1024") so the size-prefixed lookup keys never match any entry.

Related errors


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

Appendix: source

Thrown at litellm/cost_calculator.py:2014

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