n8n-io/n8n · error · Error

LangSmith sessions lookup failed: ${res.status} ${await res.

Error message

LangSmith sessions lookup failed: ${res.status} ${await res.text()}

What it means

Thrown by resolveTraceProjectId() (build-cost-report.ts:129) when the LangSmith /api/v1/sessions lookup returns a non-OK HTTP status. The response status and body are included in the message to aid diagnosis. The request has built-in 429/5xx backoff (lsFetch, up to 6 attempts honoring Retry-After), so this error means the status is a hard failure (4xx other than 429, or a 5xx that exhausted retries). The project name is URL-encoded into the query.

Source

Thrown at packages/@n8n/instance-ai/evaluations/cli/build-cost-report.ts:129

	return {
		apiUrl,
		headers: {
			'x-api-key': apiKey,
			'Content-Type': 'application/json',
			...(workspaceId ? { 'X-Tenant-Id': workspaceId } : {}),
		},
	};
}

async function resolveTraceProjectId(ls: LangSmithConfig, projectName: string): Promise<string> {
	const res = await lsFetch(
		`${ls.apiUrl}/api/v1/sessions?name=${encodeURIComponent(projectName)}`,
		{
			headers: ls.headers,
		},
	);
	if (!res.ok) {
		throw new Error(`LangSmith sessions lookup failed: ${res.status} ${await res.text()}`);
	}
	const projects = z.array(lsProjectSchema).parse(await res.json());
	const match = projects.find((p) => p.name === projectName);
	if (!match) {
		throw new Error(
			`Trace project "${projectName}" not found in the eval workspace — is this the right tenant/workspace?`,
		);
	}
	return match.id;
}

interface ThreadCost {
	costUsd: number;
	tokens: number;
	/** Root runs in the thread — one per build turn. */
	turns: number;
}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Check the HTTP status in the message: 401/403 means the API key is wrong/expired — regenerate it.
  2. Verify LANGSMITH_ENDPOINT matches your LangSmith tenant/region.
  3. For 5xx, retry the command (the built-in backoff may have been insufficient); check the LangSmith status page.
  4. For 404, confirm the API base URL is correct (it should end without a trailing path mismatch).
  5. Ensure network egress from your CI/runner can reach the LangSmith API host.

Example fix

// before (LANGSMITH_ENDPOINT wrong)
LANGSMITH_ENDPOINT=https://api.langsmith.com ... pnpm tsx evaluations/cli/build-cost-report.ts --probe-thread abc123
// after
LANGSMITH_ENDPOINT=https://api.smith.langchain.com LANGSMITH_API_KEY=lsv2_pt_... pnpm tsx evaluations/cli/build-cost-report.ts --probe-thread abc123
Defensive patterns

Strategy: try-catch

Validate before calling

// Connectivity pre-check before the full report:
async function checkLangsmithAccess(apiUrl: string, headers: Record<string,string>): Promise<void> {
  const res = await fetch(`${apiUrl}/api/v1/sessions?limit=1`, { headers });
  if (!res.ok) throw new Error(`LangSmith unreachable: ${res.status}`);
}

Try / catch

try {
  const projectId = await resolveTraceProjectId(ls, traceProject);
} catch (error) {
  const msg = error instanceof Error ? error.message : String(error);
  if (msg.includes('sessions lookup failed')) {
    console.error('LangSmith auth/endpoint issue — verify LANGSMITH_API_KEY and LANGSMITH_ENDPOINT:', msg);
    process.exit(2);
  }
  throw error;
}

Prevention

When it happens

Trigger: Any arm or --probe-thread invocation triggers a sessions lookup for the trace project (default 'instance-ai-evals', overridable via --trace-project). A 401/403 (bad/missing API key), 404 (wrong endpoint), or persistent 5xx trips this. The lsFetch helper retries 429 and 5xx up to 6 times, so a steady 4xx surfaces immediately.

Common situations: Wrong or expired LANGSMITH_API_KEY (401/403), LANGSMITH_ENDPOINT pointing at the wrong tenant/region, a transient LangSmith outage that exhausted the 6 backoff attempts, or network/egress restrictions in CI blocking the API host.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/ae7eb32163f86dba. Report an issue: GitHub.