get_usage_callback#

langchain_nvidia_ai_endpoints.callbacks.get_usage_callback(price_map: dict = {}, callback: UsageCallbackHandler | None = None) Generator[UsageCallbackHandler, None, None][source]#

Get the OpenAI callback handler in a context manager. which conveniently exposes token and cost information.

Returns:

The OpenAI callback handler.

Return type:

OpenAICallbackHandler

Parameters:

Example

>>> with get_openai_callback() as cb:
...     # Use the OpenAI callback handler