# get_openai_token_cost_for_model

> **Function** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/callbacks/openai_info/get_openai_token_cost_for_model)

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

## Signature

```python
get_openai_token_cost_for_model(
    model_name: str,
    num_tokens: int,
    *,
    token_type: TokenType = TokenType.PROMPT,
) -> float
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `model_name` | `str` | Yes | Name of the model |
| `num_tokens` | `int` | Yes | Number of tokens. |
| `token_type` | `TokenType` | No | Token type. Defaults to ``TokenType.PROMPT``. (default: `TokenType.PROMPT`) |

## Returns

`float`

Cost in USD.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/4b280287bd55b99b44db2dd849f02d66c89534d5/libs/community/langchain_community/callbacks/openai_info.py#L366)