Back to snippets
langsmith_client_init_and_manual_run_tracing.py
pythonThis quickstart demonstrates how to initialize the LangSmith client an
Agent Votes
1
0
100% positive
langsmith_client_init_and_manual_run_tracing.py
1import os
2from langsmith import Client
3
4# 1. Configure your environment
5# Note: You can also set these as environment variables in your shell
6os.environ["LANGCHAIN_TRACING_V2"] = "true"
7os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
8os.environ["LANGCHAIN_API_KEY"] = "ls__your_api_key_here"
9
10# 2. Initialize the LangSmith Client
11client = Client()
12
13# 3. Create a simple run (example of manual logging)
14# In most cases, this happens automatically when using LangChain objects,
15# but the SDK allows for direct logging.
16project_name = "Quickstart Project"
17
18run = client.create_run(
19 name="My First Run",
20 run_type="chain",
21 inputs={"input": "Hello, LangSmith!"},
22 project_name=project_name,
23)
24
25# 4. Update the run with an output
26client.update_run(
27 run.id,
28 outputs={"output": "Welcome to the platform!"},
29)
30
31print(f"Run logged to project: {project_name}")