mem0ai/mem0 · error · Error
HTTP error! status: ${response.status}
Error message
HTTP error! status: ${response.status} What it means
searchInternalMemories() in mem0-utils.ts POSTs to `${config.host || 'https://api.mem0.ai'}/v3/memories/search/` with a Token-auth header and throws this error whenever the response status is not ok. The status code is the only detail included; the response body (which usually explains the failure) is discarded.
Source
Thrown at integrations/vercel-ai-sdk/src/mem0-utils.ts:288
body.rerank = config.rerank;
}
if (config?.metadata) {
body.metadata = config.metadata;
}
const options = {
method: 'POST',
headers: {
Authorization: `Token ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(body),
};
const baseUrl = config?.host || 'https://api.mem0.ai';
const response = await fetch(`${baseUrl}/v3/memories/search/`, options);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error in searchInternalMemories:", error);
throw error;
}
}
const addMemories = async (messages: LanguageModelV3Prompt, config?: Mem0ConfigSettings) => {
try {
let finalMessages: Array<Message> = [];
if (typeof messages === "string") {
finalMessages = [{ role: "user", content: messages }];
} else {
finalMessages = convertToMem0Format(messages);
}
const response = await updateMemories(finalMessages, config);View on GitHub (pinned to 001c235229)
Solutions
- Map the status: 401/403 → fix the apiKey in config; 400/422 → inspect the request body and filter fields; 404 → verify config.host and that the server exposes /v3/memories/search/; 429 → back off and retry.
- Confirm apiKey is actually reaching the call site (log `Boolean(config.apiKey)`, never the key itself).
- If self-hosting, upgrade the Mem0 server to a version serving /v3 routes.
- Wrap the call in retry-with-backoff for 429/5xx only.
Example fix
// before
const config = { host: process.env.MEM0_HOST };
const results = await searchInternalMemories(prompt, config); // apiKey never set → 401
// after
const config = {
apiKey: process.env.MEM0_API_KEY,
host: process.env.MEM0_HOST,
};
if (!config.apiKey) throw new Error('MEM0_API_KEY not configured'); Defensive patterns
Strategy: try-catch
Validate before calling
function assertMem0Config(config?: { apiKey?: string; host?: string }): void {
if (!config?.apiKey) throw new Error('searchInternalMemories: apiKey required');
if (config.host && !/^https?:\/\//.test(config.host)) throw new Error('host must be an absolute URL');
} Type guard
const isHttpStatusError = (e: unknown, ...codes: number[]): boolean => {
const m = /HTTP error! status: (\d+)/.exec((e as Error).message ?? '');
return m !== null && (codes.length === 0 || codes.includes(Number(m[1])));
}; Try / catch
try {
const results = await searchInternalMemories(prompt, config);
} catch (e) {
if (isHttpStatusError(e, 401, 403)) throw new Error('Mem0 auth failed — check apiKey');
if (isHttpStatusError(e, 429)) { await backoff(); return retry(); }
if (isHttpStatusError(e, 404)) throw new Error('Host missing /v3/memories/search/ — check config.host/server version');
throw e;
} Prevention
- Assert config.apiKey is present before the first call.
- Keep host as the bare API origin (no path, no trailing slash).
- Treat 429 with exponential backoff; never retry 4xx other than 429.
When it happens
Trigger: Any non-2xx from the search endpoint: 401/403 for a missing/invalid apiKey in Mem0ConfigSettings, 400 for a malformed search body or invalid filters, 404 when config.host points at a server without the /v3 route, 422 for wrong filter types, 429 rate limiting.
Common situations: Setting MEM0_API_KEY env var but not passing it into the config object; a self-hosted server version that predates /v3/; wrong host including a trailing path; shipping to an environment where the key was never injected.
Related errors
- HTTP ${resp.status}: ${detail}
- Failed to insert vectors: ${response.status} ${errorText}
- API Key is invalid
- threshold must be a valid number
- Invalid threshold: ${threshold}. Must be between 0 and 1 (in
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/3e48dddd57c69067.
Report an issue: GitHub.