get_openai_token_cost_for_model#

langchain_community.callbacks.openai_info.get_openai_token_cost_for_model(
model_name: str,
num_tokens: int,
is_completion: bool = False,
*,
token_type: TokenType = TokenType.PROMPT,
) float[source]#

Get the cost in USD for a given model and number of tokens.

Parameters:
  • model_name (str) – Name of the model

  • num_tokens (int) – Number of tokens.

  • is_completion (bool) – Whether the model is used for completion or not. Defaults to False. Deprecated in favor of token_type.

  • token_type (TokenType) – Token type. Defaults to TokenType.PROMPT.

Returns:

Cost in USD.

Return type:

float