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

# Arize Phoenix Via OpenInference

> Trace a structured-output stock agent to Phoenix Cloud via phoenix.otel register with auto-instrumentation.

Demonstrates instrumenting an Agno agent with OpenInference and sending traces to Phoenix.

```python arize_phoenix_via_openinference.py theme={null}
"""
Arize Phoenix Via OpenInference
===============================

Demonstrates instrumenting an Agno agent with OpenInference and sending traces to Phoenix.
"""

import asyncio
import os

from agno.agent import Agent
from agno.db.in_memory import InMemoryDb
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
from phoenix.otel import register
from pydantic import BaseModel

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
os.environ["PHOENIX_API_KEY"] = os.getenv("PHOENIX_API_KEY")
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = (
    "https://app.phoenix.arize.com/"  # Add the suffix for your organization
)

# Configure the Phoenix tracer
tracer_provider = register(
    project_name="default",  # Default is 'default'
    auto_instrument=True,  # Automatically use the installed OpenInference instrumentation
)


class StockPrice(BaseModel):
    stock_price: float


# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIChat(id="gpt-5.2"),
    tools=[YFinanceTools()],
    db=InMemoryDb(),
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
    session_id="test_123",
    output_schema=StockPrice,
)


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    asyncio.run(
        agent.aprint_response("What is the current price of Tesla?", stream=True)
    )
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno arize-phoenix openai openinference-instrumentation-agno yfinance
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      export PHOENIX_API_KEY="your_phoenix_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      $Env:PHOENIX_API_KEY="your_phoenix_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `arize_phoenix_via_openinference.py`, then run:

    ```bash theme={null}
    python arize_phoenix_via_openinference.py
    ```
  </Step>
</Steps>

Full source: [cookbook/observability/arize\_phoenix\_via\_openinference.py](https://github.com/agno-agi/agno/blob/main/cookbook/observability/arize_phoenix_via_openinference.py)
