Last modified: Jun 13, 2026

Install LangSmith in Python Guide

LangSmith is a powerful platform for debugging, testing, and monitoring LLM applications. It helps you trace every step of your AI workflow. This guide shows you how to install LangSmith in Python quickly.

You need Python 3.8 or higher. LangSmith works best with LangChain, but it can be used standalone. We will cover installation, setup, and a basic example.

Prerequisites

Before installing, ensure you have Python installed. Open your terminal or command prompt. Check your Python version with this command.


python --version

You should see Python 3.8 or newer. If not, download the latest Python from python.org. Also, make sure pip is installed. Pip is the Python package installer.


pip --version

If pip is missing, you can install it by running python -m ensurepip --upgrade. Now you are ready to install LangSmith.

Install LangSmith Using Pip

The easiest way to install LangSmith is via pip. Run this command in your terminal.


pip install langsmith

This installs the core LangSmith library. It includes the tracing client and utilities. The installation takes only a few seconds.

If you plan to use LangSmith with LangChain, install LangChain as well. This is optional but recommended for full functionality.


pip install langchain

You can also install both at once. Use the command below for a complete setup.


pip install langsmith langchain

After installation, verify it worked. Run Python and import the library.


import langsmith
print(langsmith.__version__)

If you see a version number, installation is successful. If you get an error, double-check your pip and Python versions.

Set Up Your LangSmith API Key

LangSmith requires an API key to send traces to the cloud. First, create an account at smith.langchain.com. Then generate a new API key from your settings page.

Store the API key as an environment variable. This keeps it secure. On macOS or Linux, use this command in your terminal.


export LANGCHAIN_API_KEY="your-api-key-here"

On Windows Command Prompt, use this.


set LANGCHAIN_API_KEY="your-api-key-here"

For a more permanent solution, add the variable to your .bashrc or .env file. You can also set it directly in your Python code, but that is less secure.


import os
os.environ["LANGCHAIN_API_KEY"] = "your-api-key-here"

Never share your API key publicly. Keep it in a secret manager or environment file. LangSmith uses this key to authenticate your requests.

Configure LangSmith Tracing

To start tracing, you need to set a project name. This organizes your traces. Set it as an environment variable.


export LANGCHAIN_PROJECT="my-first-project"

You can also set it in Python. Use the langsmith.Client class to create a client.


from langsmith import Client

client = Client()
print("Client created successfully")

The client automatically reads the API key and project name from environment variables. If you want to specify them directly, pass them as arguments.


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

Now you are ready to trace your first LLM call. LangSmith will capture inputs, outputs, and metadata automatically.

Example: Trace a Simple LLM Call

Let's trace a call to OpenAI. First, install the OpenAI library.


pip install openai

Then set your OpenAI API key. Now write a Python script that uses LangSmith tracing.


import os
from langsmith import traceable
from openai import OpenAI

# Set environment variables
os.environ["LANGCHAIN_API_KEY"] = "your-langsmith-key"
os.environ["LANGCHAIN_PROJECT"] = "tutorial-demo"
os.environ["OPENAI_API_KEY"] = "your-openai-key"

# Decorate the function with @traceable
@traceable
def ask_llm(prompt: str) -> str:
    client = OpenAI()
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content

# Call the function
result = ask_llm("What is the capital of France?")
print(result)

When you run this code, LangSmith automatically traces the function. It records the prompt, the response, and timing. You can see this trace in your LangSmith dashboard.

The @traceable decorator is a key feature. It wraps your function and sends trace data to the server. You can add custom metadata to traces.

View Traces in LangSmith Dashboard

Go to your LangSmith dashboard. Click on the project you created. You will see a list of runs. Each run shows the input, output, and latency.

Click on a run to see detailed traces. You can inspect every step, including token usage. This helps you debug and optimize your LLM applications.

If you don't see any traces, check your API key and project name. Also ensure your internet connection is active. The dashboard updates in real-time.

Troubleshooting Common Issues

Sometimes installation fails. Here are common problems and fixes.

Error: "No module named langsmith". This means pip did not install correctly. Run pip install --upgrade langsmith to reinstall.

Error: "Invalid API key". Double-check your API key. Make sure there are no extra spaces. Regenerate a new key if needed.

Error: "Connection refused". Your firewall might block the API. Try using a different network. Or set a proxy if required.

If you still face issues, check the LangSmith documentation. The community forum is also helpful.

Best Practices for LangSmith

Use environment variables for all secrets. Never hardcode API keys in your scripts. This prevents accidental exposure.

Organize your traces with meaningful project names. Use different projects for development, testing, and production.

Add custom tags and metadata to your traces. This makes filtering easier. For example, tag traces by user ID or model version.

Monitor your trace costs. LangSmith has a free tier, but heavy usage may incur charges. Keep an eye on your monthly usage.

Conclusion

Installing LangSmith in Python is straightforward. You just need pip and an API key. The library integrates seamlessly with LangChain and OpenAI.

We covered installation, configuration, and a practical example. Now you can trace your LLM applications with confidence. Start using LangSmith today to improve your AI workflows.

For more advanced features, explore the LangSmith documentation. Happy coding!