OpenAI API and structured logging in Python

Hi, I wrote a blog post with a reusable Python snippet that logs every OpenAI API request and response in JSON, including API errors.

You might find it interesting :wink:

tl;dr: I like the OpenAI dashboard Logs, but API errors are missing. Sometimes I’d really like to have the request along with the error. I show here how to wire httpx event_hooks into OpenAI to log every request and response in JSON format.

1 Like