diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 4f5e171bc..73519126a 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -290,10 +290,14 @@ def _get_tracing_sampling_rate() -> float | None: def _get_api_key(api_key: Optional[str]) -> Optional[str]: - api_key = api_key or os.getenv("LANGSMITH_API_KEY", os.getenv("LANGCHAIN_API_KEY")) - if api_key is None or not api_key.strip(): + api_key_ = ( + api_key + if api_key is not None + else os.getenv("LANGSMITH_API_KEY", os.getenv("LANGCHAIN_API_KEY")) + ) + if api_key_ is None or not api_key_.strip(): return None - return api_key.strip().strip('"').strip("'") + return api_key_.strip().strip('"').strip("'") def _get_api_url(api_url: Optional[str]) -> str: @@ -452,7 +456,7 @@ def __init__( ) and os.getenv("LANGSMITH_RUNS_ENDPOINTS"): raise ls_utils.LangSmithUserError( "You cannot provide both LANGSMITH_ENDPOINT / LANGCHAIN_ENDPOINT " - "and LANGSMITH_ENDPOINTS." + "and LANGSMITH_RUNS_ENDPOINTS." ) self.tracing_sample_rate = _get_tracing_sampling_rate() diff --git a/python/tests/unit_tests/test_client.py b/python/tests/unit_tests/test_client.py index efce9c394..019253137 100644 --- a/python/tests/unit_tests/test_client.py +++ b/python/tests/unit_tests/test_client.py @@ -150,6 +150,8 @@ def test_validate_multiple_urls(monkeypatch: pytest.MonkeyPatch) -> None: "https://api.smith.langsmith-endpoint_2.com": "456", "https://api.smith.langsmith-endpoint_3.com": "789", } + monkeypatch.delenv("LANGCHAIN_ENDPOINT") + monkeypatch.delenv("LANGSMITH_ENDPOINT", raising=False) monkeypatch.setenv("LANGSMITH_RUNS_ENDPOINTS", json.dumps(data)) client = Client() assert client._write_api_urls == data