mem0ai/mem0 · error · Error

LM Studio LLM failed: ${message}

Error message

LM Studio LLM failed: ${message}

What it means

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.

Source

Thrown at mem0-ts/src/oss/src/llms/lmstudio.ts:29

  constructor(config: LLMConfig) {
    super({
      ...config,
      apiKey: config.apiKey || DEFAULT_LMSTUDIO_API_KEY,
      baseURL: config.baseURL ?? DEFAULT_BASE_URL,
      model: config.model || DEFAULT_MODEL,
    });
  }

  async generateResponse(
    messages: Message[],
    responseFormat?: { type: string },
    tools?: any[],
  ): Promise<string | LLMResponse> {
    try {
      return await super.generateResponse(messages, responseFormat, tools);
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`LM Studio LLM failed: ${message}`);
    }
  }

  async generateChat(messages: Message[]): Promise<LLMResponse> {
    try {
      return await super.generateChat(messages);
    } catch (err) {
      const message = err instanceof Error ? err.message : String(err);
      throw new Error(`LM Studio LLM failed: ${message}`);
    }
  }
}

View on GitHub (pinned to 001c235229)

Solutions

  1. Ensure LM Studio's server is running: `lms server start` or the Developer tab → Start Server, default port 1234.
  2. 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.
  3. Align baseURL with the actual port if you changed it (config.baseURL = 'http://localhost:1234/v1').
  4. If using responseFormat, verify the loaded model supports JSON mode/grammars in LM Studio.
  5. For context-overflow errors, load a model variant with a larger context or trim the message payload.

Example fix

// before
const mem = new Memory({ llm: { provider: 'lmstudio', config: { model: 'qwen2.5-7b' } } });
await mem.add('hi', { userId: 'u1' });
// LM Studio LLM failed: fetch failed (server not started)

// after (start server, use exact model id from `lms ls`, pin baseURL)
const mem = new Memory({
  llm: {
    provider: 'lmstudio',
    config: {
      model: 'qwen2.5-7b-instruct',
      baseURL: 'http://localhost:1234/v1',
    },
  },
});
Defensive patterns

Strategy: validation

Validate before calling

async function lmStudioReady(base = 'http://localhost:1234/v1', model: string) {
  const r = await fetch(`${base}/models`);
  if (!r.ok) throw new Error('LM Studio server not reachable — run `lms server start`');
  const { data } = await r.json();
  if (!data.some((m: { id: string }) => m.id === model)) throw new Error(`model '${model}' not loaded in LM Studio`);
}

Type guard

const isLMStudioDown = (e: unknown): boolean =>
  e instanceof Error && e.message.startsWith('LM Studio LLM failed:') && /fetch failed|ECONN/i.test(e.message);

Try / catch

try {
  return await lmStudioLlm.generateResponse(messages, responseFormat);
} catch (err) {
  if (isLMStudioDown(err)) throw new Error('Start LM Studio server (lms server start) and retry');
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/0f6913939ef500d2. Report an issue: GitHub.