Back to Pydantic Ai

Stream Markdown

docs/examples/stream-markdown.md

1.90.0613 B
Original Source

This example shows how to stream markdown from an agent, using the rich library to highlight the output in the terminal.

It'll run the example with both OpenAI and Google Gemini models if the required environment variables are set.

Demonstrates:

Running the Example

With dependencies installed and environment variables set, run:

bash
python/uv-run -m pydantic_ai_examples.stream_markdown

Example Code

snippet {path="/examples/pydantic_ai_examples/stream_markdown.py"}