{"record":{"id":"18f4143f52c1fb1e","repo":"BerriAI/litellm","slug":"model-not-found-in-cost-map-tried-checking-model","errorCode":null,"errorMessage":"Model not found in cost map. Tried checking {models_to_check}","messagePattern":"Model not found in cost map\\. Tried checking (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/cost_calculator.py","lineNumber":2014,"sourceCode":"    model_with_quality_without_provider = f\"{quality}/{model_without_provider}\" if quality else model_without_provider\n\n    # Try model with quality first, fall back to base model name\n    cost_info: dict | None = None\n    models_to_check: Final[list[str | None]] = [\n        model_name_with_quality,\n        base_model_name,\n        model_name_with_v2_quality,\n        model_with_quality_without_provider,\n        model_without_provider,\n        model,\n        model_name_without_custom_llm_provider,\n    ]\n    for _model in models_to_check:\n        if _model is not None and _model in litellm.model_cost:\n            cost_info = litellm.model_cost[_model]\n            break\n    if cost_info is None:\n        raise Exception(f\"Model not found in cost map. Tried checking {models_to_check}\")\n\n    # Priority 1: Use per-image pricing if available (for gpt-image-1 and similar models)\n    if \"input_cost_per_image\" in cost_info and cost_info[\"input_cost_per_image\"] is not None:\n        return cost_info[\"input_cost_per_image\"] * n\n    # Priority 2: Fall back to per-pixel pricing for backward compatibility\n    elif \"input_cost_per_pixel\" in cost_info and cost_info[\"input_cost_per_pixel\"] is not None:\n        return cost_info[\"input_cost_per_pixel\"] * height * width * n\n    else:\n        raise Exception(f\"No pricing information found for model {model}. Tried checking {models_to_check}\")\n\n\ndef default_video_cost_calculator(\n    model: str,\n    duration_seconds: float,\n    custom_llm_provider: str | None = None,\n    model_info: ModelInfo | None = None,\n    video_resolution: str | None = None,\n) -> float:","sourceCodeStart":1996,"sourceCodeEnd":2032,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/cost_calculator.py#L1996-L2032","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Register custom pricing at startup before the call: litellm.register_model({\"<your-model>\": {\"input_cost_per_image\": 0.02, \"mode\": \"image_generation\"}}).","On LiteLLM proxy, add the model to config.yaml/DB model_info with input_cost_per_image so the cost map lookup succeeds.","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."],"exampleFix":"# before: model has no pricing entry, cost lookup raises\nresult = litellm.image(model=\"my-custom-image-model\", prompt=\"a cat\", size=\"1024x1024\")\n\n# after: register pricing first (key format \"{size}/{model}\" is one of the probed variants)\nlitellm.register_model({\n    \"1024-x-1024/my-custom-image-model\": {\n        \"input_cost_per_image\": 0.02,\n        \"mode\": \"image_generation\",\n    }\n})\nresult = litellm.image(model=\"my-custom-image-model\", prompt=\"a cat\", size=\"1024x1024\")","handlingStrategy":"validation","validationCode":"import litellm\n\ndef ensure_image_pricing(model: str, size: str = \"1024-x-1024\", quality: str | None = None) -> None:\n    \"\"\"Raise before the API call if the image model has no pricing entry.\"\"\"\n    size_str = size.replace(\"x\", \"-x-\") if \"x\" in size and \"-x-\" not in size else size\n    candidates = [\n        f\"{quality}/{size_str}/{model}\" if quality else None,\n        f\"{size_str}/{model}\",\n        f\"{size_str}/{model.split('/')[-1]}\",\n        model,\n        model.split(\"/\")[-1],\n    ]\n    if not any(c and c in litellm.model_cost for c in candidates):\n        raise ValueError(\n            f\"No pricing for {model!r}; register it first: \"\n            \"litellm.register_model({model: {'input_cost_per_image': ..., 'mode': 'image_generation'}})\"\n        )","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin a recent litellm version and refresh it when new image models ship.","Call litellm.register_model for every custom/aliased image model at application startup.","In CI, assert every image model your app uses resolves in litellm.model_cost.","Wrap cost-calculation-sensitive logging separately from the image call so pricing gaps don't discard successful generations."],"tags":["image-generation","cost-tracking","pricing","model-registry"],"backgroundTag":"model-pricing-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}