{"record":{"id":"ae7eb32163f86dba","repo":"n8n-io/n8n","slug":"langsmith-sessions-lookup-failed-res-status","errorCode":null,"errorMessage":"LangSmith sessions lookup failed: ${res.status} ${await res.text()}","messagePattern":"LangSmith sessions lookup failed: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/evaluations/cli/build-cost-report.ts","lineNumber":129,"sourceCode":"\treturn {\n\t\tapiUrl,\n\t\theaders: {\n\t\t\t'x-api-key': apiKey,\n\t\t\t'Content-Type': 'application/json',\n\t\t\t...(workspaceId ? { 'X-Tenant-Id': workspaceId } : {}),\n\t\t},\n\t};\n}\n\nasync function resolveTraceProjectId(ls: LangSmithConfig, projectName: string): Promise<string> {\n\tconst res = await lsFetch(\n\t\t`${ls.apiUrl}/api/v1/sessions?name=${encodeURIComponent(projectName)}`,\n\t\t{\n\t\t\theaders: ls.headers,\n\t\t},\n\t);\n\tif (!res.ok) {\n\t\tthrow new Error(`LangSmith sessions lookup failed: ${res.status} ${await res.text()}`);\n\t}\n\tconst projects = z.array(lsProjectSchema).parse(await res.json());\n\tconst match = projects.find((p) => p.name === projectName);\n\tif (!match) {\n\t\tthrow new Error(\n\t\t\t`Trace project \"${projectName}\" not found in the eval workspace — is this the right tenant/workspace?`,\n\t\t);\n\t}\n\treturn match.id;\n}\n\ninterface ThreadCost {\n\tcostUsd: number;\n\ttokens: number;\n\t/** Root runs in the thread — one per build turn. */\n\tturns: number;\n}\n","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/evaluations/cli/build-cost-report.ts#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the HTTP status in the message: 401/403 means the API key is wrong/expired — regenerate it.","Verify LANGSMITH_ENDPOINT matches your LangSmith tenant/region.","For 5xx, retry the command (the built-in backoff may have been insufficient); check the LangSmith status page.","For 404, confirm the API base URL is correct (it should end without a trailing path mismatch).","Ensure network egress from your CI/runner can reach the LangSmith API host."],"exampleFix":"// before (LANGSMITH_ENDPOINT wrong)\nLANGSMITH_ENDPOINT=https://api.langsmith.com ... pnpm tsx evaluations/cli/build-cost-report.ts --probe-thread abc123\n// after\nLANGSMITH_ENDPOINT=https://api.smith.langchain.com LANGSMITH_API_KEY=lsv2_pt_... pnpm tsx evaluations/cli/build-cost-report.ts --probe-thread abc123","handlingStrategy":"try-catch","validationCode":"// Connectivity pre-check before the full report:\nasync function checkLangsmithAccess(apiUrl: string, headers: Record<string,string>): Promise<void> {\n  const res = await fetch(`${apiUrl}/api/v1/sessions?limit=1`, { headers });\n  if (!res.ok) throw new Error(`LangSmith unreachable: ${res.status}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const projectId = await resolveTraceProjectId(ls, traceProject);\n} catch (error) {\n  const msg = error instanceof Error ? error.message : String(error);\n  if (msg.includes('sessions lookup failed')) {\n    console.error('LangSmith auth/endpoint issue — verify LANGSMITH_API_KEY and LANGSMITH_ENDPOINT:', msg);\n    process.exit(2);\n  }\n  throw error;\n}","preventionTips":["Run a --probe-thread connectivity check before a full multi-arm report.","Keep LANGSMITH_API_KEY fresh and LANGSMITH_ENDPOINT correct in CI secrets.","For transient 5xx, wrap the report invocation in a retry-on-5xx shell loop."],"tags":["network","langsmith","http","instance-ai","cost-report"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}