Skip to content

Commit

Permalink
fix: llm-proxy response_cost being 0 (#6293)
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyaoww authored Jan 16, 2025
1 parent 8579710 commit e211647
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions openhands/llm/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,16 @@ def _completion_cost(self, response) -> float:
logger.debug(f'Using custom cost per token: {cost_per_token}')
extra_kwargs['custom_cost_per_token'] = cost_per_token

try:
# try directly get response_cost from response
_hidden_params = getattr(response, '_hidden_params', {})
cost = _hidden_params.get('response_cost', None)
if cost is None:
cost = float(
_hidden_params.get('additional_headers', {}).get(
'llm_provider-x-litellm-response-cost', 0.0
)
)
# try directly get response_cost from response
_hidden_params = getattr(response, '_hidden_params', {})
cost = _hidden_params.get('additional_headers', {}).get(
'llm_provider-x-litellm-response-cost', None
)
if cost is not None:
cost = float(cost)
logger.debug(f'Got response_cost from response: {cost}')

try:
if cost is None:
try:
cost = litellm_completion_cost(
Expand Down

0 comments on commit e211647

Please sign in to comment.