Skip to content

The agent that grows with you

fix(video_gen): build the OpenAI-compatible video client on the env-only-proxy httpx client

teknium1e113c1b3aff3
diff --git a/agent/video_gen_provider.py b/agent/video_gen_provider.py
index 76743ae81fd..4b1644ba1b3 100644
--- a/agent/video_gen_provider.py
+++ b/agent/video_gen_provider.py
@@ -230,7 +230,15 @@ class OpenAICompatibleVideoGenProvider(VideoGenProvider):
if extra_body:
call_kwargs["extra_body"] = extra_body
- client = openai.OpenAI(api_key=self._api_key(), base_url=self._base_url())
+ # Env-only-proxy httpx client: a macOS system proxy (ExceptionsList invisible to httpx)
+ # must not swallow a local/custom ``<NAME>_BASE_URL`` (#64888).
+ from agent.process_bootstrap import build_keepalive_http_client
+
+ client_kwargs: Dict[str, Any] = {"api_key": self._api_key(), "base_url": self._base_url()}
+ http_client = build_keepalive_http_client(client_kwargs["base_url"])
+ if http_client is not None:
+ client_kwargs["http_client"] = http_client
+ client = openai.OpenAI(**client_kwargs)
try:
try:
video = self._create_and_poll(client, call_kwargs)
diff --git a/tests/plugins/video_gen/test_deepinfra_provider.py b/tests/plugins/video_gen/test_deepinfra_provider.py
index 6902625e460..b1095dbaf0c 100644
--- a/tests/plugins/video_gen/test_deepinfra_provider.py
+++ b/tests/plugins/video_gen/test_deepinfra_provider.py
@@ -81,9 +81,10 @@ def _fake_openai_with_capture(captured: dict, *, status="succeeded",
return SimpleNamespace(read=lambda: download)
class _FakeClient:
- def __init__(self, api_key=None, base_url=None):
+ def __init__(self, api_key=None, base_url=None, http_client=None):
captured["api_key"] = api_key
captured["base_url"] = base_url
+ captured["http_client"] = http_client
self.videos = _FakeVideos()
fake = MagicMock()
@@ -107,6 +108,32 @@ def _mock_url_download(captured: dict, raise_exc: Exception | None = None):
yield
+def test_generate_uses_env_only_proxy_http_client(monkeypatch):
+ """The SDK client is built on Hermes' env-only-proxy httpx client: a macOS system proxy (seen by
+ httpx via ``getproxies()``, ExceptionsList dropped) must not be mounted for a custom endpoint
+ (#64888), unlike a plain ``httpx.Client()`` under the same conditions (control)."""
+ import httpx
+ for key in ("HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", "https_proxy", "http_proxy", "all_proxy",
+ "NO_PROXY", "no_proxy"):
+ monkeypatch.delenv(key, raising=False)
+ monkeypatch.setenv("DEEPINFRA_BASE_URL", "http://localhost:18081/v1")
+ sys_proxy = {"http": "http://sysproxy:3128", "https": "http://sysproxy:3128"}
+
+ def proxy_mounts(client):
+ return [m for m in client._mounts.values() if type(getattr(m, "_pool", None)).__name__ == "HTTPProxy"]
+
+ captured: dict = {}
+ with patch("httpx._utils.getproxies", return_value=sys_proxy), \
+ patch.dict("sys.modules", {"openai": _fake_openai_with_capture(captured)}), \
+ _mock_url_download(captured):
+ with httpx.Client() as control:
+ assert len(proxy_mounts(control)) == 2
+ assert deepinfra_plugin.DeepInfraVideoGenProvider().generate(prompt="a cube", model="vendor/x")["success"]
+ assert captured["base_url"] == "http://localhost:18081/v1"
+ assert isinstance(captured["http_client"], httpx.Client) and proxy_mounts(captured["http_client"]) == []
+ captured["http_client"].close()
+
+
def test_generate_text_to_video_downloads_url_and_saves_locally():
"""t2v happy path: SDK called with DeepInfra base_url + key; status
'succeeded' + data[].url → bytes downloaded and saved to a local file."""