Toggle Menu
Prev Up Next

# `langchain_community.callbacks.manager`.get_openai_callback

langchain_community.callbacks.manager.get_openai_callback() → Generator[OpenAICallbackHandler, None, None]

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

  Returns

    The OpenAI callback handler.

  Return type

    OpenAICallbackHandler

  Example

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

# Examples using get_openai_callback

- !pip install -qU langchain-openai

- Run custom functions {#run-custom-functions}

- You can kick off concurrent runs from within the context manager

- azure_chat_openai.md

- token_usage_tracking.md