Skip to main content
The LangSmith SDK is available as a Python package on PyPI and as a TypeScript/JavaScript package on npm.

Prerequisites

Before installing the SDK, you’ll need:
  1. A LangSmith account - sign up here
  2. A LangSmith API key from your Settings page
Save your API key in a secure location. It will not be shown again after creation.

Python installation

1

Install the package

Install the LangSmith SDK using pip:
pip install -U langsmith
The SDK requires Python 3.10 or higher.
2

Set environment variables

Configure your environment with your LangSmith credentials:
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=ls_...
# Optional: specify a project name (defaults to "default")
export LANGSMITH_PROJECT=my-project
# Required for organization-scoped API keys
export LANGSMITH_WORKSPACE_ID=<your-workspace-id>
Add these to your .bashrc, .zshrc, or .env file to persist across sessions.
3

Verify installation

Test that everything is working:
from langsmith import Client

client = Client()
print("LangSmith SDK installed successfully!")
print(f"Connected to: {client.api_url}")

Python optional dependencies

The SDK supports optional features that require additional packages:
# OpenTelemetry integration
pip install langsmith[otel]

# Pytest integration
pip install langsmith[pytest]

# VCR (record/replay HTTP interactions)
pip install langsmith[vcr]

# Sandbox execution environment
pip install langsmith[sandbox]

# OpenAI Agents SDK support
pip install langsmith[openai-agents]

# Anthropic Claude Agent SDK support
pip install langsmith[claude-agent-sdk]

# Google ADK support
pip install langsmith[google-adk]

TypeScript installation

1

Install the package

Install the LangSmith SDK using your preferred package manager:
npm install langsmith
The SDK works with Node.js, Deno, and modern browsers.
2

Set environment variables

Configure your environment with your LangSmith credentials:
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=ls_...
# Optional: specify a project name (defaults to "default")
export LANGSMITH_PROJECT=my-project
# Required for organization-scoped API keys
export LANGSMITH_WORKSPACE_ID=<your-workspace-id>
For EU region users:
export LANGSMITH_ENDPOINT=https://eu.api.smith.langchain.com
3

Verify installation

Test that everything is working:
import { Client } from "langsmith";

const client = new Client();
console.log("LangSmith SDK installed successfully!");
console.log(`Connected to: ${client.apiUrl}`);

TypeScript peer dependencies

Some features require peer dependencies:
# For OpenAI wrapper
npm install openai

# For OpenTelemetry integration
npm install @opentelemetry/api @opentelemetry/sdk-trace-base

Configuration options

You can configure the SDK using environment variables or constructor options.

Environment variables

LANGSMITH_TRACING
boolean
default:"false"
Enable or disable tracing globally
LANGSMITH_API_KEY
string
required
Your LangSmith API key (starts with ls_)
LANGSMITH_PROJECT
string
default:"default"
The project name where traces will be logged
LANGSMITH_ENDPOINT
string
default:"https://api.smith.langchain.com"
The LangSmith API endpoint. Use https://eu.api.smith.langchain.com for EU region.
LANGSMITH_WORKSPACE_ID
string
Your workspace ID (required for organization-scoped API keys)

Programmatic configuration

You can also configure the client programmatically:
from langsmith import Client

client = Client(
    api_key="ls_...",
    api_url="https://api.smith.langchain.com",
    project_name="my-project"
)

Region support

LangSmith is available in multiple regions:
export LANGSMITH_ENDPOINT=https://api.smith.langchain.com
This is the default endpoint and does not need to be set explicitly.

Troubleshooting

If you see import errors, make sure you’ve installed the package and are using the correct Python version (3.10+):
python --version  # Should be 3.10 or higher
pip list | grep langsmith
If you see “Unauthorized” errors:
  1. Verify your API key starts with ls_
  2. Check that LANGSMITH_API_KEY is set: echo $LANGSMITH_API_KEY
  3. If using an org-scoped key, ensure LANGSMITH_WORKSPACE_ID is set
  4. Verify your key hasn’t been revoked in the Settings page
If traces aren’t showing up:
  1. Check that LANGSMITH_TRACING=true is set
  2. Verify the project name: echo $LANGSMITH_PROJECT
  3. Look for error messages in your application logs
  4. Check the browser console or terminal for SDK errors
  5. Ensure you’re waiting for async operations to complete
If you see TypeScript errors:
  1. Ensure you’re using TypeScript 5.0 or higher
  2. Install the latest version: npm install langsmith@latest
  3. Clear your node_modules and reinstall: rm -rf node_modules package-lock.json && npm install

Next steps

Quickstart

Get your first trace in 5 minutes

Tracing concepts

Learn how tracing works

OpenAI integration

Trace OpenAI SDK calls

LangChain integration

Use with LangChain

Build docs developers (and LLMs) love