openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

Allow logging request body

Open palvarezcordoba opened this issue 8 months ago • 6 comments

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

  • [X] This is a feature request for the Python library

Describe the feature or improvement you're requesting

It would be nice to be able to be able to log the body of the requests. I needed to see what was sent over the wire, so I checked how to log body requests. Turns out, there's no way.

I needed to modify this, in order to do it. https://github.com/openai/openai-python/blob/58bec2ffe5274b37fed3adad8da188f0cbc5406c/src/openai/_base_client.py#L447-L448

Could you add support to log body requests?

I'm not sure if this is the only place that has to change. In fact, I just ended capturing network traffic just to be sure. Having to resort to this kind of technique, is not nice.

I'm aware that you can log request/response using a custom httpx client with a custom transport: https://github.com/encode/httpx/discussions/3073

EDIT: the same applies to responses body

Additional context

No response

palvarezcordoba avatar Jul 03 '24 12:07 palvarezcordoba