| 2055 | |
| 2056 | |
| 2057 | def cost_headers( |
| 2058 | response_cost: float | str | None, litellm_logging_obj: LiteLLMLoggingObj | None |
| 2059 | ) -> Mapping[str, str | None]: |
| 2060 | if ( |
| 2061 | response_cost == 0 |
| 2062 | and litellm_logging_obj is not None |
| 2063 | and litellm_logging_obj.prepared_cost is not None |
| 2064 | and not litellm_logging_obj.prepared_cost.price_known |
| 2065 | ): |
| 2066 | return {} |
| 2067 | cost_breakdown: Final = _get_cost_breakdown_from_logging_obj( |
| 2068 | litellm_logging_obj=litellm_logging_obj, response_cost=response_cost |
| 2069 | ) |
| 2070 | return { |
| 2071 | "x-litellm-response-cost": str(response_cost), |
| 2072 | "x-litellm-response-cost-original": _header_value(cost_breakdown.original_cost), |
| 2073 | "x-litellm-response-cost-discount-amount": _header_value(cost_breakdown.discount_amount), |
| 2074 | "x-litellm-response-cost-margin-amount": _header_value(cost_breakdown.margin_total_amount), |
| 2075 | "x-litellm-response-cost-margin-percent": _header_value(cost_breakdown.margin_percent), |
| 2076 | "x-litellm-response-cost-input": _header_value(cost_breakdown.input_cost), |
| 2077 | "x-litellm-response-cost-output": _header_value(cost_breakdown.output_cost), |
| 2078 | "x-litellm-response-cost-cache-read": _header_value(cost_breakdown.cache_read_cost), |
| 2079 | "x-litellm-response-cost-cache-creation": _header_value(cost_breakdown.cache_creation_cost), |
| 2080 | "x-litellm-response-cost-reasoning": _header_value(cost_breakdown.reasoning_cost), |
| 2081 | "x-litellm-response-cost-tool-usage": _header_value(cost_breakdown.tool_usage_cost), |
| 2082 | } |
| 2083 | |
| 2084 | |
| 2085 | def _classifier_cost_from_request_data(request_data: Mapping[str, object] | None) -> float | None: |