fix(router.py): gracefully handle scenario where completion response doesn't have total tokens

Closes https://github.com/BerriAI/litellm/issues/4968
This commit is contained in:
Krrish Dholakia 2024-07-30 15:14:03 -07:00
parent 311521e56e
commit ec6db03c41

View file

@ -2944,7 +2944,7 @@ class Router:
elif isinstance(id, int): elif isinstance(id, int):
id = str(id) id = str(id)
total_tokens = completion_response["usage"]["total_tokens"] total_tokens = completion_response["usage"].get("total_tokens", 0)
# ------------ # ------------
# Setup values # Setup values