tessl install tessl/npm-langsmith@0.4.3TypeScript client SDK for the LangSmith LLM tracing, evaluation, and monitoring platform.
Complete API documentation for programmatic access to LangSmith.
The LangSmith API provides comprehensive programmatic access to all platform features. This section documents the Client class, type definitions, and all available methods.
Quick reference for choosing between similar methods.
| Method | Signature | Use When | Best For |
|---|---|---|---|
createExample() | (example: ExampleCreate) | Single example creation | Individual examples, source run conversion |
createExamples() (arrays) | ({ inputs: [], outputs: [] }) | Bulk with uniform structure | CSV import, parallel arrays, simple bulk data |
createExamples() (objects) | ({ examples: [{...}] }) | Bulk with per-item config | Varied metadata, explicit per-example settings |
createLLMExample() | (input: string, output: string, options) | Text completion datasets | LLM-format data, simple text in/out |
createChatExample() | (messages: [], response: [], options) | Chat conversation datasets | Multi-turn chats, message arrays |
uploadExamplesMultipart() | ({ examples with attachments }) | Large or binary data | Images, files, attachments |
See Examples API for detailed documentation.
| Method | Returns | Iteration | Best For | Performance |
|---|---|---|---|---|
listRuns() | AsyncIterable<Run> | Stream | Large result sets, real-time processing | Memory efficient, no size limit |
listProjects() | Promise<TracerSession[]> | Array | Small result sets, all-at-once | Fast, full array in memory |
listDatasets() | AsyncIterable<Dataset> | Stream | Many datasets | Memory efficient |
listExamples() | AsyncIterable<Example> | Stream | Large datasets | Memory efficient |
listFeedback() | AsyncIterable<Feedback> | Stream | Many feedback items | Memory efficient |
listGroupRuns() | AsyncIterable<Thread> | Stream | Grouped analytics by conversation/user | Aggregated stats, efficient |
getRunStats() | Promise<RunStats> | N/A | Aggregate metrics only (no individual runs) | Fastest, minimal data transfer |
Key Principle: Use AsyncIterable methods for large result sets (stream processing), Promise<array> methods for small sets.
| Approach | Control Level | Complexity | Setup | Use When |
|---|---|---|---|---|
traceable() | Low (automatic) | Simple | 1 line | Automatic function tracing |
RunTree | High (manual) | Complex | Multiple calls | Fine-grained control, distributed tracing |
wrapOpenAI() | Medium | Simple | 1 line | OpenAI SDK integration |
wrapAnthropic() | Medium | Simple | 1 line | Anthropic SDK integration |
wrapAISDK() | Medium | Medium | Config required | Vercel AI SDK integration |
wrapSDK() | Low-Medium | Simple | 1 line | Generic SDK, custom APIs |
getLangchainCallbacks() | Medium | Simple | Pass callbacks | LangChain integration |
Decision Flow:
wrapOpenAI, etc.)traceable()RunTreewrapSDK()| Method | Granularity | Response Type | Use Case |
|---|---|---|---|
readRun(runId) | Single run | Promise<Run> | Fetch specific run by ID |
listRuns({ projectName }) | Multiple runs | AsyncIterable<Run> | All runs in project, with filtering |
listRuns({ traceId }) | All runs in trace | AsyncIterable<Run> | All runs in a trace tree |
listRuns({ parentRunId }) | Children of run | AsyncIterable<Run> | All child runs of a parent |
listRuns({ isRoot: true }) | Root runs only | AsyncIterable<Run> | Top-level runs without parents |
listGroupRuns({ groupBy }) | Grouped runs | AsyncIterable<Thread> | Analytics by conversation/session |
getRunStats({ projectName }) | Aggregates only | Promise<Stats> | Summary statistics without individual runs |
See Runs API for detailed filtering options.
| Method | Auth Required | Use When | Security |
|---|---|---|---|
createFeedback() | API key | Direct server-side access | Secure (API key required) |
createPresignedFeedbackToken() | API key (creation only) | Public feedback collection | Token-based, time-limited |
logEvaluationFeedback() | API key | From evaluator functions | Secure |
evaluateRun() | API key | Single-run evaluation | Secure |
Presigned tokens enable feedback collection without exposing API key - ideal for frontend/mobile apps.
| Operation | Method | Use Case |
|---|---|---|
| Auto-version | Add/modify examples | Automatic versioning on changes |
| Tag version | updateDatasetTag({ tag, asOf }) | Label specific versions (v1, v2, prod) |
| Read version | readDatasetVersion({ asOf }) | Access historical snapshot |
| Compare versions | diffDatasetVersions({ from, to }) | See what changed between versions |
| List splits | listDatasetSplits() | View train/test/validation splits |
| Level | Method | Granularity | Flexibility |
|---|---|---|---|
| Client-wide | new Client({ hideInputs: true }) | All traces | Boolean only |
| Client-wide selective | new Client({ hideInputs: fn }) | All traces | Function transform |
| Client-wide patterns | new Client({ anonymizer }) | All traces | Regex/processor rules |
| Per-function | traceable(fn, { processInputs }) | Specific function | Function transform |
| Per-field | Anonymizer with paths | Specific fields | Path-based rules |
Recommendation: Use anonymizer for pattern-based PII, hideInputs/Outputs for structural filtering.
// Create, read, update, delete, list projects
createProject(params) β TracerSession
readProject(params) β TracerSession
updateProject(projectId, params) β TracerSession
deleteProject(params) β void
listProjects(params?) β AsyncIterable<TracerSession>
hasProject(params) β boolean
getProjectUrl(params) β string// Create, read, update, list, share runs
createRun(run) β void
updateRun(runId, update) β void
readRun(runId) β Run
listRuns(params) β AsyncIterable<Run>
shareRun(runId) β string
getRunUrl(params) β string
getRunStats(params) β RunStats// Create, read, update, delete, list, share datasets
createDataset(params) β Dataset
readDataset(params) β Dataset
updateDataset(params) β Dataset
deleteDataset(params) β void
listDatasets(params?) β AsyncIterable<Dataset>
shareDataset(datasetId) β string
indexDataset(params) β void
similarExamples(params) β Example[]// Create, read, update, delete examples
createExample(example) β Example
createExamples(params) β void
updateExample(params) β Example
updateExamples(examples) β void
listExamples(params) β AsyncIterable<Example>
deleteExample(exampleId) β void// Create, read, update, delete, list feedback
createFeedback(feedback) β Feedback
updateFeedback(feedbackId, update) β void
readFeedback(feedbackId) β Feedback
listFeedback(params) β AsyncIterable<Feedback>
deleteFeedback(feedbackId) β void
createPresignedFeedbackToken(params) β FeedbackIngestToken// Create, pull, push, list prompts
createPrompt(name, params?) β Prompt
pullPrompt(name, params?) β PromptCommit
pushPrompt(name, params) β string
listPrompts(params?) β AsyncIterable<Prompt>
deletePrompt(name) β void
likePrompt(name) β void
unlikePrompt(name) β voidimport { Client } from "langsmith";
// Default configuration
const client = new Client();
// Custom configuration
const client = new Client({
apiKey: process.env.LANGSMITH_API_KEY,
timeout_ms: 10000,
autoBatchTracing: true,
});// Iterate through all results
for await (const run of client.listRuns({ projectName: "my-project" })) {
console.log(run.name);
}
// With filtering
for await (const dataset of client.listDatasets({ datasetName: "test" })) {
console.log(dataset.name);
}try {
const run = await client.readRun(runId);
} catch (error) {
if (error.status === 404) {
console.error("Run not found");
} else if (error.status === 401) {
console.error("Authentication failed");
} else {
console.error("API error:", error.message);
}
}All API methods are fully typed. Import types from langsmith/schemas:
import type {
Run,
RunCreate,
Dataset,
Example,
Feedback,
TracerSession,
} from "langsmith/schemas";See Schemas for complete type reference.
const client = new Client({
apiKey: process.env.LANGSMITH_API_KEY,
autoBatchTracing: true,
tracingSamplingRate: 0.1, // 10% sampling
hideInputs: (inputs) => redactPII(inputs),
blockOnRootRunFinalization: false,
});const client = new Client({
apiKey: process.env.LANGSMITH_API_KEY,
debug: true, // Log all requests
blockOnRootRunFinalization: true, // Ensure traces complete
});const client = new Client({
apiKey: process.env.LANGSMITH_API_KEY,
autoBatchTracing: true,
batchSizeLimit: 10, // Lower batch size for serverless
});
// Always flush before function ends
await client.awaitPendingTraceBatches();