From 6a3b1e58ab18041c5f6fdb411e73592f3142639e Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Fri, 17 Jul 2026 19:48:12 +0200 Subject: [PATCH] fix(cost): price table with prefix match instead of hardcoded 2.5-flash rates --- main.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 3309569..f4dcd26 100644 --- a/main.py +++ b/main.py @@ -858,12 +858,22 @@ def get_viral_clips(transcript_result, video_duration): try: usage = response.usage_metadata if usage: - # Gemini 2.5 Flash Pricing (Dec 2025) - # Input: $0.10 per 1M tokens - # Output: $0.40 per 1M tokens - - input_price_per_million = 0.10 - output_price_per_million = 0.40 + # USD per 1M tokens, longest-prefix match on the model name so + # env-overridden models still price correctly (ai.google.dev). + MODEL_PRICES = { + "gemini-3.5-flash": (1.50, 9.00), + "gemini-3.1-flash-lite": (0.25, 1.50), + "gemini-3-flash-preview": (0.50, 3.00), + "gemini-2.5-flash-lite": (0.10, 0.40), + "gemini-2.5-flash": (0.30, 2.50), + } + match = None + for key in MODEL_PRICES: + if model_name.startswith(key) and (match is None or len(key) > len(match)): + match = key + input_price_per_million, output_price_per_million = ( + MODEL_PRICES[match] if match else (0.50, 3.00) # conservative default + ) prompt_tokens = usage.prompt_token_count output_tokens = usage.candidates_token_count