mem0ai/mem0 · error · Error

LiteLLM failed: ${message}

Error message

LiteLLM failed: ${message}

What it means

Thrown by LiteLLM (an OpenAILLM subclass pointed at a LiteLLM proxy server) when generateResponse fails against the LiteLLM gateway. LiteLLM proxies forward requests to upstream providers, so the suffix after 'LiteLLM failed:' can be a LiteLLM router error (no deployments, fallback failure, bad model key) or a passthrough of the upstream provider's error.

Source

Thrown at mem0-ts/src/oss/src/llms/litellm.ts:27

      apiKey: config.apiKey || process.env.LITELLM_API_KEY || "sk-anything",
      baseURL:
        config.baseURL ||
        process.env.LITELLM_API_BASE ||
        "http://localhost:4000",
      model: config.model || "gpt-5-mini",
    });
  }

  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(`LiteLLM 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(`LiteLLM failed: ${message}`);
    }
  }
}

View on GitHub (pinned to 001c235229)

Solutions

  1. Read the suffix: 'No deployments available' / 'model not in model_list' → fix the LiteLLM config; 401 → fix the key sent as apiKey; connection refused → proxy not running.
  2. Verify the proxy independently: curl $LITELLM_BASE_URL/v1/models with the master/virtual key and confirm your model string appears.
  3. Match model names exactly: LiteLLM routes on model_name (alias), not the upstream provider id.
  4. Check the LiteLLM server logs — the router prints the upstream failure that produced the surfaced error.
  5. For budget/TPM limits on virtual keys, raise them in the LiteLLM UI/config.

Example fix

// before
const mem = new Memory({
  llm: { provider: 'litellm', config: { model: 'gpt-4o', apiKey: 'sk-123', baseURL: 'http://localhost:4000' } },
});
await mem.add('hi', { userId: 'u1' }); // LiteLLM failed: 401 Unauthorized

// after (model alias that exists on the proxy + correct master key)
const mem = new Memory({
  llm: {
    provider: 'litellm',
    config: {
      model: 'team-gpt4o',        // alias defined in LiteLLM config.yaml model_list
      apiKey: process.env.LITELLM_MASTER_KEY,
      baseURL: 'http://localhost:4000',
    },
  },
});
Defensive patterns

Strategy: fallback

Validate before calling

async function litellmReady(base: string, key: string, model: string) {
  const r = await fetch(`${base}/v1/models`, { headers: { Authorization: `Bearer ${key}` } });
  if (!r.ok) throw new Error(`LiteLLM proxy ${r.status}`);
  const { data } = await r.json();
  if (!data.some((m: { id: string }) => m.id === model)) throw new Error(`model '${model}' not in LiteLLM model_list`);
}

Type guard

const isLiteLLMWrapperError = (e: unknown): e is Error => e instanceof Error && e.message.startsWith('LiteLLM failed:');

Try / catch

try {
  return await litellmLlm.generateResponse(messages, responseFormat);
} catch (err) {
  const msg = String(err);
  if (/401|not in model_list|No deployments/.test(msg)) throw new GatewayConfigError(msg);
  if (/ECONN|timeout|429|5\d\d/.test(msg)) return retryOrFallback(fn);
  throw err;
}

Prevention

When it happens

Trigger: Calling generateResponse() when: the LiteLLM proxy baseURL is wrong or unreachable, the model name is not a valid key in the LiteLLM config's model_list, the proxy returns 401 (missing LITELLM_MASTER_KEY), all deployments for a model are rate-limited/cooldown, or the upstream provider (OpenAI, Azure, Anthropic...) behind LiteLLM returned an error that LiteLLM passes through.

Common situations: Self-hosting LiteLLM and forgetting to add a model to config.yaml; using the deployment alias instead of the model_name; proxy auth header mismatch (master key vs virtual key budgets); upstream provider keys expired so LiteLLM returns 'No deployments available'; local proxy at localhost:4000 not running when the app starts.

Related errors


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