{"record":{"id":"3e48dddd57c69067","repo":"mem0ai/mem0","slug":"http-error-status-response-status","errorCode":null,"errorMessage":"HTTP error! status: ${response.status}","messagePattern":"HTTP error! status: (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"integrations/vercel-ai-sdk/src/mem0-utils.ts","lineNumber":288,"sourceCode":"            body.rerank = config.rerank;\n        }\n        if (config?.metadata) {\n            body.metadata = config.metadata;\n        }\n\n        const options = {\n            method: 'POST',\n            headers: {\n                Authorization: `Token ${apiKey}`,\n                'Content-Type': 'application/json'\n            },\n            body: JSON.stringify(body),\n        };\n\n        const baseUrl = config?.host || 'https://api.mem0.ai';\n        const response = await fetch(`${baseUrl}/v3/memories/search/`, options);\n        if (!response.ok) {\n            throw new Error(`HTTP error! status: ${response.status}`);\n        }\n        const data = await response.json();\n        return data;\n    } catch (error) {\n        console.error(\"Error in searchInternalMemories:\", error);\n        throw error;\n    }\n}\n\nconst addMemories = async (messages: LanguageModelV3Prompt, config?: Mem0ConfigSettings) => {\n    try {\n        let finalMessages: Array<Message> = [];\n        if (typeof messages === \"string\") {\n            finalMessages = [{ role: \"user\", content: messages }];\n        } else {\n            finalMessages = convertToMem0Format(messages);\n        }\n        const response = await updateMemories(finalMessages, config);","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/integrations/vercel-ai-sdk/src/mem0-utils.ts#L270-L306","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst config = { host: process.env.MEM0_HOST };\nconst results = await searchInternalMemories(prompt, config); // apiKey never set → 401\n\n// after\nconst config = {\n  apiKey: process.env.MEM0_API_KEY,\n  host: process.env.MEM0_HOST,\n};\nif (!config.apiKey) throw new Error('MEM0_API_KEY not configured');","handlingStrategy":"try-catch","validationCode":"function assertMem0Config(config?: { apiKey?: string; host?: string }): void {\n  if (!config?.apiKey) throw new Error('searchInternalMemories: apiKey required');\n  if (config.host && !/^https?:\\/\\//.test(config.host)) throw new Error('host must be an absolute URL');\n}","typeGuard":"const isHttpStatusError = (e: unknown, ...codes: number[]): boolean => {\n  const m = /HTTP error! status: (\\d+)/.exec((e as Error).message ?? '');\n  return m !== null && (codes.length === 0 || codes.includes(Number(m[1])));\n};","tryCatchPattern":"try {\n  const results = await searchInternalMemories(prompt, config);\n} catch (e) {\n  if (isHttpStatusError(e, 401, 403)) throw new Error('Mem0 auth failed — check apiKey');\n  if (isHttpStatusError(e, 429)) { await backoff(); return retry(); }\n  if (isHttpStatusError(e, 404)) throw new Error('Host missing /v3/memories/search/ — check config.host/server version');\n  throw e;\n}","preventionTips":["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."],"tags":["http","api","search","authentication"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}