{"record":{"id":"afc7840b3ec28e49","repo":"headroomlabs-ai/headroom","slug":"withheadroom-requires-the-ai-package-install","errorCode":null,"errorMessage":"withHeadroom() requires the \"ai\" package. Install it with: npm install ai","messagePattern":"withHeadroom\\(\\) requires the \"ai\" package\\. Install it with: npm install ai","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"sdk/typescript/src/adapters/vercel-ai.ts","lineNumber":122,"sourceCode":" * const model = withHeadroom(openai('gpt-4o'));\n * const { text } = await generateText({ model, messages });\n * ```\n */\nexport function withHeadroom<T extends LanguageModel>(\n  model: T,\n  options: CompressOptions = {},\n): T {\n  let wrapLanguageModel: (opts: {\n    model: T;\n    middleware: any;\n  }) => T;\n\n  try {\n    const require = createRequire(import.meta.url);\n    const ai = require(\"ai\");\n    wrapLanguageModel = ai.wrapLanguageModel;\n  } catch {\n    throw new Error(\n      'withHeadroom() requires the \"ai\" package. Install it with: npm install ai',\n    );\n  }\n\n  return wrapLanguageModel({\n    model,\n    middleware: headroomMiddleware(options),\n  });\n}\n","sourceCodeStart":104,"sourceCodeEnd":132,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/sdk/typescript/src/adapters/vercel-ai.ts#L104-L132","documentation":"Error \"withHeadroom() requires the \"ai\" package. Install it with: npm install ai\" thrown in headroomlabs-ai/headroom.","triggerScenarios":"Raised when withHeadroom() is called in a project where the 'ai' (Vercel AI SDK) package is not installed.","commonSituations":"See trigger scenarios.","solutions":["Install the Vercel AI SDK: npm install ai","Ensure the 'ai' package version is compatible with the withHeadroom adapter"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}