http_socket_optionsTCP socket options applied to the httpx transports built by this instance.
Defaults to a conservative TCP-keepalive + TCP_USER_TIMEOUT profile that
targets a ~2-minute bound on silent connection hangs (silent mid-stream peer
loss, gVisor/NAT idle timeouts, silent TCP black holes) on platforms that
support the full option set. On platforms that only support a subset
(macOS without TCP_USER_TIMEOUT, Windows with only SO_KEEPALIVE,
minimal kernels), unsupported options are silently dropped and the bound
degrades to whatever the remaining options + OS defaults provide — still
better than indefinite hang.
Accepted values:
None (default): use env-driven defaults. Matches the "unset" convention
used by http_client elsewhere on this class.() (empty): disable socket-option injection entirely. Inherits the OS
defaults and restores httpx's native env-proxy auto-detection.(level, option, value) tuples: explicit
override; passed verbatim to the transport (not filtered). Unsupported
options raise OSError at connect time rather than being silently
dropped — the user chose them explicitly.Environment variables (only consulted when this field is None):
LANGCHAIN_OPENAI_TCP_KEEPALIVE (set to 0 to disable entirely — the
kill-switch), LANGCHAIN_OPENAI_TCP_KEEPIDLE,
LANGCHAIN_OPENAI_TCP_KEEPINTVL, LANGCHAIN_OPENAI_TCP_KEEPCNT,
LANGCHAIN_OPENAI_TCP_USER_TIMEOUT_MS.
Applied per side: if http_client is supplied, the sync path uses
that user-owned client's socket options as-is; the async path still
gets http_socket_options applied to its default builder (and
vice-versa for http_async_client). Supply both to take full control.
When a custom httpx transport is active, httpx disables its
native env-proxy auto-detection (HTTP_PROXY / HTTPS_PROXY /
ALL_PROXY / NO_PROXY and macOS/Windows system proxy settings).
To keep the default shape safe, ChatOpenAI detects the
"proxy-env-shadow" pattern and skips the custom transport
entirely when all of the following hold:
http_socket_options is left at its default (None)http_client or http_async_client suppliedopenai_proxy suppliedOn that specific shape, the instance falls back to pre-PR behavior
and httpx's env-proxy auto-detection applies (a one-time INFO log
records the bypass for observability).
If you explicitly set http_socket_options=[...] while a proxy
env var is also set, no bypass — you opted into the transport, and
a one-time WARNING records the shadowing. Set
http_socket_options=() or LANGCHAIN_OPENAI_TCP_KEEPALIVE=0 to
disable transport injection explicitly, or pass a fully-configured
http_async_client / http_client to take full control. The
openai_proxy constructor kwarg is unaffected — socket options
are applied cleanly through the proxied transport on that path.