{"record":{"id":"f39c69652e84503f","repo":"BerriAI/litellm","slug":"model-is-none-and-does-not-exist-in-passed-complet","errorCode":null,"errorMessage":"Model is None and does not exist in passed completion_response. Passed completion_response={completion_response}, model={model}","messagePattern":"Model is None and does not exist in passed completion_response\\. Passed completion_response=(.+?), model=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/cost_calculator.py","lineNumber":1311,"sourceCode":"                    total_time = getattr(completion_response, \"_response_ms\", 0)\n\n                    hidden_params = getattr(completion_response, \"_hidden_params\", None)\n                    if hidden_params is not None:\n                        custom_llm_provider = hidden_params.get(\"custom_llm_provider\", custom_llm_provider or None)\n                        region_name = hidden_params.get(\"region_name\", region_name)\n\n                        # For Gemini/Vertex AI responses, trafficType is stored in\n                        # provider_specific_fields.  Map it to the service_tier used\n                        # by the cost key lookup (_priority / _flex suffixes) so that\n                        # ON_DEMAND_PRIORITY requests are billed at priority prices.\n                        if service_tier is None:\n                            provider_specific = hidden_params.get(\"provider_specific_fields\") or {}\n                            raw_traffic_type = provider_specific.get(\"traffic_type\")\n                            if raw_traffic_type:\n                                service_tier = _map_traffic_type_to_service_tier(raw_traffic_type)\n                else:\n                    if model is None:\n                        raise ValueError(\n                            f\"Model is None and does not exist in passed completion_response. Passed completion_response={completion_response}, model={model}\"\n                        )\n                    if len(messages) > 0:\n                        prompt_tokens = token_counter(model=model, messages=messages)\n                    elif len(prompt) > 0:\n                        prompt_tokens = token_counter(model=model, text=prompt)\n                    completion_tokens = token_counter(model=model, text=completion)\n\n                # Handle A2A calls before model check - A2A doesn't require a model\n                if call_type in _A2A_CALL_TYPES:\n                    from litellm.a2a_protocol.cost_calculator import A2ACostCalculator\n\n                    return A2ACostCalculator.calculate_a2a_cost(litellm_logging_obj=litellm_logging_obj)\n\n                if model is None:\n                    raise ValueError(\n                        f\"Model is None and does not exist in passed completion_response. Passed completion_response={completion_response}, model={model}\"\n                    )","sourceCodeStart":1293,"sourceCodeEnd":1329,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/cost_calculator.py#L1293-L1329","documentation":"Cost extraction from a completion response found no model: the model argument was None and the response object carries no model field (echoed in the message), so the correct pricing row cannot be located.","triggerScenarios":"Thrown at litellm/cost_calculator.py:1311 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the model explicitly, or use a completion_response object that contains a model field.","Verify the response object you pass is a valid ModelResponse with model set."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}