Skip to main content
This middleware captures non-streaming JSON bodies and streaming SSE content for POST .../runs requests carrying X-APP-UUID. A public ASGI send wrapper observes response body frames without rebuilding the response, so no private Starlette response import or type check is needed.
response_middleware.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export your OpenAI API key

4

Run the example

Save the code above as response_middleware.py, then run:
Full source: cookbook/05_agent_os/06_customize/response_middleware.py