{"record":{"id":"0f6913939ef500d2","repo":"mem0ai/mem0","slug":"lm-studio-llm-failed-message","errorCode":null,"errorMessage":"LM Studio LLM failed: ${message}","messagePattern":"LM Studio LLM failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/lmstudio.ts","lineNumber":29,"sourceCode":"  constructor(config: LLMConfig) {\n    super({\n      ...config,\n      apiKey: config.apiKey || DEFAULT_LMSTUDIO_API_KEY,\n      baseURL: config.baseURL ?? DEFAULT_BASE_URL,\n      model: config.model || DEFAULT_MODEL,\n    });\n  }\n\n  async generateResponse(\n    messages: Message[],\n    responseFormat?: { type: string },\n    tools?: any[],\n  ): Promise<string | LLMResponse> {\n    try {\n      return await super.generateResponse(messages, responseFormat, tools);\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`LM Studio LLM failed: ${message}`);\n    }\n  }\n\n  async generateChat(messages: Message[]): Promise<LLMResponse> {\n    try {\n      return await super.generateChat(messages);\n    } catch (err) {\n      const message = err instanceof Error ? err.message : String(err);\n      throw new Error(`LM Studio LLM failed: ${message}`);\n    }\n  }\n}\n","sourceCodeStart":11,"sourceCodeEnd":42,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/lmstudio.ts#L11-L42","documentation":"Thrown by LMStudioLLM.generateResponse when the request to a local LM Studio server (OpenAI-compatible API) fails. LMStudioLLM extends OpenAILLM with a localhost base URL, so the suffix after 'LM Studio LLM failed:' is typically a fetch/ECONNREFUSED error, a 404 from a wrong endpoint, or an LM Studio application error.","triggerScenarios":"Calling generateResponse() when LM Studio's local server is not running (default http://localhost:1234/v1), the configured baseURL/port is wrong, no model is loaded in LM Studio ('model not found' / 'no model loaded'), the loaded model does not support the requested responseFormat, or the request body exceeds the local context window.","commonSituations":"Forgetting to click 'Start Server' (or `lms server start`) in LM Studio; server bound to a different port; model unloaded after an app update or GUI restart; passing responseFormat json_schema to a model without JSON/grammar support; large memory-add payloads overflowing a small local context.","solutions":["Ensure LM Studio's server is running: `lms server start` or the Developer tab → Start Server, default port 1234.","Confirm the model is loaded and note its exact identifier via `lms ls` or GET http://localhost:1234/v1/models; use that string as config.model.","Align baseURL with the actual port if you changed it (config.baseURL = 'http://localhost:1234/v1').","If using responseFormat, verify the loaded model supports JSON mode/grammars in LM Studio.","For context-overflow errors, load a model variant with a larger context or trim the message payload."],"exampleFix":"// before\nconst mem = new Memory({ llm: { provider: 'lmstudio', config: { model: 'qwen2.5-7b' } } });\nawait mem.add('hi', { userId: 'u1' });\n// LM Studio LLM failed: fetch failed (server not started)\n\n// after (start server, use exact model id from `lms ls`, pin baseURL)\nconst mem = new Memory({\n  llm: {\n    provider: 'lmstudio',\n    config: {\n      model: 'qwen2.5-7b-instruct',\n      baseURL: 'http://localhost:1234/v1',\n    },\n  },\n});","handlingStrategy":"validation","validationCode":"async function lmStudioReady(base = 'http://localhost:1234/v1', model: string) {\n  const r = await fetch(`${base}/models`);\n  if (!r.ok) throw new Error('LM Studio server not reachable — run `lms server start`');\n  const { data } = await r.json();\n  if (!data.some((m: { id: string }) => m.id === model)) throw new Error(`model '${model}' not loaded in LM Studio`);\n}","typeGuard":"const isLMStudioDown = (e: unknown): boolean =>\n  e instanceof Error && e.message.startsWith('LM Studio LLM failed:') && /fetch failed|ECONN/i.test(e.message);","tryCatchPattern":"try {\n  return await lmStudioLlm.generateResponse(messages, responseFormat);\n} catch (err) {\n  if (isLMStudioDown(err)) throw new Error('Start LM Studio server (lms server start) and retry');\n  throw err;\n}","preventionTips":["Start the server with `lms server start` as part of your dev script.","Always pin config.model to the identifier from GET /v1/models.","Check the loaded model supports JSON mode before using responseFormat."],"tags":["lmstudio","local","llm","network","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}