LangSmith Fetch

raw JSON →
0.3.1 verified Fri May 01 auth: no python

Minimal CLI and library for fetching LangSmith threads and traces. Version 0.3.1, regular releases on PyPI.

pip install langsmith-fetch
error ModuleNotFoundError: No module named 'langsmith_fetch'
cause Package not installed or installed under different name.
fix
Install with pip install langsmith-fetch and import with from langsmith_fetch import ....
error langsmith_fetch.exceptions.AuthenticationError: Invalid API key
cause Missing or incorrect LangSmith API key.
fix
Set the LANGSMITH_API_KEY environment variable or pass api_key parameter.
error TypeError: fetch_thread() missing 1 required positional argument: 'api_key'
cause API key not provided.
fix
Add api_key=os.environ.get('LANGSMITH_API_KEY') to the function call.
error AttributeError: 'Trace' object has no attribute 'items'
cause Assuming returned object is a dict in version >=0.3.0.
fix
Access attributes directly, e.g., trace.id, trace.runs.
gotcha The CLI and Python API have different parameter names. Use `--api-key` for CLI, `api_key` for Python.
fix Be consistent with casing and dashes depending on usage.
deprecated Python 3.9 support dropped in 0.3.0, requires Python >=3.10.
fix Use Python 3.10 or newer.
gotcha API key must be passed explicitly; reading from environment is not automatic.
fix Always provide `api_key` parameter or use `--api-key` flag in CLI.
breaking In version 0.3.0, the return format of `fetch_trace` changed from dict to custom Trace object.
fix Access attributes directly instead of dict keys, e.g., `trace.id` instead of `trace['id']`.

Fetch a LangSmith thread by ID using environment variable for API key.

import os
from langsmith_fetch import fetch_thread

api_key = os.environ.get('LANGSMITH_API_KEY', '')
result = fetch_thread('thread_id_here', api_key=api_key)
print(result)