wuenlp_tools.utils.model_cost
1from loguru import logger 2 3model_cost_query = { 4 "gpt-5": 1.25 / 1000000, 5 "gpt-5-mini": 0.25 / 1000000, 6 "gpt-5-nano": 0.05 / 1000000, 7 "o4-mini": 1.1 / 1000000, 8 "o4-mini-deep-research": 2 / 1000000, 9 "gpt-4.1": 2 / 1000000, 10 "gpt-4.1-mini": 0.4 / 1000000, 11 "gpt-4.1-nano": 0.1 / 1000000, 12 "gpt-4o": 2.5 / 1000000, 13 "o1-preview": 15 / 1000000, 14 "o1-mini": 1.1 / 1000000, 15 "o3-mini": 1.1 / 1000000, 16 "gpt-4o-2024-08-06": 2.5 / 1000000, 17 "gpt-4o-mini": 0.15 / 1000000, 18 "gpt-4o-mini-search-preview": 0.15 / 1000000, 19 "gpt-3.5-turbo": 0.5 / 1000000 20} 21model_cost_output = { 22 "gpt-5": 10 / 1000000, 23 "gpt-5-mini": 2 / 1000000, 24 "gpt-5-nano": 0.4 / 1000000, 25 "o4-mini": 4.4 / 1000000, 26 "o4-mini-deep-research": 8 / 1000000, 27 "gpt-4.1": 8 / 1000000, 28 "gpt-4.1-mini": 1.6 / 1000000, 29 "gpt-4.1-nano": 0.4 / 1000000, 30 "gpt-4o": 10 / 1000000, 31 "o1-preview": 60 / 1000000, 32 "o1-mini": 4.4 / 1000000, 33 "o3-mini": 4.4 / 1000000, 34 "gpt-4o-2024-08-06": 10 / 1000000, 35 "gpt-4o-mini": 0.6 / 1000000, 36 "gpt-4o-mini-search-preview": 0.6 / 1000000, 37 "gpt-3.5-turbo": 1.5 / 1000000 38} 39 40model_cost_image = { 41 "normal": 0.04, 42 "high": 0.08, 43} 44 45 46def get_cost(response, model): 47 response_message = response.choices[0].message 48 completion_tokens = response.usage.completion_tokens 49 prompt_tokens = response.usage.prompt_tokens 50 try: 51 cost = model_cost_query[model] * prompt_tokens + model_cost_output[model] * completion_tokens 52 except Exception as e: 53 logger.error(f"Error calculating cost for model {model}: {e}") 54 cost = 0 55 56 return cost
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
47def get_cost(response, model): 48 response_message = response.choices[0].message 49 completion_tokens = response.usage.completion_tokens 50 prompt_tokens = response.usage.prompt_tokens 51 try: 52 cost = model_cost_query[model] * prompt_tokens + model_cost_output[model] * completion_tokens 53 except Exception as e: 54 logger.error(f"Error calculating cost for model {model}: {e}") 55 cost = 0 56 57 return cost