langsmith.client.Client#

class langsmith.client.Client(api_url: str | None = None, *, api_key: str | None = None, retry_config: Retry | None = None, timeout_ms: int | Tuple[int, int] | None = None, web_url: str | None = None, session: Session | None = None, auto_batch_tracing: bool = True, anonymizer: Callable[[dict], dict] | None = None, hide_inputs: Callable[[dict], dict] | bool | None = None, hide_outputs: Callable[[dict], dict] | bool | None = None, info: dict | LangSmithInfo | None = None, api_urls: Dict[str, str] | None = None)[source]#

Client for interacting with the LangSmith API.

Initialize a Client instance.

Parameters:
  • api_url (str or None, default=None) – URL for the LangSmith API. Defaults to the LANGCHAIN_ENDPOINT environment variable or https://api.smith.langchain.com if not set.

  • api_key (str or None, default=None) – API key for the LangSmith API. Defaults to the LANGCHAIN_API_KEY environment variable.

  • retry_config (Retry or None, default=None) – Retry configuration for the HTTPAdapter.

  • timeout_ms (int, tuple[int, int], or None, default=None) – Timeout for the HTTPAdapter. Can also be a 2-tuple of (connect timeout, read timeout) to set them separately.

  • web_url (str or None, default=None) – URL for the LangSmith web app. Default is auto-inferred from the ENDPOINT.

  • session (requests.Session or None, default=None) – The session to use for requests. If None, a new session will be created.

  • anonymizer (Optional[Callable[[dict], dict]]) – A function applied for masking serialized run inputs and outputs, before sending to the API.

  • hide_inputs (Whether to hide run inputs when tracing with this client.) – If True, hides the entire inputs. If a function, applied to all run inputs when creating runs.

  • hide_outputs (Whether to hide run outputs when tracing with this client.) – If True, hides the entire outputs. If a function, applied to all run outputs when creating runs.

  • info (Optional[ls_schemas.LangSmithInfo]) – The information about the LangSmith API. If not provided, it will be fetched from the API.

  • api_urls (Optional[Dict[str, str]]) – A dictionary of write API URLs and their corresponding API keys. Useful for multi-tenant setups. Data is only read from the first URL in the dictionary. However, ONLY Runs are written (POST and PATCH) to all URLs in the dictionary. Feedback, sessions, datasets, examples, annotation queues and evaluation results are only written to the first.

  • Raises

  • ------

  • LangSmithUserError – If the API key is not provided when using the hosted service. If both api_url and api_urls are provided.

  • auto_batch_tracing (bool) –