How can I disable OpenAI client logs in Python

When I set this INFO level


There are OpenAI logs in the file
2023-11-23 15:01:37,630 HTTP Request: POST “HTTP/1.1 200 OK”

2023-11-23 15:01:40,139 HTTP Request: POST “HTTP/1.1 200 OK”

2023-11-23 15:01:42,698 HTTP Request: POST “HTTP/1.1 200 OK”

2023-11-23 15:01:44,483 HTTP Request: POST “HTTP/1.1 200 OK”
How can I prevent this logging?

1 Like

I have already set the environment variable: OPENAI_LOG_FORMAT = ''

You want to log your entire script at INFO instead of WARNING, but don’t want to see that particular message?

Filter objects: logging — Logging facility for Python — Python 3.12.0 documentation

Seems like something an AI could craft for you once you know what to ask for.

I was using OpenAI module in my program. When I was doing logging in my program it was also logging the OpenAI requests, which I wanted to avoid.
I was doing this before

logger = logging.getLogger()

With this, I got the root logger and it was printing the logs of all modules in my program.
Now I am doing:

logger = logging.getLogger("Assitant")

This give me a logger for my program.


started using the logger in my code, found it helpful, thanks for sharing

# Disable OpenAI and httpx logging
# Configure logging level for specific loggers by name
# # Disable specific loggers by name
# logging.getLogger("openai").disabled = True
# logging.getLogger("httpx").disabled = True