mem0ai/mem0 · error · Error
Sarvam LLM failed: ${message}
Error message
Sarvam LLM failed: ${message} What it means
Thrown by SarvamLLM.generateResponse when the underlying request to Sarvam's OpenAI-compatible endpoint (default https://api.sarvam.ai/v1) fails. The suffix after 'Sarvam LLM failed:' preserves the raw Sarvam API error — typically 401 invalid key, 429 rate limit, subscription/quota issues, or invalid model.
Source
Thrown at mem0-ts/src/oss/src/llms/sarvam.ts:40
apiKey,
baseURL:
config.baseURL ||
process.env.SARVAM_API_BASE ||
"https://api.sarvam.ai/v1",
model: config.model || "sarvam-m",
});
}
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(`Sarvam 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(`Sarvam LLM failed: ${message}`);
}
}
}
View on GitHub (pinned to 001c235229)
Solutions
- Read the suffix: 401 → fix SARVAM_API_KEY; 429/quota → back off or top up the Sarvam plan; invalid model → correct the identifier.
- Verify the key with a direct call: curl https://api.sarvam.ai/v1/models -H "Authorization: Bearer $SARVAM_API_KEY".
- Retry transient (429/5xx/network) failures with exponential backoff; treat 401 as fatal.
- If routing through a custom base, confirm the gateway is up and OpenAI-compatible.
Example fix
// before
await sarvamLlm.generateResponse(messages, { type: 'json_object' });
// Sarvam LLM failed: 401 Unauthorized
// after
try {
await sarvamLlm.generateResponse(messages, { type: 'json_object' });
} catch (e) {
if (/401/.test(String(e))) throw new ConfigError('Sarvam key invalid');
throw e;
} Defensive patterns
Strategy: retry
Validate before calling
async function sarvamAuthed(key = process.env.SARVAM_API_KEY, base = 'https://api.sarvam.ai/v1') {
const r = await fetch(`${base}/models`, { headers: { Authorization: `Bearer ${key}` } });
if (r.status === 401) throw new Error('Sarvam key invalid');
return r.ok;
} Type guard
const isSarvamFatal = (e: unknown): boolean =>
e instanceof Error && e.message.startsWith('Sarvam LLM failed:') && /401|quota|credit/i.test(e.message); Try / catch
try {
return await sarvamLlm.generateResponse(messages, responseFormat);
} catch (err) {
if (isSarvamFatal(err)) throw err;
if (/429|timeout|ECONN/i.test(String(err))) return withRetry(fn, { retries: 3 });
throw err;
} Prevention
- Validate the key with a direct /v1/models call during smoke tests.
- Top up Sarvam credits before batch memory-ingestion jobs.
- Retry only transient errors; auth failures need config changes.
When it happens
Trigger: Calling generateResponse() with an invalid/expired Sarvam key, exhausted API credits, a wrong model name (default 'sarvam-m'), an unsupported responseFormat for the model, or when api.sarvam.ai / a custom SARVAM_API_BASE is unreachable.
Common situations: See trigger scenarios.
Related errors
- MiniMax LLM failed: ${message}
- Sarvam API key is required
- DeepSeek API key is required
- DeepSeek LLM failed: ${message}
- Groq API key is required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/0f679ed7ccee4b03.
Report an issue: GitHub.