What happens
src/openrouter/utils/logger.py:25 calls logging.basicConfig(level=logging.DEBUG) when
OPENROUTER_DEBUG is set. get_default_logger() runs at client construction
(src/openrouter/sdk.py:183), so simply instantiating OpenRouter() mutates the host
application's root logger.
Measured before/after OpenRouter(...) with OPENROUTER_DEBUG=1:
root level BEFORE: WARNING handlers: []
root level AFTER: DEBUG handlers: [<StreamHandler <stderr>>]
Every library in the process then emits DEBUG to stderr — httpx's request log showed up in
my capture — not just the SDK.
Why it's wrong
A library should configure its own logger, never the root one. basicConfig is for
applications; it's a global side effect that the caller didn't opt into and can't easily
undo. It also overrides any logging setup the app performed before the client was built.
No credential leakage here — httpx renders the auth header as 'authorization': '[secure]'
— so this is noise/ownership, not a security issue.
Repro
import logging, os
os.environ["OPENROUTER_DEBUG"] = "1"
print(logging.getLogger().level, logging.getLogger().handlers) # 30 []
from openrouter import OpenRouter
OpenRouter(api_key="x")
print(logging.getLogger().level, logging.getLogger().handlers) # 10 [StreamHandler]
Suggested fix
Scope the handler and level to the openrouter logger:
def get_default_logger() -> Logger:
if os.getenv("OPENROUTER_DEBUG"):
logger = logging.getLogger("openrouter")
if not logger.handlers:
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
return logger
return NoOpLogger()
Note: utils/logger.py is Speakeasy-generated (DO NOT EDIT header), so the change needs
to land in the generator template / gen config rather than as a direct edit here.
What happens
src/openrouter/utils/logger.py:25callslogging.basicConfig(level=logging.DEBUG)whenOPENROUTER_DEBUGis set.get_default_logger()runs at client construction(
src/openrouter/sdk.py:183), so simply instantiatingOpenRouter()mutates the hostapplication's root logger.
Measured before/after
OpenRouter(...)withOPENROUTER_DEBUG=1:Every library in the process then emits DEBUG to stderr — httpx's request log showed up in
my capture — not just the SDK.
Why it's wrong
A library should configure its own logger, never the root one.
basicConfigis forapplications; it's a global side effect that the caller didn't opt into and can't easily
undo. It also overrides any logging setup the app performed before the client was built.
No credential leakage here — httpx renders the auth header as
'authorization': '[secure]'— so this is noise/ownership, not a security issue.
Repro
Suggested fix
Scope the handler and level to the
openrouterlogger:Note:
utils/logger.pyis Speakeasy-generated (DO NOT EDITheader), so the change needsto land in the generator template / gen config rather than as a direct edit here.