{"record":{"id":"2bd427c09bb5d739","repo":"BerriAI/litellm","slug":"could-not-calculate-cost-for-model-request-model","errorCode":null,"errorMessage":"Could not calculate cost for model '{request.model}' (resolved to '{resolved_model}'): {e}","messagePattern":"Could not calculate cost for model '(.+?)' \\(resolved to '(.+?)'\\): (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"warning","filePath":"litellm/proxy/management_endpoints/cost_tracking_settings.py","lineNumber":522,"sourceCode":"        messages=[],\n        stream=False,\n        call_type=\"completion\",\n        start_time=None,\n        litellm_call_id=\"cost-estimate\",\n        function_id=\"cost-estimate\",\n    )\n\n    # Use completion_cost which handles all the logic including margins/discounts\n    try:\n        cost_per_request: Final = completion_cost(\n            completion_response=mock_response,\n            model=resolved_model,\n            custom_llm_provider=resolved_provider,\n            custom_cost_per_token=resolved.custom_cost_per_token,\n            litellm_logging_obj=litellm_logging_obj,\n        )\n    except Exception as e:\n        raise HTTPException(\n            status_code=404,\n            detail={\n                \"error\": f\"Could not calculate cost for model '{request.model}' (resolved to '{resolved_model}'): {e}\"\n            },\n        )\n\n    # Get cost breakdown from the logging object\n    cost_breakdown: Final = litellm_logging_obj.cost_breakdown\n\n    input_cost: Final = cost_breakdown.get(\"input_cost\", 0.0) if cost_breakdown else 0.0\n    output_cost: Final = cost_breakdown.get(\"output_cost\", 0.0) if cost_breakdown else 0.0\n    margin_cost: Final = cost_breakdown.get(\"margin_total_amount\", 0.0) if cost_breakdown else 0.0\n\n    model_info: Final = _lookup_model_info(resolved_model)\n    mapped_input_price: Final = model_info.get(\"input_cost_per_token\") if model_info is not None else None\n    mapped_output_price: Final = model_info.get(\"output_cost_per_token\") if model_info is not None else None\n    mapped_provider: Final = model_info.get(\"litellm_provider\") if model_info is not None else None\n","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/management_endpoints/cost_tracking_settings.py#L504-L540","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","For Azure-style custom deployment names, set base_model to a known model so resolution maps to priced pricing.","Upgrade LiteLLM so the model exists in the current cost map.","Check the resolved name in the error message: if resolution produced the wrong/unpriced name, fix the deployment's model/base_model fields."],"exampleFix":"# before\nmodel_list:\n  - model_name: my-llama\n    litellm_params:\n      model: ollama/llama3\n      api_base: http://ollama:11434\n# POST /cost/estimate {\"model\": \"my-llama\", ...} -> 404\n\n# after\nmodel_list:\n  - model_name: my-llama\n    litellm_params:\n      model: ollama/llama3\n      api_base: http://ollama:11434\n      input_cost_per_token: 0.0000002\n      output_cost_per_token: 0.0000005","handlingStrategy":"try-catch","validationCode":"import litellm, requests\n\ndef model_priced(model: str) -> bool:\n    try:\n        info = litellm.get_model_info(model)\n        return info is not None\n    except Exception:\n        return False\n\nif not model_priced(request_model) and not deployment_has_custom_pricing(request_model):\n    raise ValueError(f\"No pricing for '{request_model}'; add input/output_cost_per_token or base_model\")","typeGuard":null,"tryCatchPattern":"try:\n    r = requests.post(f\"{PROXY_URL}/cost/estimate\", json={\"model\": \"my-llama\", \"input_tokens\": 1000, \"output_tokens\": 500}, headers=HDRS)\n    r.raise_for_status()\nexcept requests.HTTPError as e:\n    if e.response.status_code == 404 and \"Could not calculate cost\" in e.response.text:\n        # unpriced model: add per-token pricing to the deployment, then retry once\n        add_custom_pricing_to_deployment(\"my-llama\")\n        r = requests.post(f\"{PROXY_URL}/cost/estimate\", json=payload, headers=HDRS)\n        r.raise_for_status()\n    else:\n        raise","preventionTips":["Give every self-hosted/custom deployment explicit input_cost_per_token/output_cost_per_token.","Set base_model on Azure-style custom deployment names so resolution lands on priced models.","Keep LiteLLM updated so new models enter the cost map.","Inspect the 'resolved to' name in the error to debug alias->model mapping."],"tags":["litellm-proxy","cost-tracking","pricing","model-resolution"],"backgroundTag":"model-pricing-not-found","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}