---
title: "OpenAI Agents"
description: "Learn about using Sentry for OpenAI Agents SDK."
url: https://docs.sentry.io/platforms/python/agent-tracing/openai-agents/
---

# OpenAI Agents for Python

##### Beta

The support for **OpenAI Agents SDK** is in its beta phase. Please test locally before using in production.

This integration connects Sentry with the [OpenAI Python SDK](https://openai.github.io/openai-agents-python/). The integration has been confirmed to work with OpenAI Agents version 0.10.3.

## Set up with Sentry CLI

Set up the Sentry Python SDK with the Sentry CLI. Install the CLI with one of these commands, then follow the Sentry CLI docs to finish setup.

**cURL**

```bash
curl https://cli.sentry.dev/install -fsS | bash
```

**PowerShell**

```powershell
irm https://cli.sentry.dev/install.ps1 | iex
```

**Homebrew**

```bash
brew install getsentry/tools/sentry
```

**npx**

```bash
npx sentry@latest
```

[Learn more about the Sentry CLI](https://cli.sentry.dev/)

Once you've installed this SDK, you can use the [Agents Dashboards](https://sentry.io/orgredirect/organizations/:orgslug/dashboards/?filter=onlyPrebuilt\&query=agents\&sort=mostPopular) to understand what's going on with your agents.

Sentry Agents tracing will automatically collect information about agents, tools, prompts, tokens, and models.

## [Install](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#install)

Install `sentry-sdk` from PyPI:

```bash
pip install "sentry-sdk"
```

*Other available variations of the above snippet: uv*

## [Configure](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#configure)

If you have the `agents` package in your dependencies, the OpenAI Agents integration will be enabled automatically when you initialize the Sentry SDK.

Error Monitoring\[ ]Tracing\[ ]Profiling

```python
import sentry_sdk

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of service spans for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
)
```

## [Verify](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#verify)

Verify that the integration works by running an agent. The resulting data should show up in your Agents Dashboard.

```python
import asyncio
import random

import sentry_sdk
import agents
from pydantic import BaseModel  # installed by openai-agents

@agents.function_tool
def random_number(max: int) -> int:
    return random.randint(0, max)

class FinalResult(BaseModel):
    number: int

random_number_agent = agents.Agent(
    name="Random Number Agent",
    instructions="Generate a random number.",
    tools=[random_number, ],
    output_type=FinalResult,
    model="gpt-4o-mini",
)

async def main() -> None:
    sentry_sdk.init(
        dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
        traces_sample_rate=1.0,
        # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
        data_collection={
            "gen_ai": {"inputs": True, "outputs": True},
        },
    )

    await agents.Runner.run(
        random_number_agent,
        input=f"Generate a random number between 0 and {10}.",
    )

if __name__ == "__main__":
    asyncio.run(main())
```

It may take a couple of moments for the data to appear in [sentry.io](https://sentry.io).

## [Behavior](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#behavior)

Data on the following will be collected:

* Agent invocations
* execution of tools
* number of input and output tokens used
* LLM models usage

By default, the SDK records LLM and tool inputs and outputs, such as prompts, messages, and responses. Tool definitions are recorded too; setting `inputs` to `False` in the `gen_ai` key removes them. To control this, use the `gen_ai` key of the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection), which lets you control inputs and outputs separately:

```python
sentry_sdk.init(
    # ...
    data_collection={
        # Record LLM and tool inputs, but not outputs
        "gen_ai": {"inputs": True, "outputs": False},
    },
)
```

In SDK versions prior to `3.0`, Sentry considers LLM and tool inputs and outputs as PII and doesn't include prompts, messages, or responses unless you pass a `data_collection` dictionary or set `send_default_pii=True`. With `send_default_pii=True`, you can exclude them with the integration's `include_prompts=False` option, as shown in the [Options section](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#options) below.

## [Options](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#options)

Only available in SDK versions prior to `3.0`. In SDK `3.x`, `OpenAIAgentsIntegration` doesn't accept any options. Use the `gen_ai` key of the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection) instead.

By adding `OpenAIAgentsIntegration` to your `sentry_sdk.init()` call explicitly, you can set options for `OpenAIAgentsIntegration` to change its behavior:

```python
import sentry_sdk
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration

sentry_sdk.init(
    # ...
    # Add data like inputs and responses;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    integrations=[
        OpenAIAgentsIntegration(
            include_prompts=False,  # LLM and tool inputs/outputs will be not sent to Sentry, despite send_default_pii=True
        ),
    ],
)
```

You can pass the following keyword arguments to `OpenAIAgentsIntegration()`:

* `include_prompts`:

  Whether LLM and tool inputs and outputs should be sent to Sentry. If you use the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection), this option is ignored. Use the `gen_ai` key instead.

  Sentry considers this data personal identifiable data (PII) by default. If you want to include the data, set `send_default_pii=True` in the `sentry_sdk.init()` call. To explicitly exclude prompts and outputs despite `send_default_pii=True`, configure the integration with `include_prompts=False`.

  The default is `True`.

## [Supported Versions](https://docs.sentry.io/platforms/python/agent-tracing/openai-agents.md#supported-versions)

* OpenAI Agents SDK: 0.0.19+ (SDK <3.0), 0.10.3+ (SDK 3.0+)
* Python: 3.9+
