Basic Streaming

Stream an AzureOpenAI agent's response with stream=True.

Code

from typing import Iterator  # noqa

from agno.agent import Agent, RunOutputEvent  # noqa
from agno.models.azure import AzureOpenAI

agent = Agent(model=AzureOpenAI(id="gpt-5.2"), markdown=True)

# Get the response in a variable
# run_response: Iterator[RunOutputEvent] = agent.run("Share a 2 sentence horror story", stream=True)
# for chunk in run_response:
#     print(chunk.content)

# Print the response on the terminal
agent.print_response("Share a 2 sentence horror story", stream=True)

Usage

Create or select a gpt-5.2 chat deployment. Set AZURE_OPENAI_DEPLOYMENT to its actual deployment name, and use the key and resource endpoint for that deployment. You may omit the deployment setting only when an existing deployment is named exactly like id. Keep id aligned with the deployed model family.

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Set your API key

export AZURE_OPENAI_API_KEY=xxx
export AZURE_OPENAI_ENDPOINT=xxx
export AZURE_OPENAI_DEPLOYMENT="your_chat_deployment"  # Optional

Install dependencies

uv pip install -U openai agno

Run Agent

python basic_stream.py