Client class is the primary interface for interacting with the LangSmith API. Use it to customize API keys, workspace connections, SSL certificates, and manage LangSmith resources like runs, datasets, examples, and feedback.
Constructor
URL for the LangSmith API. Defaults to the
LANGCHAIN_ENDPOINT or LANGSMITH_ENDPOINT environment variable, or https://api.smith.langchain.com if not set.API key for authentication. Defaults to the
LANGCHAIN_API_KEY or LANGSMITH_API_KEY environment variable.Timeout for requests in milliseconds. Can be a single value or a tuple of (connect, read, write, pool) timeouts.
URL for the LangSmith web application. Used for generating links to traces and datasets.
Custom requests session to use for HTTP calls.
Whether to automatically batch tracing data. Default is
True.Function to hide or redact sensitive input data before sending to LangSmith.
Function to hide or redact sensitive output data before sending to LangSmith.
Additional information about the LangSmith instance.
Core methods
create_run
Create a new run (trace span) in LangSmith.Name of the run.
Input data for the run.
Type of run:
"llm", "chain", "tool", "retriever", or "prompt".Project to log the run to. Defaults to the
LANGCHAIN_PROJECT environment variable.Unique identifier for the run. Auto-generated if not provided.
ID of the parent run for nested traces.
Start time of the run. Defaults to current time.
Tags to attach to the run for filtering and organization.
Additional metadata to attach to the run.
This method queues the run for background upload and returns immediately.
update_run
Update an existing run with outputs and end time.ID of the run to update.
Output data from the run.
Error message if the run failed.
End time of the run.
create_feedback
Create feedback (metric/score) for a run.ID of the run to attach feedback to.
Name of the metric or feedback type.
Numeric score for the feedback.
Non-numeric value for the feedback.
Explanation or context for the feedback.
Suggested correction if the output was incorrect.
Dataset methods
create_dataset
Create a new dataset for evaluation.Name of the dataset.
Description of the dataset’s purpose.
Type of data:
"kv", "llm", or "chat".The created dataset object.
create_example
Add an example (record) to a dataset.Input data for the example.
Expected output data (ground truth).
ID of the dataset to add the example to.
Additional metadata for the example.
The created example object.
list_datasets
List all datasets in your workspace.Iterator of dataset objects.
Prompt methods
pull_prompt
Pull a prompt from the LangSmith prompt hub.Prompt identifier in format
"name", "owner/name", "name:hash", or "owner/name:hash".Whether to include model configuration in the prompt.
The prompt object (typically a LangChain prompt template).
push_prompt
Push a prompt to the LangSmith prompt hub.Name or identifier for the prompt.
The prompt object to push (typically a LangChain prompt).
Whether to make the prompt publicly accessible. Default is
False.URL of the pushed prompt.