{"record":{"id":"b2a4006a641049b4","repo":"mem0ai/mem0","slug":"litellm-failed-message","errorCode":null,"errorMessage":"LiteLLM failed: ${message}","messagePattern":"LiteLLM failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/litellm.ts","lineNumber":27,"sourceCode":"      apiKey: config.apiKey || process.env.LITELLM_API_KEY || \"sk-anything\",\n      baseURL:\n        config.baseURL ||\n        process.env.LITELLM_API_BASE ||\n        \"http://localhost:4000\",\n      model: config.model || \"gpt-5-mini\",\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(`LiteLLM 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(`LiteLLM failed: ${message}`);\n    }\n  }\n}\n","sourceCodeStart":9,"sourceCodeEnd":40,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/litellm.ts#L9-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Verify the proxy independently: curl $LITELLM_BASE_URL/v1/models with the master/virtual key and confirm your model string appears.","Match model names exactly: LiteLLM routes on model_name (alias), not the upstream provider id.","Check the LiteLLM server logs — the router prints the upstream failure that produced the surfaced error.","For budget/TPM limits on virtual keys, raise them in the LiteLLM UI/config."],"exampleFix":"// before\nconst mem = new Memory({\n  llm: { provider: 'litellm', config: { model: 'gpt-4o', apiKey: 'sk-123', baseURL: 'http://localhost:4000' } },\n});\nawait mem.add('hi', { userId: 'u1' }); // LiteLLM failed: 401 Unauthorized\n\n// after (model alias that exists on the proxy + correct master key)\nconst mem = new Memory({\n  llm: {\n    provider: 'litellm',\n    config: {\n      model: 'team-gpt4o',        // alias defined in LiteLLM config.yaml model_list\n      apiKey: process.env.LITELLM_MASTER_KEY,\n      baseURL: 'http://localhost:4000',\n    },\n  },\n});","handlingStrategy":"fallback","validationCode":"async function litellmReady(base: string, key: string, model: string) {\n  const r = await fetch(`${base}/v1/models`, { headers: { Authorization: `Bearer ${key}` } });\n  if (!r.ok) throw new Error(`LiteLLM proxy ${r.status}`);\n  const { data } = await r.json();\n  if (!data.some((m: { id: string }) => m.id === model)) throw new Error(`model '${model}' not in LiteLLM model_list`);\n}","typeGuard":"const isLiteLLMWrapperError = (e: unknown): e is Error => e instanceof Error && e.message.startsWith('LiteLLM failed:');","tryCatchPattern":"try {\n  return await litellmLlm.generateResponse(messages, responseFormat);\n} catch (err) {\n  const msg = String(err);\n  if (/401|not in model_list|No deployments/.test(msg)) throw new GatewayConfigError(msg);\n  if (/ECONN|timeout|429|5\\d\\d/.test(msg)) return retryOrFallback(fn);\n  throw err;\n}","preventionTips":["Gate the app on a LiteLLM /health/liveliness check at startup.","Validate that your model alias appears in GET /v1/models before first use.","Configure LiteLLM fallbacks so upstream failures degrade instead of surfacing here.","Keep proxy config.yaml and app config in the same deploy unit."],"tags":["litellm","proxy","llm","network","config","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}