{"record":{"id":"916b6da80d01ba59","repo":"BerriAI/litellm","slug":"invalid-arg-model-cannot-be-none","errorCode":null,"errorMessage":"Invalid arg. Model cannot be none.","messagePattern":"Invalid arg\\. Model cannot be none\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/cost_calculator.py","lineNumber":353,"sourceCode":"\n    Parameters:\n        model (str): The name of the model to use. Default is \"\"\n        prompt_tokens (int): The number of tokens in the prompt.\n        completion_tokens (int): The number of tokens in the completion.\n        response_time (float): The amount of time, in milliseconds, it took the call to complete.\n        prompt_characters (float): The number of characters in the prompt. Used for vertex ai cost calculation.\n        completion_characters (float): The number of characters in the completion response. Used for vertex ai cost calculation.\n        custom_llm_provider (str): The llm provider to whom the call was made (see init.py for full list)\n        custom_cost_per_token: Optional[CostPerToken]: the cost per input + output token for the llm api call.\n        custom_cost_per_second: Optional[float]: the cost per second for the llm api call.\n        call_type: Optional[str]: the call type\n\n    Returns:\n        tuple: A tuple containing the cost in USD dollars for prompt tokens and completion tokens, respectively.\n    \"\"\"\n\n    if model is None:\n        raise Exception(\"Invalid arg. Model cannot be none.\")\n\n    ## RECONSTRUCT USAGE BLOCK ##\n    if usage_object is not None:\n        usage_block = usage_object\n    else:\n        usage_block = Usage(\n            prompt_tokens=prompt_tokens,\n            completion_tokens=completion_tokens,\n            total_tokens=prompt_tokens + completion_tokens,\n            cache_creation_input_tokens=cache_creation_input_tokens,\n            cache_read_input_tokens=cache_read_input_tokens,\n        )\n\n    ## CUSTOM PRICING ##\n    # Normalize cache token counts across providers:\n    #   - OpenAI-compatible: usage.prompt_tokens_details.cached_tokens\n    #     (prompt_tokens already INCLUDES cached_tokens)\n    #   - Anthropic: usage.cache_read_input_tokens / cache_creation_input_tokens","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/cost_calculator.py#L335-L371","documentation":"Argument guard in the cost calculation API: the model argument is None, so the function cannot look up provider pricing or a cost handler and refuses to compute cost rather than returning a misleading zero.","triggerScenarios":"Thrown at litellm/cost_calculator.py:353 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-None model to the cost calculation call.","Ensure the model name is set on the request or response before computing cost."],"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"}