n8n-io/n8n · error · Error
LangSmith client not initialized - check LANGSMITH_API_KEY
Error message
LangSmith client not initialized - check LANGSMITH_API_KEY
What it means
Thrown when `--backend langsmith` is requested but `setupTestEnvironment(...)` did not produce an `lsClient`. The client is built from the `LANGSMITH_API_KEY` environment variable; if it is absent or empty the client is `undefined` and the run aborts before touching the LangSmith API. This is a deliberate early-validation so the failure points at credentials rather than at a downstream 'unauthorized' response.
Source
Thrown at packages/@n8n/ai-workflow-builder.ee/evaluations/cli/index.ts:485
*/
export async function runV2Evaluation(): Promise<void> {
const args = parseEvaluationArgs();
if (args.backend === 'langsmith' && (args.prompt || args.promptsCsv || args.testCase)) {
throw new Error(
'LangSmith mode requires `--dataset` and does not support `--prompt`, `--prompts-csv`, or `--test-case`',
);
}
// Setup environment with per-stage model configuration
const logger = createLogger(args.verbose);
const stageModels = argsToStageModels(args);
const env = await setupTestEnvironment(stageModels, logger);
// Validate LangSmith client early if langsmith backend is requested
if (args.backend === 'langsmith' && !env.lsClient) {
throw new Error('LangSmith client not initialized - check LANGSMITH_API_KEY');
}
// Create workflow generator based on agent type
const generateWorkflow =
args.agent === AGENT_TYPES.CODE_BUILDER
? createCodeWorkflowBuilderGenerator(
env.parsedNodeTypes,
env.llms,
args.timeoutMs,
env.nodeDefinitionDirs,
)
: createWorkflowGenerator(env.parsedNodeTypes, env.llms, args.featureFlags);
// Create evaluators based on suite type
const evaluators = createEvaluators({
suite: args.suite,
judgeLlm: env.llms.judge,
parsedNodeTypes: env.parsedNodeTypes,View on GitHub (pinned to 5ac6606e81)
Solutions
- Export the key in the same shell that runs the eval: `export LANGSMITH_API_KEY=lsv2_sk_...`.
- If using a `.env` loader, confirm it runs before `runV2Evaluation()`; otherwise prefix the command inline: `LANGSMITH_API_KEY=lsv2_sk_... pnpm eval --backend langsmith --dataset NAME`.
- In CI, add `LANGSMITH_API_KEY` to the repository/worker secret store and verify the job actually receives it (print its length, never the value).
Example fix
// before $ pnpm eval --backend langsmith --dataset my-dataset Error: LangSmith client not initialized - check LANGSMITH_API_KEY // after $ export LANGSMITH_API_KEY=lsv2_sk_... $ pnpm eval --backend langsmith --dataset my-dataset
Defensive patterns
Strategy: validation
Validate before calling
function assertLangsmithEnv(): void {
const key = process.env.LANGSMITH_API_KEY;
if (!key || key.trim() === '') {
throw new Error('LANGSMITH_API_KEY is missing or empty; set it before using --backend langsmith');
}
}
// call before runV2Evaluation when backend === 'langsmith'
if (backend === 'langsmith') assertLangsmithEnv(); Prevention
- Store the key in your team secret manager and inject it into the eval job's env explicitly.
- In CI, fail the job early if `LANGSMITH_API_KEY` is unset instead of letting it reach the CLI.
- Print `process.env.LANGSMITH_API_KEY?.length` (never the value) at job start to confirm the secret is present.
When it happens
Trigger: `args.backend === 'langsmith'` AND `env.lsClient` is falsy after environment setup. Typically `LANGSMITH_API_KEY` is unset, set to an empty string, or only exported in a different shell than the one running the eval.
Common situations: Running evals in a fresh terminal, in CI without the secret in the matrix env, after switching accounts/projects, or when the key is stored in a `.env` file that the CLI does not auto-load.
Related errors
- LangSmith mode requires `--dataset` and does not support `--
- seed.endpoint "${endpoint}" is the secondary (US) tenant but
- Dataset "${datasetName}" not found: ${errorMessage}
- --build-via-mcp requires LangSmith experiment tracking — set
- LANGSMITH_API_KEY is not set — the AIA arm needs LangSmith a
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/a184a2644cde0f5a.
Report an issue: GitHub.