{"record":{"id":"c40c38eac062e8b9","repo":"supermemoryai/supermemory","slug":"supermemory-profile-search-failed-response-stat","errorCode":null,"errorMessage":"Supermemory profile search failed: ${response.status} ${response.statusText}. ${errorText}","messagePattern":"Supermemory profile search failed: (.+?) (.+?)\\. (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/tools/src/openai/middleware.ts","lineNumber":121,"sourceCode":"\t\t\t\tcontainerTag: containerTag,\n\t\t\t})\n\t\t: JSON.stringify({\n\t\t\t\tcontainerTag: containerTag,\n\t\t\t})\n\n\ttry {\n\t\tconst response = await fetch(`${baseUrl}/v4/profile`, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t},\n\t\t\tbody: payload,\n\t\t})\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text().catch(() => \"Unknown error\")\n\t\t\tthrow new Error(\n\t\t\t\t`Supermemory profile search failed: ${response.status} ${response.statusText}. ${errorText}`,\n\t\t\t)\n\t\t}\n\n\t\treturn await response.json()\n\t} catch (error) {\n\t\tif (error instanceof Error) {\n\t\t\tthrow error\n\t\t}\n\t\tthrow new Error(`Supermemory API request failed: ${error}`)\n\t}\n}\n\n/**\n * Adds memory-enhanced system prompts to chat completion messages.\n *\n * Searches for relevant memories based on the specified mode and injects them\n * into the conversation. If a system prompt already exists, memories are appended","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/supermemoryai/supermemory/blob/d436792e777a99865939dd543c8d1a16d57f54ec/packages/tools/src/openai/middleware.ts#L103-L139","documentation":"supermemoryProfileSearch in the OpenAI middleware throws when the POST to Supermemory's profile-search endpoint returns a non-OK HTTP status, embedding the status, status text, and response body in the message.","triggerScenarios":"The middleware issuing a profile search before chat completion and receiving 401 (bad API key), 400 (bad payload/filter), 429 (rate limit), or 5xx from the Supermemory API.","commonSituations":"Expired or wrong-scoped API key; invalid filter payload in newer API versions; hitting rate limits under load; regional endpoint outage.","solutions":["Read the embedded status code and errorText to classify the failure","Verify SUPERMEMORY_API_KEY is valid and has the right scope","Check for payload/filter schema changes in the Supermemory API changelog","Add retry with backoff for 429/5xx and degrade gracefully to non-memory completion"],"exampleFix":"// before\nconst memories = await supermemoryProfileSearch(payload)\n\n// after\nlet memories\ntry {\n  memories = await supermemoryProfileSearch(payload)\n} catch {\n  memories = { results: [] } // degrade to no-memory completion\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let memories; try { memories = await supermemoryProfileSearch(payload) } catch (e) { logger.warn('memory search failed', e); memories = { results: [] } } // proceed without memories","preventionTips":["Degrade gracefully: memory search failure should not kill the chat request","Retry 429/5xx with backoff","Monitor error rates on the profile-search endpoint"],"tags":["http","api","openai","middleware","supermemory"],"backgroundTag":"api-request-failed","analyzedSha":"d436792e777a99865939dd543c8d1a16d57f54ec","analyzedAt":"2026-08-28T18:04:46.947Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}