{"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":2010,"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":1992,"sourceCodeEnd":2028,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/cost_calculator.py#L1992-L2028","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Update LiteLLM so the bundled cost map includes the model.","Register pricing yourself: litellm.register_model({'model-id': {'input_cost_per_image': ...}}) before generating.","Map custom deployment names to a known base model via the model_info in your router deployment.","Catch the exception and skip/bill-zero for unmapped image models if that's acceptable."],"exampleFix":"# before\ncost = litellm.completion_cost(completion_response=resp, model=\"acme-image-v9\")  # unknown\n\n# after\nlitellm.register_model({\"acme-image-v9\": {\"input_cost_per_image\": 0.04}})\ncost = litellm.completion_cost(completion_response=resp, model=\"acme-image-v9\")","handlingStrategy":"validation","validationCode":"import litellm\n\ndef image_model_priced(model: str) -> bool:\n    candidates = {model, model.split(\"/\")[-1]}\n    return any(c in litellm.model_cost for c in candidates)\n\nif not image_model_priced(model):\n    litellm.register_model({model: {\"input_cost_per_image\": fallback}})","typeGuard":"def image_model_known(model: str) -> bool:\n    base = model.split(\"/\")[-1]\n    return model in litellm.model_cost or base in litellm.model_cost","tryCatchPattern":"try:\n    cost = litellm.completion_cost(completion_response=resp, model=model)\nexcept Exception as e:\n    if \"Model not found in cost map\" in str(e):\n        litellm.register_model({model: {\"input_cost_per_image\": fallback_price}})\n        cost = litellm.completion_cost(completion_response=resp, model=model)\n    else:\n        raise","preventionTips":["Register pricing for any non-standard image model at startup via litellm.register_model.","Validate user-supplied model strings against litellm.model_cost before generating.","Update LiteLLM when new image models ship."],"tags":["litellm","cost-calculation","image-generation","pricing-data"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}