get_openai_callback#
- langchain_community.callbacks.manager.get_openai_callback() Generator[OpenAICallbackHandler, 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:
Example
>>> with get_openai_callback() as cb: ... # Use the OpenAI callback handler
Examples using get_openai_callback