{"record":{"id":"288759c5ff5f3d38","repo":"ruvnet/ruflo","slug":"failed-to-import-openai","errorCode":null,"errorMessage":"Failed to import OpenAI","messagePattern":"Failed to import OpenAI","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ruflo/src/ruvocal/src/lib/server/endpoints/openai/endpointOai.ts","lineNumber":73,"sourceCode":"): Promise<Endpoint> {\n\tconst {\n\t\tbaseURL,\n\t\tapiKey,\n\t\tcompletion,\n\t\tmodel,\n\t\tdefaultHeaders,\n\t\tdefaultQuery,\n\t\tmultimodal,\n\t\textraBody,\n\t\tuseCompletionTokens,\n\t\tstreamingSupported,\n\t} = endpointOAIParametersSchema.parse(input);\n\n\tlet OpenAI;\n\ttry {\n\t\tOpenAI = (await import(\"openai\")).OpenAI;\n\t} catch (e) {\n\t\tthrow new Error(\"Failed to import OpenAI\", { cause: e });\n\t}\n\n\t// Store router metadata if captured\n\tlet routerMetadata: { route?: string; model?: string; provider?: string } = {};\n\n\t// Custom fetch wrapper to capture response headers for router metadata\n\tconst customFetch = async (url: RequestInfo, init?: RequestInit): Promise<Response> => {\n\t\tconst response = await fetch(url, init);\n\n\t\t// Capture router headers if present (fallback for non-streaming)\n\t\tconst routeHeader = response.headers.get(\"X-Router-Route\");\n\t\tconst modelHeader = response.headers.get(\"X-Router-Model\");\n\t\tconst providerHeader = response.headers.get(\"x-inference-provider\");\n\n\t\tif (routeHeader && modelHeader) {\n\t\t\trouterMetadata = {\n\t\t\t\troute: routeHeader,\n\t\t\t\tmodel: modelHeader,","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/ruflo/src/ruvocal/src/lib/server/endpoints/openai/endpointOai.ts#L55-L91","documentation":"Thrown when the dynamic import('openai') inside endpointOai fails (the catch wraps the underlying error as the cause). The OpenAI SDK is loaded lazily so that environments that never call the OpenAI endpoint do not need it installed; if the package cannot be resolved, the endpoint refuses to construct.","triggerScenarios":"The 'openai' npm package is not installed, not resolvable from the ruvocal package's node_modules, or its version throws on import (e.g. an incompatible ESM/CJS build, a broken hoist in a monorepo/pnpm setup, or a corrupt install).","commonSituations":"A fresh clone where npm install was not run; the openai dep was moved to optionalDependencies and skipped; pnpm hoisting/raycasting prevents resolution; a Node version older than the SDK's engines requirement; a bundler stripped the dynamic import target; a broken node_modules after a failed install.","solutions":["Install the SDK in the ruvocal package: npm install openai (or pnpm add openai in that workspace).","Run a clean reinstall: rm -rf node_modules package-lock.json && npm install.","Check the underlying cause — read e.cause from the thrown error for the real resolution/import failure.","Confirm the installed openai version satisfies the engines/Node version in use."],"exampleFix":"// before — openai not installed → 'Failed to import OpenAI'\n\n// after\n// in ruflo/src/ruvocal:\nnpm install openai\n// or pin: \"openai\": \"^4.20.0\" in package.json then npm install","handlingStrategy":"validation","validationCode":"// at startup, confirm the SDK resolves\ntry { await import('openai'); } catch { throw new Error('openai package not installed — run npm install openai in ruflo/src/ruvocal'); }","typeGuard":"async function isOpenAiInstalled(): Promise<boolean> { try { await import('openai'); return true; } catch { return false; } }","tryCatchPattern":"try { return await endpointOai(input); } catch (e) { if (e instanceof Error && e.message === 'Failed to import OpenAI') throw new Error('OpenAI SDK missing — install it or check e.cause', { cause: e }); throw e; }","preventionTips":["List openai in the ruvocal package's dependencies.","Read e.cause for the real resolution error.","Run a clean reinstall when the dynamic import fails in a monorepo."],"tags":["dependency","import","openai","ruvocal"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}