# get_openai_callback

> **Function** in `langchain_community`

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

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

## Signature

```python
get_openai_callback() -> Generator[OpenAICallbackHandler, None, None]
```

## Description

**Example:**

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

## Returns

`None`

The OpenAI callback handler.

---

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