{"record":{"id":"5ec78acd5c1ce9a2","repo":"BerriAI/litellm","slug":"usage-object-and-custom-llm-provider-must-be-provi","errorCode":null,"errorMessage":"usage object and custom_llm_provider must be provided for realtime stream cost calculation. Got cost_per_token_usage_object={cost_per_token_usage_object}, custom_llm_provider={custom_llm_provider}","messagePattern":"usage object and custom_llm_provider must be provided for realtime stream cost calculation\\. Got cost_per_token_usage_object=(.+?), custom_llm_provider=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/cost_calculator.py","lineNumber":1501,"sourceCode":"                        completion_tokens_cost_usd_dollar=completion_cost_result,\n                        cost_for_built_in_tools_cost_usd_dollar=0.0,\n                        total_cost_usd_dollar=_final_cost,\n                        original_cost=original_cost,\n                        discount_percent=discount_percent,\n                        discount_amount=discount_amount,\n                        margin_percent=margin_percent,\n                        margin_fixed_amount=margin_fixed_amount,\n                        margin_total_amount=margin_total_amount,\n                        service_tier=service_tier,\n                        data_residency=data_residency,\n                    )\n\n                    return _final_cost\n                elif call_type == _AREALTIME_CALL_TYPE and isinstance(\n                    completion_response, LiteLLMRealtimeStreamLoggingObject\n                ):\n                    if cost_per_token_usage_object is None or custom_llm_provider is None:\n                        raise ValueError(\n                            f\"usage object and custom_llm_provider must be provided for realtime stream cost calculation. Got cost_per_token_usage_object={cost_per_token_usage_object}, custom_llm_provider={custom_llm_provider}\"\n                        )\n                    return handle_realtime_stream_cost_calculation(\n                        results=completion_response.results,\n                        combined_usage_object=cost_per_token_usage_object,\n                        custom_llm_provider=custom_llm_provider,\n                        litellm_model_name=model,\n                        data_residency=data_residency,\n                        litellm_logging_obj=litellm_logging_obj,\n                    )\n                elif call_type == _MCP_CALL_TYPE:\n                    from litellm.proxy._experimental.mcp_server.cost_calculator import (\n                        MCPCostCalculator,\n                    )\n\n                    return MCPCostCalculator.calculate_mcp_tool_call_cost(litellm_logging_obj=litellm_logging_obj)\n                # Calculate cost based on prompt_tokens, completion_tokens\n                if \"togethercomputer\" in model or \"together_ai\" in model or custom_llm_provider == \"together_ai\":","sourceCodeStart":1483,"sourceCodeEnd":1519,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/cost_calculator.py#L1483-L1519","documentation":"Error \"usage object and custom_llm_provider must be provided for realtime stream cost calculation. Got cost_per_token_usage_object={cost_per_token_usage_object}, custom_llm_provider={custom_llm_provider}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/cost_calculator.py:1501 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide both the usage object and custom_llm_provider when computing realtime stream cost.","Ensure the realtime session passes usage data through to the cost calculator."],"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"}