fix(cost): price table with prefix match instead of hardcoded 2.5-flash rates
This commit is contained in:
parent
e5d88999cf
commit
6a3b1e58ab
1 changed files with 16 additions and 6 deletions
22
main.py
22
main.py
|
|
@ -858,12 +858,22 @@ def get_viral_clips(transcript_result, video_duration):
|
||||||
try:
|
try:
|
||||||
usage = response.usage_metadata
|
usage = response.usage_metadata
|
||||||
if usage:
|
if usage:
|
||||||
# Gemini 2.5 Flash Pricing (Dec 2025)
|
# USD per 1M tokens, longest-prefix match on the model name so
|
||||||
# Input: $0.10 per 1M tokens
|
# env-overridden models still price correctly (ai.google.dev).
|
||||||
# Output: $0.40 per 1M tokens
|
MODEL_PRICES = {
|
||||||
|
"gemini-3.5-flash": (1.50, 9.00),
|
||||||
input_price_per_million = 0.10
|
"gemini-3.1-flash-lite": (0.25, 1.50),
|
||||||
output_price_per_million = 0.40
|
"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
|
prompt_tokens = usage.prompt_token_count
|
||||||
output_tokens = usage.candidates_token_count
|
output_tokens = usage.candidates_token_count
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue