> ## 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.

# Streaming Metrics

> Capture metrics from streaming responses.

Capture metrics from streaming responses. Use yield\_run\_output=True to receive a RunOutput at the end of the stream.

```python streaming_metrics.py theme={null}
"""
Streaming Metrics
=============================

Demonstrates how to capture metrics from streaming responses.
Use yield_run_output=True to receive a RunOutput at the end of the stream.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.run.agent import RunOutput
from rich.pretty import pprint

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    model=OpenAIChat(id="gpt-4o-mini"),
)

# ---------------------------------------------------------------------------
# Run Agent (Streaming)
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    response = None
    for event in agent.run("Count from 1 to 10.", stream=True, yield_run_output=True):
        if isinstance(event, RunOutput):
            response = event

    if response and response.metrics:
        print("=" * 50)
        print("STREAMING RUN METRICS")
        print("=" * 50)
        pprint(response.metrics)

        print("=" * 50)
        print("MODEL DETAILS")
        print("=" * 50)
        if response.metrics.details:
            for model_type, model_metrics_list in response.metrics.details.items():
                print(f"\n{model_type}:")
                for model_metric in model_metrics_list:
                    pprint(model_metric)
```

## Run the Example

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

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

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

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

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

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

Full source: [cookbook/02\_agents/14\_advanced/streaming\_metrics.py](https://github.com/agno-agi/agno/blob/main/cookbook/02_agents/14_advanced/streaming_metrics.py)
