Allow logging request body
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.6k
- Forks
- 5.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 96
Description
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read src/openai/_base_client.py around lines 447-448 and review the linked custom httpx transport discussion. Trace how request and response bodies are handled, then determine the supported logging behavior needed for both; done means callers can inspect those bodies without capturing network traffic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, observability
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100