@@ -173,7 +173,9 @@ def __call__(self, *args, **kwargs):
173173 def fetch_pricing_information_from_provider (self ) -> Optional [dict ]:
174174 """
175175 Fetch the pricing information dictionary for the given provider.
176- Returns a dict mapping model names to pricing info, or None if not found.
176+
177+ Returns:
178+ Optional[dict]: A dict mapping model names to pricing info, or None if not found.
177179 """
178180 pricing_fn_map = {
179181 "openai" : get_pricing_openai ,
@@ -248,11 +250,19 @@ def get_effective_cost(self, response):
248250 )
249251 return 0.0
250252
251- def get_effective_cost_from_antrophic_api (self , response ):
252- """Get the effective cost from the Anthropic API response.
253- ## Anthropic usage 'input_tokens' are new input tokens (tokens that are not cached).
254- ## Anthorphic has different pricing for cache write and cache read tokens.
255- ## See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#tracking-cache-performance
253+ def get_effective_cost_from_antrophic_api (self , response ) -> float :
254+ """
255+ Get the effective cost from the Anthropic API response.
256+
257+ Anthropic usage 'input_tokens' are new input tokens (tokens that are not cached).
258+ Anthropic has different pricing for cache write and cache read tokens.
259+ See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching#tracking-cache-performance
260+
261+ Args:
262+ response: The response object from the Anthropic API.
263+
264+ Returns:
265+ float: The effective cost calculated from the response.
256266 """
257267 usage = getattr (response , "usage" , {})
258268 new_input_tokens = getattr (usage , "input_tokens" , 0 ) # new input tokens
@@ -272,13 +282,21 @@ def get_effective_cost_from_antrophic_api(self, response):
272282 )
273283 return effective_cost
274284
275- def get_effective_cost_from_openai_api (self , response ):
276- """Get the effective cost from the OpenAI API response.
277- ## OpenAI usage 'prompt_tokens' are the total input tokens (cache read tokens + new input tokens).
278- ## See https://openai.com/index/api-prompt-caching/
279- ## OpenAI has only one price for cache tokens i.e. cache read price. (Generally 50% cheaper)
280- ## OpenAI had no extra charge for cache write tokens.
281- ## See Pricing Here: https://platform.openai.com/docs/pricing
285+ def get_effective_cost_from_openai_api (self , response ) -> float :
286+ """
287+ Get the effective cost from the OpenAI API response.
288+
289+ OpenAI usage 'prompt_tokens' are the total input tokens (cache read tokens + new input tokens).
290+ See https://openai.com/index/api-prompt-caching/
291+ OpenAI has only one price for cache tokens, i.e., cache read price (generally 50% cheaper).
292+ OpenAI has no extra charge for cache write tokens.
293+ See Pricing Here: https://platform.openai.com/docs/pricing
294+
295+ Args:
296+ response: The response object from the OpenAI API.
297+
298+ Returns:
299+ float: The effective cost calculated from the response.
282300 """
283301 usage = getattr (response , "usage" , {})
284302 prompt_token_details = getattr (response , "prompt_tokens_details" , {})
0 commit comments