Skip unconfigured models in /balance

Existing users may have token usage recorded against models that have
since been removed from models.yml. Skip any model key not present in
the config when building the balance breakdown so /balance no longer
raises a KeyError for them.
This commit is contained in:
Father Bot
2026-05-23 16:41:20 +03:00
parent b0ca129e75
commit 5d8f98427e
+5
View File
@@ -752,6 +752,11 @@ async def show_balance_handle(update: Update, context: CallbackContext):
details_text = "🏷️ Details:\n"
for model_key in sorted(n_used_tokens_dict.keys()):
# skip models that are no longer configured (e.g. removed legacy models
# a user spent tokens on in the past) to avoid a KeyError
if model_key not in config.models["info"]:
continue
n_input_tokens, n_output_tokens = n_used_tokens_dict[model_key]["n_input_tokens"], n_used_tokens_dict[model_key]["n_output_tokens"]
total_n_used_tokens += n_input_tokens + n_output_tokens