Build a client from `LANGSMITH_*` / `LANGCHAIN_*` env vars. Endpoint resolution is env var > `_DEFAULT_ENDPOINT`. Project-local deploy state is intentionally ignored because it can be repository controlled and must not steer authenticated requests. Exits non-zero wi
(
cls,
*,
transport: httpx.BaseTransport | None = None,
)
| 89 | |
| 90 | @classmethod |
| 91 | def from_env( |
| 92 | cls, |
| 93 | *, |
| 94 | transport: httpx.BaseTransport | None = None, |
| 95 | ) -> ApiClient: |
| 96 | """Build a client from `LANGSMITH_*` / `LANGCHAIN_*` env vars. |
| 97 | |
| 98 | Endpoint resolution is env var > `_DEFAULT_ENDPOINT`. Project-local |
| 99 | deploy state is intentionally ignored because it can be repository |
| 100 | controlled and must not steer authenticated requests. |
| 101 | |
| 102 | Exits non-zero with a friendly message if the API key is missing. |
| 103 | """ |
| 104 | api_key = ( |
| 105 | os.environ.get("LANGSMITH_API_KEY") |
| 106 | or os.environ.get("LANGCHAIN_API_KEY") |
| 107 | or "" |
| 108 | ).strip() |
| 109 | if not api_key: |
| 110 | sys.stderr.write( |
| 111 | "Error: set LANGSMITH_API_KEY in your .env or environment.\n" |
| 112 | ) |
| 113 | raise SystemExit(1) |
| 114 | endpoint = ( |
| 115 | os.environ.get("LANGSMITH_ENDPOINT") |
| 116 | or os.environ.get("LANGCHAIN_ENDPOINT") |
| 117 | or _DEFAULT_ENDPOINT |
| 118 | ) |
| 119 | endpoint = _normalize_endpoint(endpoint) |
| 120 | return cls(endpoint=endpoint, api_key=api_key, transport=transport) |
| 121 | |
| 122 | def close(self) -> None: |
| 123 | """Close the underlying HTTP connection pool.""" |