AsyncClient class provides an async interface for interacting with the LangSmith API. It uses httpx for async HTTP requests and is ideal for async applications.
Constructor
URL for the LangSmith API. Defaults to the
LANGCHAIN_ENDPOINT or LANGSMITH_ENDPOINT environment variable.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 timeouts.
Configuration for request retries. Default is
{"max_retries": 3}.URL for the LangSmith web application.
Whether to disable prompt caching for this client. Default is
False.Usage with context manager
The async client should be used as an async context manager:Core methods
acreate_run
Asynchronously create a new run 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.
Unique identifier for the run.
ID of the parent run for nested traces.
Tags for filtering and organization.
Additional metadata.
aupdate_run
Asynchronously update an existing run.ID of the run to update.
Output data from the run.
Error message if the run failed.
End time of the run.
acreate_feedback
Asynchronously create feedback for a run.ID of the run to attach feedback to.
Name of the metric.
Numeric score.
Explanation for the feedback.
Dataset methods
acreate_dataset
Asynchronously create a new dataset.Name of the dataset.
Description of the dataset.
The created dataset object.
acreate_example
Asynchronously add an example to a dataset.Input data for the example.
Expected output data.
ID of the dataset.
The created example object.
alist_datasets
Asynchronously list all datasets.Async iterator of dataset objects.
Prompt methods
apull_prompt
Asynchronously pull a prompt from the hub.Prompt identifier in format
"name", "owner/name", or with commit hash.Whether to include model configuration.
The prompt object.
apush_prompt
Asynchronously push a prompt to the hub.Name for the prompt.
The prompt object to push.
URL of the pushed prompt.