refactor(cli): inject the control plane transport and keep httpx base_url

This commit is contained in:
Hugo Durand
2026-09-18 13:33:49 -04:00
parent 177d772cba
commit a0e9bbc93a
5 changed files with 154 additions and 205 deletions
+2 -2
View File
@@ -1414,11 +1414,11 @@ def _call_host_backend_with_optional_tenant(
"Find your workspace ID in LangSmith under Settings > Workspaces.",
fg="yellow",
)
client._client.headers["X-Tenant-ID"] = click.prompt("Workspace ID")
client.set_tenant(click.prompt("Workspace ID"))
prompted_for_tenant = True
continue
if err.status_code == 403 and "not enabled" in err.message.lower():
smith_base = _smith_dashboard_base_url(client._base_url)
smith_base = _smith_dashboard_base_url(client.base_url)
raise HostBackendError(
"LangSmith Deployment is not enabled for this organization. "
f"Enable it at {smith_base}/host/deployments"
+8 -4
View File
@@ -24,10 +24,11 @@ class HostBackendClient:
base_url: str,
api_key: str,
tenant_id: str | None = None,
*,
transport: httpx.BaseTransport | None = None,
):
if not base_url:
raise click.UsageError("Host backend URL is required")
transport = httpx.HTTPTransport(retries=3)
headers: dict[str, str] = {
"X-Api-Key": api_key,
"Accept": "application/json",
@@ -36,8 +37,9 @@ class HostBackendClient:
headers["X-Tenant-ID"] = tenant_id
self._base_url = base_url.rstrip("/")
self._client = httpx.Client(
base_url=self._base_url,
headers=headers,
transport=transport,
transport=transport or httpx.HTTPTransport(retries=3),
timeout=30,
)
@@ -45,6 +47,9 @@ class HostBackendClient:
def base_url(self) -> str:
return self._base_url
def set_tenant(self, tenant_id: str) -> None:
self._client.headers["X-Tenant-ID"] = tenant_id
def _request(
self,
method: str,
@@ -53,8 +58,7 @@ class HostBackendClient:
params: dict[str, Any] | None = None,
) -> Any:
try:
full_url = self._base_url + path
resp = self._client.request(method, full_url, json=payload, params=params)
resp = self._client.request(method, path, json=payload, params=params)
resp.raise_for_status()
except httpx.HTTPStatusError as err:
detail = err.response.text or str(err.response.status_code)