> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brello.app/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI

> Track OpenAI Responses, Chat Completions, and Embeddings usage in Python.

Start with the [Python quickstart](https://docs.brello.app/sdk/python/quickstart.md). Set `OPENAI_API_KEY` and choose a model your project can use for `OPENAI_MODEL`.

## Track a Responses call

```python theme={null}
import os

from brello import Brello
from openai import OpenAI

brello = Brello()
with brello.wrap(OpenAI()) as client:
    response = client.responses.create(
        model=os.environ["OPENAI_MODEL"],
        input="Summarize the release notes.",
    )
    print(response.output_text)

brello.flush()
```

| API | Observed methods |
| - | - |
| Responses | `responses.create()`, including `stream=True`, `responses.parse()`, and `responses.stream()` |
| Chat Completions | `chat.completions.create()`, including `stream=True`, `chat.completions.parse()`, and `chat.completions.stream()` |
| Embeddings | `embeddings.create()` |

For embeddings, Brello records input tokens and zero output tokens. Brello estimates token costs from OpenAI's usage metadata. Separate charges for built-in tools, such as file search calls or Code Interpreter containers, are excluded from the estimate. Brello leaves prompts, outputs, tool arguments, and embedding vectors in your application.

## Track background Responses

For [background Responses](https://developers.openai.com/api/docs/guides/background), poll with `responses.retrieve(response_id)` on the same wrapped client or consume a resumed stream with `responses.stream(response_id=..., starting_after=...)`. Brello records the response once it observes a terminal status. If a different wrapped client resumes the stream, Brello uses that client's current context when it has no record of the original call.

## Track async Chat Completions streaming

Request the final usage chunk with `stream_options={"include_usage": True}` and consume the provider stream as usual.

```python theme={null}
import asyncio
import os

from brello import Brello
from openai import AsyncOpenAI


async def main():
    brello = Brello()
    async with brello.wrap(AsyncOpenAI()) as client:
        stream = await client.chat.completions.create(
            model=os.environ["OPENAI_MODEL"],
            messages=[{"role": "user", "content": "Summarize the release notes."}],
            stream=True,
            stream_options={"include_usage": True},
        )
        async with stream:
            async for chunk in stream:
                if chunk.choices:
                    print(chunk.choices[0].delta.content or "", end="")

    await brello.aflush()


asyncio.run(main())
```

If final token counts are unavailable, Brello records `usage: null`. Brello captures `x-request-id` from the OpenAI streaming response when available. With `with_raw_response` or `with_streaming_response`, Brello keeps the body available to your application and records basic request metadata without token usage.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.