diff --git a/pyproject.toml b/pyproject.toml index c63c46452e..d085811107 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ Repository = "https://github.com/openai/openai-python" [project.optional-dependencies] aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.9"] +http2 = ["httpx[http2]"] realtime = ["websockets >= 13, < 16"] datalib = ["numpy >= 1", "pandas >= 1.2.3", "pandas-stubs >= 1.1.0.11"] voice_helpers = ["sounddevice>=0.5.1", "numpy>=2.0.2"] diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index 216b36aabd..60d997caa0 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -39,6 +39,13 @@ from httpx import URL from pydantic import PrivateAttr +try: + import h2 # noqa: F401 + + _HTTP2_AVAILABLE = True +except ImportError: + _HTTP2_AVAILABLE = False + from . import _exceptions from ._qs import Querystring from ._files import to_httpx_files, async_to_httpx_files @@ -836,6 +843,7 @@ def __init__(self, **kwargs: Any) -> None: kwargs.setdefault("timeout", DEFAULT_TIMEOUT) kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS) kwargs.setdefault("follow_redirects", True) + kwargs.setdefault("http2", _HTTP2_AVAILABLE) super().__init__(**kwargs) @@ -1423,6 +1431,7 @@ def __init__(self, **kwargs: Any) -> None: kwargs.setdefault("timeout", DEFAULT_TIMEOUT) kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS) kwargs.setdefault("follow_redirects", True) + kwargs.setdefault("http2", _HTTP2_AVAILABLE) super().__init__(**kwargs)